mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/rss.rb, lib/rss/, test/rss/, sample/rss/: merged from trunk.
- 0.1.6 -> 2.0.0. - fixed image module URI. Thanks to Dmitry Borodaenko. - supported Atom. - supported ITunes module. - supported Slash module. * NEWS: added an entry for RSS Parser. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@13747 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
754b1fac44
commit
57a639494a
81 changed files with 11826 additions and 1691 deletions
|
@ -4,14 +4,16 @@ module RSS
|
|||
|
||||
# Convert a name_with_underscores to CamelCase.
|
||||
def to_class_name(name)
|
||||
name.split(/_/).collect do |part|
|
||||
name.split(/[_\-]/).collect do |part|
|
||||
"#{part[0, 1].upcase}#{part[1..-1]}"
|
||||
end.join("")
|
||||
end
|
||||
|
||||
def get_file_and_line_from_caller(i=0)
|
||||
file, line, = caller[i].split(':')
|
||||
[file, line.to_i]
|
||||
line = line.to_i
|
||||
line += 1 if i.zero?
|
||||
[file, line]
|
||||
end
|
||||
|
||||
# escape '&', '"', '<' and '>' for use in HTML.
|
||||
|
@ -33,5 +35,77 @@ module RSS
|
|||
def element_initialize_arguments?(args)
|
||||
[true, false].include?(args[0]) and args[1].is_a?(Hash)
|
||||
end
|
||||
|
||||
module YesCleanOther
|
||||
module_function
|
||||
def parse(value)
|
||||
if [true, false, nil].include?(value)
|
||||
value
|
||||
else
|
||||
case value.to_s
|
||||
when /\Ayes\z/i
|
||||
true
|
||||
when /\Aclean\z/i
|
||||
false
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module YesOther
|
||||
module_function
|
||||
def parse(value)
|
||||
if [true, false].include?(value)
|
||||
value
|
||||
else
|
||||
/\Ayes\z/i.match(value.to_s) ? true : false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module CSV
|
||||
module_function
|
||||
def parse(value, &block)
|
||||
if value.is_a?(String)
|
||||
value = value.strip.split(/\s*,\s*/)
|
||||
value = value.collect(&block) if block_given?
|
||||
value
|
||||
else
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module InheritedReader
|
||||
def inherited_reader(constant_name)
|
||||
base_class = inherited_base
|
||||
result = base_class.const_get(constant_name)
|
||||
found_base_class = false
|
||||
ancestors.reverse_each do |klass|
|
||||
if found_base_class
|
||||
if klass.const_defined?(constant_name)
|
||||
result = yield(result, klass.const_get(constant_name))
|
||||
end
|
||||
else
|
||||
found_base_class = klass == base_class
|
||||
end
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def inherited_array_reader(constant_name)
|
||||
inherited_reader(constant_name) do |result, current|
|
||||
current + result
|
||||
end
|
||||
end
|
||||
|
||||
def inherited_hash_reader(constant_name)
|
||||
inherited_reader(constant_name) do |result, current|
|
||||
result.merge(current)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue