[#37050] [Feature #735] Date#inspect — "rubikitch ." <redmine@...>

Feature #735: Date#inspect

14 messages 2008/11/09

[#37075] [Feature #747] /\A/u ignores BOM — Shyouhei Urabe <redmine@...>

Feature #747: /\A/u ignores BOM

14 messages 2008/11/12

[#37161] m17n of irb — "Yugui (Yuki Sonoda)" <yugui@...>

Yuguiです。

35 messages 2008/11/24
[#37183] Re: m17n of irb — keiju@... (keiju ISHITSUKA) 2008/11/25

けいじゅ@いしつかです.

[#37203] Re: m17n of irb — "Yugui (Yuki Sonoda)" <yugui@...> 2008/11/26

keiju ISHITSUKA さんは書きました:

[#37292] Re: m17n of irb — Yukihiro Matsumoto <matz@...> 2008/12/06

まつもと ゆきひろです

[#37293] Re: m17n of irb — "Yugui (Yuki Sonoda)" <yugui@...> 2008/12/07

Yuguiです。

[#37298] Re: m17n of irb — Yukihiro Matsumoto <matz@...> 2008/12/07

まつもと ゆきひろです

[#37210] RSS::Maker.create(version) — "Akinori MUSHA" <knu@...>

 RSS::Maker で、 "2.0" 等の文字列でフィードのフォーマットを渡す

15 messages 2008/11/27

[#37213] Re: [ruby-cvs:27586] Ruby:r20368 (trunk): * ext/bigdecimal/bigdecimal.c (BigDecimal_div2): should return — Tadayoshi Funaba <tadf@...>

> * ext/bigdecimal/bigdecimal.c (BigDecimal_div2): should return

8 messages 2008/11/27

[ruby-dev:37210] RSS::Maker.create(version)

From: "Akinori MUSHA" <knu@...>
Date: 2008-11-27 06:22:05 UTC
List: ruby-dev #37210
 RSS::Maker で、 "2.0" 等の文字列でフィードのフォーマットを渡す
インターフェースは事実上 RSS::Maker.make(version) {|maker| ... }
しかありません。(maker = RSS::Maker::XXXXX.new 相当ができない)

 しかし、RSSの生成が処理の主眼でない場合や、複数のRSSフィードを
同時に作ったりする場合、ブロックの導入が必須のインターフェースは
使いづらいです。

 そこで、 RSS::Maker.create(version) のようなメソッドを追加する
のはどうでしょうか。つまり、

    FEED_FORMAT = "2.0"
    ARTICLES_RSS = File.expand_path("~/public_html/feeds/articles.rss")
    IMPORTANT_ARTICLES_RSS = File.expand_path("~/public_html/feeds/important_articles.rss")

    rss = RSS::Maker.make(FEED_FORMAT) { |rssmaker|
      # ... channel, image等の設定

      rss_important = RSS::Maker.make(FEED_FORMAT) { |rssmaker_important|
        # ... channel, image等の設定

        articles.each { |article|
          rssmaker.new_item { |item|
            item.title = article.subject
            # ... link, date等の設定
          }
          if article.important?
            rssmaker_important.new_item { |item|
              item.title = article.subject
              # ... link, date等の設定
            }
          end
        }
      }
      File.open(IMPORTANT_ARTICLES_RSS, "w") { |w|
        w.print(rss_important.to_s)
      }
    }
    File.open(ARTICLES_RSS, "w") { |w|
      w.print(rss.to_s)
    }

の本処理部分を

    rssmaker = RSS::Maker.create(FEED_FORMAT)
    # ... channel, image等の設定

    rssmaker_important = RSS::Maker.make(FEED_FORMAT)
    # ... channel, image等の設定

    articles.each { |article|
      rssmaker.new_item { |item|
        item.title = article.subject
        # ... link, date等の設定
      }
      if article.important?
        rssmaker_important.new_item { |item|
          item.title = article.subject
          # ... link, date等の設定
        }
      end
    }
    File.open(IMPORTANT_ARTICLES_RSS, "w") { |w|
      w.print(rssmaker_important.to_feed.to_s)
    }
    File.open(ARTICLES_RSS, "w") { |w|
      w.print(rssmaker.to_feed.to_s)
    }

のようにフラットな構造で書きたい、というわけです。

 以下がパッチです。

Index: lib/rss/maker.rb
===================================================================
--- lib/rss/maker.rb	(revision 20367)
+++ lib/rss/maker.rb	(working copy)
@@ -5,10 +5,14 @@ module RSS
     MAKERS = {}

     class << self
-      def make(version, &block)
+      def create(version)
         m = maker(version)
         raise UnsupportedMakerVersionError.new(version) if m.nil?
-        m[:maker].make(m[:version], &block)
+        m[:maker].new(m[:version])
+      end
+
+      def make(version, &block)
+        create(version).make(&block)
       end

       def maker(version)

--
Akinori MUSHA / http://akinori.org/

In This Thread

Prev Next