summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--lib/rss/0.9.rb100
-rw-r--r--lib/rss/1.0.rb50
-rw-r--r--lib/rss/2.0.rb40
-rw-r--r--lib/rss/content.rb13
-rw-r--r--lib/rss/dublincore.rb24
-rw-r--r--lib/rss/image.rb4
-rw-r--r--lib/rss/maker/base.rb4
-rw-r--r--lib/rss/maker/dublincore.rb8
-rw-r--r--lib/rss/syndication.rb17
-rw-r--r--lib/rss/taxonomy.rb12
-rw-r--r--lib/rss/trackback.rb10
12 files changed, 147 insertions, 141 deletions
diff --git a/ChangeLog b/ChangeLog
index d783847d1e..42b4f235a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Apr 5 16:01:12 2005 Kouhei Sutou <kou@cozmixng.org>
+
+ * lib/rss/*: refactored.
+ - gave a name to 'x'.
+ - undef_method -> remove_method for avoiding a warning in ruby 1.6.
+
Tue Apr 5 15:45:33 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb:
diff --git a/lib/rss/0.9.rb b/lib/rss/0.9.rb
index a2f66ee28d..a473322612 100644
--- a/lib/rss/0.9.rb
+++ b/lib/rss/0.9.rb
@@ -25,8 +25,8 @@ module RSS
install_model(tag, occurs)
end
- %w(channel).each do |x|
- install_have_child_element(x)
+ %w(channel).each do |name|
+ install_have_child_element(name)
end
attr_accessor :rss_version, :version, :encoding, :standalone
@@ -78,7 +78,9 @@ module RSS
def _tags
[
[nil, 'channel'],
- ].delete_if {|x| send(x[1]).nil?}
+ ].delete_if do |uri, name|
+ send(name).nil?
+ end
end
def _attrs
@@ -101,17 +103,17 @@ module RSS
["webMaster", "?"],
["rating", "?"],
["docs", "?"],
- ].each do |x, occurs|
- install_text_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_text_element(name)
+ install_model(name, occurs)
end
[
["pubDate", "?"],
["lastBuildDate", "?"],
- ].each do |x, occurs|
- install_date_element(x, 'rfc822')
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_date_element(name, 'rfc822')
+ install_model(name, occurs)
end
alias date pubDate
alias date= pubDate=
@@ -121,23 +123,23 @@ module RSS
["skipHours", "?"],
["image", nil],
["textInput", "?"],
- ].each do |x, occurs|
- install_have_child_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_child_element(name)
+ install_model(name, occurs)
end
[
["cloud", "?"]
- ].each do |x, occurs|
- install_have_attribute_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_attribute_element(name)
+ install_model(name, occurs)
end
[
["item", "*"]
- ].each do |x, occurs|
- install_have_children_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_children_element(name)
+ install_model(name, occurs)
end
def initialize()
@@ -192,8 +194,8 @@ module RSS
"image",
"textInput",
"cloud",
- ].delete_if do |x|
- send(x).nil?
+ ].delete_if do |name|
+ send(name).nil?
end.collect do |elem|
[nil, elem]
end
@@ -234,9 +236,9 @@ module RSS
[
["day", "*"]
- ].each do |x, occurs|
- install_have_children_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_children_element(name)
+ install_model(name, occurs)
end
def to_s(need_convert=true, indent=calc_indent)
@@ -279,9 +281,9 @@ module RSS
[
["hour", "*"]
- ].each do |x, occurs|
- install_have_children_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_children_element(name)
+ install_model(name, occurs)
end
def to_s(need_convert=true, indent=calc_indent)
@@ -328,13 +330,13 @@ module RSS
include RSS09
- %w(url title link).each do |x|
- install_text_element(x)
- install_model(x, nil)
+ %w(url title link).each do |name|
+ install_text_element(name)
+ install_model(name, nil)
end
- %w(width height description).each do |x|
- install_text_element(x)
- install_model(x, "?")
+ %w(width height description).each do |name|
+ install_text_element(name)
+ install_model(name, "?")
end
def to_s(need_convert=true, indent=calc_indent)
@@ -355,8 +357,8 @@ module RSS
private
def _tags
- %w(url title link width height description).delete_if do |x|
- send(x).nil?
+ %w(url title link width height description).delete_if do |name|
+ send(name).nil?
end.collect do |elem|
[nil, elem]
end
@@ -409,12 +411,12 @@ module RSS
include RSS09
- %w(title link description).each do |x|
- install_text_element(x)
+ %w(title link description).each do |name|
+ install_text_element(name)
end
- %w(source enclosure).each do |x|
- install_have_child_element(x)
+ %w(source enclosure).each do |name|
+ install_have_child_element(name)
end
[
@@ -457,10 +459,10 @@ module RSS
def _tags
rv = %w(title link description author comments
- source enclosure).delete_if do |x|
- send(x).nil?
- end.collect do |x|
- [nil, x]
+ source enclosure).delete_if do |name|
+ send(name).nil?
+ end.collect do |name|
+ [nil, name]
end
@category.each do
@@ -607,9 +609,9 @@ module RSS
include RSS09
- %w(title description name link).each do |x|
- install_text_element(x)
- install_model(x, nil)
+ %w(title description name link).each do |name|
+ install_text_element(name)
+ install_model(name, nil)
end
def to_s(need_convert=true, indent=calc_indent)
@@ -628,8 +630,8 @@ module RSS
private
def _tags
- %w(title description name link).each do |x|
- send(x).nil?
+ %w(title description name link).each do |name|
+ send(name).nil?
end.collect do |elem|
[nil, elem]
end
@@ -644,8 +646,8 @@ module RSS
end
- RSS09::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(nil, x, "#{x}=")
+ RSS09::ELEMENTS.each do |name|
+ BaseListener.install_get_text_element(nil, name, "#{name}=")
end
module ListenerMixin
diff --git a/lib/rss/1.0.rb b/lib/rss/1.0.rb
index d48164825f..0e0f8d9fd2 100644
--- a/lib/rss/1.0.rb
+++ b/lib/rss/1.0.rb
@@ -44,8 +44,8 @@ module RSS
install_model(tag, occurs)
end
- %w(channel image textinput).each do |x|
- install_have_child_element(x)
+ %w(channel image textinput).each do |name|
+ install_have_child_element(name)
end
install_have_children_element("item")
@@ -87,8 +87,8 @@ module RSS
rv = [
[::RSS::URI, "channel"],
[::RSS::URI, "image"],
- ].delete_if {|x| send(x[1]).nil?}
- @item.each do |x|
+ ].delete_if {|uri, name| send(name).nil?}
+ @item.each do |item|
rv << [::RSS::URI, "item"]
end
rv << [::RSS::URI, "textinput"] if @textinput
@@ -142,7 +142,7 @@ module RSS
def _tags
rv = []
- @li.each do |x|
+ @li.each do |li|
rv << [URI, "li"]
end
rv
@@ -210,12 +210,12 @@ module RSS
install_get_attribute(name, uri, required)
end
- %w(title link description).each do |x|
- install_text_element(x)
+ %w(title link description).each do |name|
+ install_text_element(name)
end
- %w(image items textinput).each do |x|
- install_have_child_element(x)
+ %w(image items textinput).each do |name|
+ install_have_child_element(name)
end
[
@@ -263,8 +263,8 @@ module RSS
[::RSS::URI, 'image'],
[::RSS::URI, 'items'],
[::RSS::URI, 'textinput'],
- ].delete_if do |x|
- send(x[1]).nil?
+ ].delete_if do |uri, name|
+ send(name).nil?
end
end
@@ -431,8 +431,8 @@ module RSS
install_get_attribute(name, uri, required)
end
- %w(title url link).each do |x|
- install_text_element(x)
+ %w(title url link).each do |name|
+ install_text_element(name)
end
[
@@ -467,8 +467,8 @@ module RSS
[::RSS::URI, 'title'],
[::RSS::URI, 'url'],
[::RSS::URI, 'link'],
- ].delete_if do |x|
- send(x[1]).nil?
+ ].delete_if do |uri, name|
+ send(name).nil?
end
end
@@ -501,8 +501,8 @@ module RSS
install_get_attribute(name, uri, required)
end
- %w(title link description).each do |x|
- install_text_element(x)
+ %w(title link description).each do |name|
+ install_text_element(name)
end
[
@@ -537,8 +537,8 @@ module RSS
[::RSS::URI, 'title'],
[::RSS::URI, 'link'],
[::RSS::URI, 'description'],
- ].delete_if do |x|
- send(x[1]).nil?
+ ].delete_if do |uri, name|
+ send(name).nil?
end
end
@@ -571,8 +571,8 @@ module RSS
install_get_attribute(name, uri, required)
end
- %w(title description name link).each do |x|
- install_text_element(x)
+ %w(title description name link).each do |name|
+ install_text_element(name)
end
[
@@ -610,8 +610,8 @@ module RSS
[::RSS::URI, 'description'],
[::RSS::URI, 'name'],
[::RSS::URI, 'link'],
- ].delete_if do |x|
- send(x[1]).nil?
+ ].delete_if do |uri, name|
+ send(name).nil?
end
end
@@ -628,8 +628,8 @@ module RSS
end
- RSS10::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(URI, x, "#{x}=")
+ RSS10::ELEMENTS.each do |name|
+ BaseListener.install_get_text_element(URI, name, "#{name}=")
end
module ListenerMixin
diff --git a/lib/rss/2.0.rb b/lib/rss/2.0.rb
index 1ae320f2db..af6ced9f7c 100644
--- a/lib/rss/2.0.rb
+++ b/lib/rss/2.0.rb
@@ -6,9 +6,9 @@ module RSS
class Channel
- %w(generator ttl).each do |x|
- install_text_element(x)
- install_model(x, '?')
+ %w(generator ttl).each do |name|
+ install_text_element(name)
+ install_model(name, '?')
end
remove_method :ttl=
@@ -26,8 +26,8 @@ module RSS
[
["image", "?"],
["language", "?"],
- ].each do |x, occurs|
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_model(name, occurs)
end
def other_element(need_convert, indent)
@@ -47,8 +47,8 @@ EOT
alias _tags09 _tags
def _tags
- rv = %w(generator ttl).delete_if do |x|
- send(x).nil?
+ rv = %w(generator ttl).delete_if do |name|
+ send(name).nil?
end.collect do |elem|
[nil, elem]
end + _tags09
@@ -67,25 +67,25 @@ EOT
[
["comments", "?"],
["author", "?"],
- ].each do |x, occurs|
- install_text_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_text_element(name)
+ install_model(name, occurs)
end
[
["pubDate", '?'],
- ].each do |x, occurs|
- install_date_element(x, 'rfc822')
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_date_element(name, 'rfc822')
+ install_model(name, occurs)
end
alias date pubDate
alias date= pubDate=
[
["guid", '?'],
- ].each do |x, occurs|
- install_have_child_element(x)
- install_model(x, occurs)
+ ].each do |name, occurs|
+ install_have_child_element(name)
+ install_model(name, occurs)
end
def other_element(need_convert, indent)
@@ -108,8 +108,8 @@ EOT
alias _tags09 _tags
def _tags
- %w(comments author pubDate guid).delete_if do |x|
- send(x).nil?
+ %w(comments author pubDate guid).delete_if do |name|
+ send(name).nil?
end.collect do |elem|
[nil, elem]
end + _tags09
@@ -162,8 +162,8 @@ EOT
end
- RSS09::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(nil, x, "#{x}=")
+ RSS09::ELEMENTS.each do |name|
+ BaseListener.install_get_text_element(nil, name, "#{name}=")
end
end
diff --git a/lib/rss/content.rb b/lib/rss/content.rb
index 78eefadff1..a732cec973 100644
--- a/lib/rss/content.rb
+++ b/lib/rss/content.rb
@@ -17,16 +17,16 @@ module RSS
super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
- %w(encoded).each do |x|
- install_text_element("\#{CONTENT_PREFIX}_\#{x}")
+ %w(encoded).each do |name|
+ install_text_element("\#{CONTENT_PREFIX}_\#{name}")
end
EOC
end
def content_validate(tags)
counter = {}
- ELEMENTS.each do |x|
- counter[x] = 0
+ ELEMENTS.each do |name|
+ counter[name] = 0
end
tags.each do |tag|
@@ -45,8 +45,9 @@ module RSS
prefix_size = CONTENT_PREFIX.size + 1
ContentModel::ELEMENTS.uniq!
- ContentModel::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(CONTENT_URI, x[prefix_size..-1], "#{x}=")
+ ContentModel::ELEMENTS.each do |full_name|
+ name = full_name[prefix_size..-1]
+ BaseListener.install_get_text_element(CONTENT_URI, name, "#{full_name}=")
end
end
diff --git a/lib/rss/dublincore.rb b/lib/rss/dublincore.rb
index 1a1e1776c7..5571640bf2 100644
--- a/lib/rss/dublincore.rb
+++ b/lib/rss/dublincore.rb
@@ -75,9 +75,9 @@ module RSS
ELEMENTS = TEXT_ELEMENTS.keys + DATE_ELEMENTS.keys
- ELEMENTS.each do |x, plural_name|
+ ELEMENTS.each do |name, plural_name|
module_eval(<<-EOC, *get_file_and_line_from_caller(0))
- class DublinCore#{Utils.to_class_name(x)} < Element
+ class DublinCore#{Utils.to_class_name(name)} < Element
include RSS10
content_setup
@@ -92,7 +92,7 @@ module RSS
end
end
- @tag_name = #{x.dump}
+ @tag_name = #{name.dump}
alias_method(:value, :content)
alias_method(:value=, :content=)
@@ -107,11 +107,11 @@ module RSS
end
def maker_target(target)
- target.new_#{x}
+ target.new_#{name}
end
- def setup_maker_attributes(#{x})
- #{x}.content = content
+ def setup_maker_attributes(#{name})
+ #{name}.content = content
end
end
EOC
@@ -120,8 +120,8 @@ module RSS
DATE_ELEMENTS.each do |name, type|
module_eval(<<-EOC, *get_file_and_line_from_caller(0))
class DublinCore#{Utils.to_class_name(name)} < Element
- undef_method(:content=)
- undef_method(:value=)
+ remove_method(:content=)
+ remove_method(:value=)
date_writer("content", #{type.dump}, #{name.dump})
@@ -151,10 +151,10 @@ module RSS
class Textinput; include DublinCoreModel; end
end
- DublinCoreModel::ELEMENTS.each do |x|
- class_name = Utils.to_class_name(x)
- BaseListener.install_class_name(DC_URI, x, "DublinCore#{class_name}")
+ DublinCoreModel::ELEMENTS.each do |name|
+ class_name = Utils.to_class_name(name)
+ BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
end
- DublinCoreModel::ELEMENTS.collect! {|x| "#{DC_PREFIX}_#{x}"}
+ DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
end
diff --git a/lib/rss/image.rb b/lib/rss/image.rb
index 441e83fc2d..4dea91925b 100644
--- a/lib/rss/image.rb
+++ b/lib/rss/image.rb
@@ -105,8 +105,8 @@ module RSS
[
[IMAGE_URI, 'width'],
[IMAGE_URI, 'height'],
- ].delete_if do |x|
- send(x[1]).nil?
+ ].delete_if do |uri, name|
+ send(name).nil?
end
end
diff --git a/lib/rss/maker/base.rb b/lib/rss/maker/base.rb
index 4f5e31f542..629f794b07 100644
--- a/lib/rss/maker/base.rb
+++ b/lib/rss/maker/base.rb
@@ -185,10 +185,6 @@ EOC
end
end
- def current_element(rss)
- rss
- end
-
private
remove_method :make_xml_stylesheets
def make_xml_stylesheets
diff --git a/lib/rss/maker/dublincore.rb b/lib/rss/maker/dublincore.rb
index 4e4378436d..948c459416 100644
--- a/lib/rss/maker/dublincore.rb
+++ b/lib/rss/maker/dublincore.rb
@@ -101,8 +101,8 @@ EOC
class ChannelBase
include DublinCoreModel
- undef_method(:dc_date)
- undef_method(:dc_date=)
+ remove_method(:dc_date)
+ remove_method(:dc_date=)
alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=)
end
@@ -112,8 +112,8 @@ EOC
class ItemBase
include DublinCoreModel
- undef_method(:dc_date)
- undef_method(:dc_date=)
+ remove_method(:dc_date)
+ remove_method(:dc_date=)
alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=)
end
diff --git a/lib/rss/syndication.rb b/lib/rss/syndication.rb
index e71455c6a4..56976085a1 100644
--- a/lib/rss/syndication.rb
+++ b/lib/rss/syndication.rb
@@ -17,12 +17,12 @@ module RSS
super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
- %w(updatePeriod updateFrequency).each do |x|
- install_text_element("\#{SY_PREFIX}_\#{x}")
+ %w(updatePeriod updateFrequency).each do |name|
+ install_text_element("\#{SY_PREFIX}_\#{name}")
end
- %w(updateBase).each do |x|
- install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x)
+ %w(updateBase).each do |name|
+ install_date_element("\#{SY_PREFIX}_\#{name}", 'w3cdtf', name)
end
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
@@ -42,8 +42,8 @@ module RSS
def sy_validate(tags)
counter = {}
- ELEMENTS.each do |x|
- counter[x] = 0
+ ELEMENTS.each do |name|
+ counter[name] = 0
end
tags.each do |tag|
@@ -78,8 +78,9 @@ module RSS
prefix_size = SY_PREFIX.size + 1
SyndicationModel::ELEMENTS.uniq!
- SyndicationModel::ELEMENTS.each do |x|
- BaseListener.install_get_text_element(SY_URI, x[prefix_size..-1], "#{x}=")
+ SyndicationModel::ELEMENTS.each do |full_name|
+ name = full_name[prefix_size..-1]
+ BaseListener.install_get_text_element(SY_URI, name, "#{full_name}=")
end
end
diff --git a/lib/rss/taxonomy.rb b/lib/rss/taxonomy.rb
index 173214dffb..f70d475a11 100644
--- a/lib/rss/taxonomy.rb
+++ b/lib/rss/taxonomy.rb
@@ -11,17 +11,17 @@ module RSS
TAXO_ELEMENTS = []
- %w(link).each do |x|
- if const_defined? :Listener
- Listener.install_get_text_element(TAXO_NS, x, "#{TAXO_PREFIX}_#{x}=")
- end
- TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{x}"
+ %w(link).each do |name|
+ full_name = "#{TAXO_PREFIX}_#{name}"
+ BaseListener.install_get_text_element(TAXO_NS, name, "#{full_name}=")
+ TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
end
module TaxonomyModel
attr_writer(*%w(title description creator subject publisher
contributor date format identifier source
- language relation coverage rights).collect{|x| "#{TAXO_PREFIX}_#{x}"})
+ language relation coverage rights
+ ).collect{|name| "#{TAXO_PREFIX}_#{name}"})
end
class Channel; extend TaxonomyModel; end
diff --git a/lib/rss/trackback.rb b/lib/rss/trackback.rb
index c8228059de..973a1035d1 100644
--- a/lib/rss/trackback.rb
+++ b/lib/rss/trackback.rb
@@ -13,8 +13,8 @@ module RSS
private
def trackback_validate(tags)
counter = {}
- %w(ping about).each do |x|
- counter["#{TRACKBACK_PREFIX}_#{x}"] = 0
+ %w(ping about).each do |name|
+ counter["#{TRACKBACK_PREFIX}_#{name}"] = 0
end
tags.each do |tag|
@@ -40,9 +40,9 @@ module RSS
unless klass.class == Module
klass.__send__(:include, TrackBackUtils)
- %w(ping).each do |x|
- var_name = "#{TRACKBACK_PREFIX}_#{x}"
- klass_name = x.capitalize
+ %w(ping).each do |name|
+ var_name = "#{TRACKBACK_PREFIX}_#{name}"
+ klass_name = name.capitalize
klass.install_have_child_element(var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name}