class RSS::Parser
Public Class Methods
default_parser()
click to toggle source
# File lib/rss/parser.rb, line 60 def default_parser @@default_parser || AVAILABLE_PARSERS.first end
default_parser=(new_value)
click to toggle source
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 def default_parser=(new_value) if AVAILABLE_PARSERS.include?(new_value) @@default_parser = new_value else raise NotValidXMLParser.new(new_value) end end
new(rss, parser_class=self.class.default_parser)
click to toggle source
# File lib/rss/parser.rb, line 88 def initialize(rss, parser_class=self.class.default_parser) @parser = parser_class.new(normalize_rss(rss)) end
parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser)
click to toggle source
# File lib/rss/parser.rb, line 74 def parse(rss, do_validate=true, ignore_unknown_element=true, parser_class=default_parser) parser = new(rss, parser_class) parser.do_validate = do_validate parser.ignore_unknown_element = ignore_unknown_element parser.parse end
Private Instance Methods
maybe_xml?(source)
click to toggle source
maybe_xml? tests if source is a string that looks like XML.
# File lib/rss/parser.rb, line 112 def maybe_xml?(source) source.is_a?(String) and /</ =~ source end
normalize_rss(rss)
click to toggle source
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 def normalize_rss(rss) return rss if maybe_xml?(rss) uri = to_uri(rss) if uri.respond_to?(:read) uri.read elsif !rss.tainted? and File.readable?(rss) File.open(rss) {|f| f.read} else rss end end
to_uri(rss)
click to toggle source
Attempt to convert rss to a URI, but just return it if there's a ::URI::Error
# File lib/rss/parser.rb, line 118 def to_uri(rss) return rss if rss.is_a?(::URI::Generic) begin ::URI.parse(rss) rescue ::URI::Error rss end end