diff options
| author | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-29 09:12:56 +0000 |
|---|---|---|
| committer | kou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-29 09:12:56 +0000 |
| commit | 51bd9cada87c6f07499d767dc712f0177cb19a08 (patch) | |
| tree | d8163b71056db73ec20a0a32dbdf552cefac0833 /lib/rss/parser.rb | |
| parent | 8272251f6dd058fab4e34150525f345eebb5693c (diff) | |
* NEWS: add an entry for rss.
* lib/rss/, test/rss/: merge from trunk.
- 0.2.4 -> 0.2.5.
- RSS::Maker.make raise an exception not returns nil for invalid
feed making.
- RSS::Maker.make requires block.
- don't use instance_variable to initialize variables. (speed up)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@17677 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rss/parser.rb')
| -rw-r--r-- | lib/rss/parser.rb | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/rss/parser.rb b/lib/rss/parser.rb index 9e4919223c..9b28f0fa8a 100644 --- a/lib/rss/parser.rb +++ b/lib/rss/parser.rb @@ -34,8 +34,8 @@ module RSS class NotValidXMLParser < Error def initialize(parser) super("#{parser} is not an available XML parser. " << - "Available XML parser"<< - (AVAILABLE_PARSERS.size > 1 ? "s are ": " is ") << + "Available XML parser" << + (AVAILABLE_PARSERS.size > 1 ? "s are " : " is ") << "#{AVAILABLE_PARSERS.inspect}.") end end @@ -113,7 +113,7 @@ module RSS source.is_a?(String) and /</ =~ source end - # Attempt to convert rss to a URI, but just return it if + # Attempt to convert rss to a URI, but just return it if # there's a ::URI::Error def to_uri(rss) return rss if rss.is_a?(::URI::Generic) @@ -220,9 +220,7 @@ module RSS name = (@@class_names[uri] || {})[tag_name] return name if name - tag_name = tag_name.gsub(/[_\-]([a-z]?)/) do - $1.upcase - end + tag_name = tag_name.gsub(/[_\-]([a-z]?)/) {$1.upcase} tag_name[0, 1].upcase + tag_name[1..-1] end @@ -389,9 +387,7 @@ module RSS def start_else_element(local, prefix, attrs, ns) class_name = self.class.class_name(_ns(ns, prefix), local) current_class = @last_element.class - if class_name and - (current_class.const_defined?(class_name) or - current_class.constants.include?(class_name)) + if known_class?(current_class, class_name) next_class = current_class.const_get(class_name) start_have_something_element(local, prefix, attrs, ns, next_class) else @@ -407,6 +403,20 @@ module RSS end end + if Module.method(:const_defined?).arity == -1 + def known_class?(target_class, class_name) + class_name and + (target_class.const_defined?(class_name, false) or + target_class.constants.include?(class_name.to_sym)) + end + else + def known_class?(target_class, class_name) + class_name and + (target_class.const_defined?(class_name) or + target_class.constants.include?(class_name)) + end + end + NAMESPLIT = /^(?:([\w:][-\w\d.]*):)?([\w:][-\w\d.]*)/ def split_name(name) name =~ NAMESPLIT @@ -504,7 +514,7 @@ module RSS else if klass.have_content? if @last_element.need_base64_encode? - text = Base64.decode64(text.lstrip) + text = text.lstrip.unpack("m").first end @last_element.content = text end |
