1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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>
* sample/rss/tdiary_plugin/rss-recent.rb:

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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}