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)