* lib/rss/*: refactored.

- gave a name to 'x'.
  - undef_method -> remove_method for avoiding a warning in ruby 1.6.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8255 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
kou 2005-04-05 07:03:43 +00:00
parent 56ce2994de
commit 5f3a36794a
12 changed files with 147 additions and 141 deletions

View File

@ -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> Tue Apr 5 15:45:33 2005 Kouhei Sutou <kou@cozmixng.org>
* sample/rss/tdiary_plugin/rss-recent.rb: * sample/rss/tdiary_plugin/rss-recent.rb:

View File

@ -25,8 +25,8 @@ module RSS
install_model(tag, occurs) install_model(tag, occurs)
end end
%w(channel).each do |x| %w(channel).each do |name|
install_have_child_element(x) install_have_child_element(name)
end end
attr_accessor :rss_version, :version, :encoding, :standalone attr_accessor :rss_version, :version, :encoding, :standalone
@ -78,7 +78,9 @@ module RSS
def _tags def _tags
[ [
[nil, 'channel'], [nil, 'channel'],
].delete_if {|x| send(x[1]).nil?} ].delete_if do |uri, name|
send(name).nil?
end
end end
def _attrs def _attrs
@ -101,17 +103,17 @@ module RSS
["webMaster", "?"], ["webMaster", "?"],
["rating", "?"], ["rating", "?"],
["docs", "?"], ["docs", "?"],
].each do |x, occurs| ].each do |name, occurs|
install_text_element(x) install_text_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
[ [
["pubDate", "?"], ["pubDate", "?"],
["lastBuildDate", "?"], ["lastBuildDate", "?"],
].each do |x, occurs| ].each do |name, occurs|
install_date_element(x, 'rfc822') install_date_element(name, 'rfc822')
install_model(x, occurs) install_model(name, occurs)
end end
alias date pubDate alias date pubDate
alias date= pubDate= alias date= pubDate=
@ -121,23 +123,23 @@ module RSS
["skipHours", "?"], ["skipHours", "?"],
["image", nil], ["image", nil],
["textInput", "?"], ["textInput", "?"],
].each do |x, occurs| ].each do |name, occurs|
install_have_child_element(x) install_have_child_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
[ [
["cloud", "?"] ["cloud", "?"]
].each do |x, occurs| ].each do |name, occurs|
install_have_attribute_element(x) install_have_attribute_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
[ [
["item", "*"] ["item", "*"]
].each do |x, occurs| ].each do |name, occurs|
install_have_children_element(x) install_have_children_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
def initialize() def initialize()
@ -192,8 +194,8 @@ module RSS
"image", "image",
"textInput", "textInput",
"cloud", "cloud",
].delete_if do |x| ].delete_if do |name|
send(x).nil? send(name).nil?
end.collect do |elem| end.collect do |elem|
[nil, elem] [nil, elem]
end end
@ -234,9 +236,9 @@ module RSS
[ [
["day", "*"] ["day", "*"]
].each do |x, occurs| ].each do |name, occurs|
install_have_children_element(x) install_have_children_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -279,9 +281,9 @@ module RSS
[ [
["hour", "*"] ["hour", "*"]
].each do |x, occurs| ].each do |name, occurs|
install_have_children_element(x) install_have_children_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -328,13 +330,13 @@ module RSS
include RSS09 include RSS09
%w(url title link).each do |x| %w(url title link).each do |name|
install_text_element(x) install_text_element(name)
install_model(x, nil) install_model(name, nil)
end end
%w(width height description).each do |x| %w(width height description).each do |name|
install_text_element(x) install_text_element(name)
install_model(x, "?") install_model(name, "?")
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -355,8 +357,8 @@ module RSS
private private
def _tags def _tags
%w(url title link width height description).delete_if do |x| %w(url title link width height description).delete_if do |name|
send(x).nil? send(name).nil?
end.collect do |elem| end.collect do |elem|
[nil, elem] [nil, elem]
end end
@ -409,12 +411,12 @@ module RSS
include RSS09 include RSS09
%w(title link description).each do |x| %w(title link description).each do |name|
install_text_element(x) install_text_element(name)
end end
%w(source enclosure).each do |x| %w(source enclosure).each do |name|
install_have_child_element(x) install_have_child_element(name)
end end
[ [
@ -457,10 +459,10 @@ module RSS
def _tags def _tags
rv = %w(title link description author comments rv = %w(title link description author comments
source enclosure).delete_if do |x| source enclosure).delete_if do |name|
send(x).nil? send(name).nil?
end.collect do |x| end.collect do |name|
[nil, x] [nil, name]
end end
@category.each do @category.each do
@ -607,9 +609,9 @@ module RSS
include RSS09 include RSS09
%w(title description name link).each do |x| %w(title description name link).each do |name|
install_text_element(x) install_text_element(name)
install_model(x, nil) install_model(name, nil)
end end
def to_s(need_convert=true, indent=calc_indent) def to_s(need_convert=true, indent=calc_indent)
@ -628,8 +630,8 @@ module RSS
private private
def _tags def _tags
%w(title description name link).each do |x| %w(title description name link).each do |name|
send(x).nil? send(name).nil?
end.collect do |elem| end.collect do |elem|
[nil, elem] [nil, elem]
end end
@ -644,8 +646,8 @@ module RSS
end end
RSS09::ELEMENTS.each do |x| RSS09::ELEMENTS.each do |name|
BaseListener.install_get_text_element(nil, x, "#{x}=") BaseListener.install_get_text_element(nil, name, "#{name}=")
end end
module ListenerMixin module ListenerMixin

View File

@ -44,8 +44,8 @@ module RSS
install_model(tag, occurs) install_model(tag, occurs)
end end
%w(channel image textinput).each do |x| %w(channel image textinput).each do |name|
install_have_child_element(x) install_have_child_element(name)
end end
install_have_children_element("item") install_have_children_element("item")
@ -87,8 +87,8 @@ module RSS
rv = [ rv = [
[::RSS::URI, "channel"], [::RSS::URI, "channel"],
[::RSS::URI, "image"], [::RSS::URI, "image"],
].delete_if {|x| send(x[1]).nil?} ].delete_if {|uri, name| send(name).nil?}
@item.each do |x| @item.each do |item|
rv << [::RSS::URI, "item"] rv << [::RSS::URI, "item"]
end end
rv << [::RSS::URI, "textinput"] if @textinput rv << [::RSS::URI, "textinput"] if @textinput
@ -142,7 +142,7 @@ module RSS
def _tags def _tags
rv = [] rv = []
@li.each do |x| @li.each do |li|
rv << [URI, "li"] rv << [URI, "li"]
end end
rv rv
@ -210,12 +210,12 @@ module RSS
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required)
end end
%w(title link description).each do |x| %w(title link description).each do |name|
install_text_element(x) install_text_element(name)
end end
%w(image items textinput).each do |x| %w(image items textinput).each do |name|
install_have_child_element(x) install_have_child_element(name)
end end
[ [
@ -263,8 +263,8 @@ module RSS
[::RSS::URI, 'image'], [::RSS::URI, 'image'],
[::RSS::URI, 'items'], [::RSS::URI, 'items'],
[::RSS::URI, 'textinput'], [::RSS::URI, 'textinput'],
].delete_if do |x| ].delete_if do |uri, name|
send(x[1]).nil? send(name).nil?
end end
end end
@ -431,8 +431,8 @@ module RSS
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required)
end end
%w(title url link).each do |x| %w(title url link).each do |name|
install_text_element(x) install_text_element(name)
end end
[ [
@ -467,8 +467,8 @@ module RSS
[::RSS::URI, 'title'], [::RSS::URI, 'title'],
[::RSS::URI, 'url'], [::RSS::URI, 'url'],
[::RSS::URI, 'link'], [::RSS::URI, 'link'],
].delete_if do |x| ].delete_if do |uri, name|
send(x[1]).nil? send(name).nil?
end end
end end
@ -501,8 +501,8 @@ module RSS
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required)
end end
%w(title link description).each do |x| %w(title link description).each do |name|
install_text_element(x) install_text_element(name)
end end
[ [
@ -537,8 +537,8 @@ module RSS
[::RSS::URI, 'title'], [::RSS::URI, 'title'],
[::RSS::URI, 'link'], [::RSS::URI, 'link'],
[::RSS::URI, 'description'], [::RSS::URI, 'description'],
].delete_if do |x| ].delete_if do |uri, name|
send(x[1]).nil? send(name).nil?
end end
end end
@ -571,8 +571,8 @@ module RSS
install_get_attribute(name, uri, required) install_get_attribute(name, uri, required)
end end
%w(title description name link).each do |x| %w(title description name link).each do |name|
install_text_element(x) install_text_element(name)
end end
[ [
@ -610,8 +610,8 @@ module RSS
[::RSS::URI, 'description'], [::RSS::URI, 'description'],
[::RSS::URI, 'name'], [::RSS::URI, 'name'],
[::RSS::URI, 'link'], [::RSS::URI, 'link'],
].delete_if do |x| ].delete_if do |uri, name|
send(x[1]).nil? send(name).nil?
end end
end end
@ -628,8 +628,8 @@ module RSS
end end
RSS10::ELEMENTS.each do |x| RSS10::ELEMENTS.each do |name|
BaseListener.install_get_text_element(URI, x, "#{x}=") BaseListener.install_get_text_element(URI, name, "#{name}=")
end end
module ListenerMixin module ListenerMixin

View File

@ -6,9 +6,9 @@ module RSS
class Channel class Channel
%w(generator ttl).each do |x| %w(generator ttl).each do |name|
install_text_element(x) install_text_element(name)
install_model(x, '?') install_model(name, '?')
end end
remove_method :ttl= remove_method :ttl=
@ -26,8 +26,8 @@ module RSS
[ [
["image", "?"], ["image", "?"],
["language", "?"], ["language", "?"],
].each do |x, occurs| ].each do |name, occurs|
install_model(x, occurs) install_model(name, occurs)
end end
def other_element(need_convert, indent) def other_element(need_convert, indent)
@ -47,8 +47,8 @@ EOT
alias _tags09 _tags alias _tags09 _tags
def _tags def _tags
rv = %w(generator ttl).delete_if do |x| rv = %w(generator ttl).delete_if do |name|
send(x).nil? send(name).nil?
end.collect do |elem| end.collect do |elem|
[nil, elem] [nil, elem]
end + _tags09 end + _tags09
@ -67,25 +67,25 @@ EOT
[ [
["comments", "?"], ["comments", "?"],
["author", "?"], ["author", "?"],
].each do |x, occurs| ].each do |name, occurs|
install_text_element(x) install_text_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
[ [
["pubDate", '?'], ["pubDate", '?'],
].each do |x, occurs| ].each do |name, occurs|
install_date_element(x, 'rfc822') install_date_element(name, 'rfc822')
install_model(x, occurs) install_model(name, occurs)
end end
alias date pubDate alias date pubDate
alias date= pubDate= alias date= pubDate=
[ [
["guid", '?'], ["guid", '?'],
].each do |x, occurs| ].each do |name, occurs|
install_have_child_element(x) install_have_child_element(name)
install_model(x, occurs) install_model(name, occurs)
end end
def other_element(need_convert, indent) def other_element(need_convert, indent)
@ -108,8 +108,8 @@ EOT
alias _tags09 _tags alias _tags09 _tags
def _tags def _tags
%w(comments author pubDate guid).delete_if do |x| %w(comments author pubDate guid).delete_if do |name|
send(x).nil? send(name).nil?
end.collect do |elem| end.collect do |elem|
[nil, elem] [nil, elem]
end + _tags09 end + _tags09
@ -162,8 +162,8 @@ EOT
end end
RSS09::ELEMENTS.each do |x| RSS09::ELEMENTS.each do |name|
BaseListener.install_get_text_element(nil, x, "#{x}=") BaseListener.install_get_text_element(nil, name, "#{name}=")
end end
end end

View File

@ -17,16 +17,16 @@ module RSS
super super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(encoded).each do |x| %w(encoded).each do |name|
install_text_element("\#{CONTENT_PREFIX}_\#{x}") install_text_element("\#{CONTENT_PREFIX}_\#{name}")
end end
EOC EOC
end end
def content_validate(tags) def content_validate(tags)
counter = {} counter = {}
ELEMENTS.each do |x| ELEMENTS.each do |name|
counter[x] = 0 counter[name] = 0
end end
tags.each do |tag| tags.each do |tag|
@ -45,8 +45,9 @@ module RSS
prefix_size = CONTENT_PREFIX.size + 1 prefix_size = CONTENT_PREFIX.size + 1
ContentModel::ELEMENTS.uniq! ContentModel::ELEMENTS.uniq!
ContentModel::ELEMENTS.each do |x| ContentModel::ELEMENTS.each do |full_name|
BaseListener.install_get_text_element(CONTENT_URI, x[prefix_size..-1], "#{x}=") name = full_name[prefix_size..-1]
BaseListener.install_get_text_element(CONTENT_URI, name, "#{full_name}=")
end end
end end

View File

@ -75,9 +75,9 @@ module RSS
ELEMENTS = TEXT_ELEMENTS.keys + DATE_ELEMENTS.keys 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)) 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 include RSS10
content_setup content_setup
@ -92,7 +92,7 @@ module RSS
end end
end end
@tag_name = #{x.dump} @tag_name = #{name.dump}
alias_method(:value, :content) alias_method(:value, :content)
alias_method(:value=, :content=) alias_method(:value=, :content=)
@ -107,11 +107,11 @@ module RSS
end end
def maker_target(target) def maker_target(target)
target.new_#{x} target.new_#{name}
end end
def setup_maker_attributes(#{x}) def setup_maker_attributes(#{name})
#{x}.content = content #{name}.content = content
end end
end end
EOC EOC
@ -120,8 +120,8 @@ module RSS
DATE_ELEMENTS.each do |name, type| DATE_ELEMENTS.each do |name, type|
module_eval(<<-EOC, *get_file_and_line_from_caller(0)) module_eval(<<-EOC, *get_file_and_line_from_caller(0))
class DublinCore#{Utils.to_class_name(name)} < Element class DublinCore#{Utils.to_class_name(name)} < Element
undef_method(:content=) remove_method(:content=)
undef_method(:value=) remove_method(:value=)
date_writer("content", #{type.dump}, #{name.dump}) date_writer("content", #{type.dump}, #{name.dump})
@ -151,10 +151,10 @@ module RSS
class Textinput; include DublinCoreModel; end class Textinput; include DublinCoreModel; end
end end
DublinCoreModel::ELEMENTS.each do |x| DublinCoreModel::ELEMENTS.each do |name|
class_name = Utils.to_class_name(x) class_name = Utils.to_class_name(name)
BaseListener.install_class_name(DC_URI, x, "DublinCore#{class_name}") BaseListener.install_class_name(DC_URI, name, "DublinCore#{class_name}")
end end
DublinCoreModel::ELEMENTS.collect! {|x| "#{DC_PREFIX}_#{x}"} DublinCoreModel::ELEMENTS.collect! {|name| "#{DC_PREFIX}_#{name}"}
end end

View File

@ -105,8 +105,8 @@ module RSS
[ [
[IMAGE_URI, 'width'], [IMAGE_URI, 'width'],
[IMAGE_URI, 'height'], [IMAGE_URI, 'height'],
].delete_if do |x| ].delete_if do |uri, name|
send(x[1]).nil? send(name).nil?
end end
end end

View File

@ -185,10 +185,6 @@ EOC
end end
end end
def current_element(rss)
rss
end
private private
remove_method :make_xml_stylesheets remove_method :make_xml_stylesheets
def make_xml_stylesheets def make_xml_stylesheets

View File

@ -101,8 +101,8 @@ EOC
class ChannelBase class ChannelBase
include DublinCoreModel include DublinCoreModel
undef_method(:dc_date) remove_method(:dc_date)
undef_method(:dc_date=) remove_method(:dc_date=)
alias_method(:dc_date, :date) alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=) alias_method(:dc_date=, :date=)
end end
@ -112,8 +112,8 @@ EOC
class ItemBase class ItemBase
include DublinCoreModel include DublinCoreModel
undef_method(:dc_date) remove_method(:dc_date)
undef_method(:dc_date=) remove_method(:dc_date=)
alias_method(:dc_date, :date) alias_method(:dc_date, :date)
alias_method(:dc_date=, :date=) alias_method(:dc_date=, :date=)
end end

View File

@ -17,12 +17,12 @@ module RSS
super super
klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1)) klass.module_eval(<<-EOC, *get_file_and_line_from_caller(1))
%w(updatePeriod updateFrequency).each do |x| %w(updatePeriod updateFrequency).each do |name|
install_text_element("\#{SY_PREFIX}_\#{x}") install_text_element("\#{SY_PREFIX}_\#{name}")
end end
%w(updateBase).each do |x| %w(updateBase).each do |name|
install_date_element("\#{SY_PREFIX}_\#{x}", 'w3cdtf', x) install_date_element("\#{SY_PREFIX}_\#{name}", 'w3cdtf', name)
end end
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=) alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
@ -42,8 +42,8 @@ module RSS
def sy_validate(tags) def sy_validate(tags)
counter = {} counter = {}
ELEMENTS.each do |x| ELEMENTS.each do |name|
counter[x] = 0 counter[name] = 0
end end
tags.each do |tag| tags.each do |tag|
@ -78,8 +78,9 @@ module RSS
prefix_size = SY_PREFIX.size + 1 prefix_size = SY_PREFIX.size + 1
SyndicationModel::ELEMENTS.uniq! SyndicationModel::ELEMENTS.uniq!
SyndicationModel::ELEMENTS.each do |x| SyndicationModel::ELEMENTS.each do |full_name|
BaseListener.install_get_text_element(SY_URI, x[prefix_size..-1], "#{x}=") name = full_name[prefix_size..-1]
BaseListener.install_get_text_element(SY_URI, name, "#{full_name}=")
end end
end end

View File

@ -11,17 +11,17 @@ module RSS
TAXO_ELEMENTS = [] TAXO_ELEMENTS = []
%w(link).each do |x| %w(link).each do |name|
if const_defined? :Listener full_name = "#{TAXO_PREFIX}_#{name}"
Listener.install_get_text_element(TAXO_NS, x, "#{TAXO_PREFIX}_#{x}=") BaseListener.install_get_text_element(TAXO_NS, name, "#{full_name}=")
end TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{x}"
end end
module TaxonomyModel module TaxonomyModel
attr_writer(*%w(title description creator subject publisher attr_writer(*%w(title description creator subject publisher
contributor date format identifier source contributor date format identifier source
language relation coverage rights).collect{|x| "#{TAXO_PREFIX}_#{x}"}) language relation coverage rights
).collect{|name| "#{TAXO_PREFIX}_#{name}"})
end end
class Channel; extend TaxonomyModel; end class Channel; extend TaxonomyModel; end

View File

@ -13,8 +13,8 @@ module RSS
private private
def trackback_validate(tags) def trackback_validate(tags)
counter = {} counter = {}
%w(ping about).each do |x| %w(ping about).each do |name|
counter["#{TRACKBACK_PREFIX}_#{x}"] = 0 counter["#{TRACKBACK_PREFIX}_#{name}"] = 0
end end
tags.each do |tag| tags.each do |tag|
@ -40,9 +40,9 @@ module RSS
unless klass.class == Module unless klass.class == Module
klass.__send__(:include, TrackBackUtils) klass.__send__(:include, TrackBackUtils)
%w(ping).each do |x| %w(ping).each do |name|
var_name = "#{TRACKBACK_PREFIX}_#{x}" var_name = "#{TRACKBACK_PREFIX}_#{name}"
klass_name = x.capitalize klass_name = name.capitalize
klass.install_have_child_element(var_name) klass.install_have_child_element(var_name)
klass.module_eval(<<-EOC, __FILE__, __LINE__) klass.module_eval(<<-EOC, __FILE__, __LINE__)
remove_method :#{var_name} remove_method :#{var_name}