Class | RSS::Parser |
In: |
lib/rss/parser.rb
|
Parent: | Object |
# File lib/rss/parser.rb, line 60 60: def default_parser 61: @@default_parser || AVAILABLE_PARSERS.first 62: end
Set @@default_parser to new_value if it is one of the available parsers. Else raise NotValidXMLParser error.
# File lib/rss/parser.rb, line 66 66: def default_parser=(new_value) 67: if AVAILABLE_PARSERS.include?(new_value) 68: @@default_parser = new_value 69: else 70: raise NotValidXMLParser.new(new_value) 71: end 72: end
# File lib/rss/parser.rb, line 88 88: def initialize(rss, parser_class=self.class.default_parser) 89: @parser = parser_class.new(normalize_rss(rss)) 90: end
# File lib/rss/parser.rb, line 74 74: def parse(rss, do_validate=true, ignore_unknown_element=true, 75: parser_class=default_parser) 76: parser = new(rss, parser_class) 77: parser.do_validate = do_validate 78: parser.ignore_unknown_element = ignore_unknown_element 79: parser.parse 80: end
maybe_xml? tests if source is a string that looks like XML.
# File lib/rss/parser.rb, line 112 112: def maybe_xml?(source) 113: source.is_a?(String) and /</ =~ source 114: end
Try to get the XML associated with rss. Return rss if it already looks like XML, or treat it as a URI, or a file to get the XML,
# File lib/rss/parser.rb, line 97 97: def normalize_rss(rss) 98: return rss if maybe_xml?(rss) 99: 100: uri = to_uri(rss) 101: 102: if uri.respond_to?(:read) 103: uri.read 104: elsif !rss.tainted? and File.readable?(rss) 105: File.open(rss) {|f| f.read} 106: else 107: rss 108: end 109: end
Attempt to convert rss to a URI, but just return it if there‘s a ::URI::Error
# File lib/rss/parser.rb, line 118 118: def to_uri(rss) 119: return rss if rss.is_a?(::URI::Generic) 120: 121: begin 122: ::URI.parse(rss) 123: rescue ::URI::Error 124: rss 125: end 126: end