| Class | RSS::Parser |
| In: |
lib/rss/parser.rb
|
| Parent: | Object |
# File lib/rss/parser.rb, line 59
59: def default_parser
60: @@default_parser || AVAILABLE_PARSERS.first
61: 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 65
65: def default_parser=(new_value)
66: if AVAILABLE_PARSERS.include?(new_value)
67: @@default_parser = new_value
68: else
69: raise NotValidXMLParser.new(new_value)
70: end
71: end
# File lib/rss/parser.rb, line 87
87: def initialize(rss, parser_class=self.class.default_parser)
88: @parser = parser_class.new(normalize_rss(rss))
89: end
# File lib/rss/parser.rb, line 73
73: def parse(rss, do_validate=true, ignore_unknown_element=true,
74: parser_class=default_parser)
75: parser = new(rss, parser_class)
76: parser.do_validate = do_validate
77: parser.ignore_unknown_element = ignore_unknown_element
78: parser.parse
79: end
maybe_xml? tests if source is a string that looks like XML.
# File lib/rss/parser.rb, line 111
111: def maybe_xml?(source)
112: source.is_a?(String) and /</ =~ source
113: 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 96
96: def normalize_rss(rss)
97: return rss if maybe_xml?(rss)
98:
99: uri = to_uri(rss)
100:
101: if uri.respond_to?(:read)
102: uri.read
103: elsif !rss.tainted? and File.readable?(rss)
104: File.open(rss) {|f| f.read}
105: else
106: rss
107: end
108: end
Attempt to convert rss to a URI, but just return it if there‘s a ::URI::Error
# File lib/rss/parser.rb, line 117
117: def to_uri(rss)
118: return rss if rss.is_a?(::URI::Generic)
119:
120: begin
121: URI(rss)
122: rescue ::URI::Error
123: rss
124: end
125: end