Class: RSS::Parser
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | lib/rss/parser.rb |
Class Attribute Summary
- .default_parser rw
-
.default_parser=(new_value)
rw
Set @@default_parser to new_value if it is one of the available parsers.
Class Method Summary
Instance Method Summary
-
#maybe_xml?(source) ⇒ Boolean
private
maybe_xml? tests if source is a string that looks like XML.
-
#normalize_rss(rss)
private
Try to get the XML associated with
rss
. -
#to_uri(rss)
private
Attempt to convert rss to a URI, but just return it if there's a ::URI::Error.
Constructor Details
.new(rss, parser_class = self.class.default_parser) ⇒ Parser
# File 'lib/rss/parser.rb', line 89
def initialize(rss, parser_class=self.class.default_parser) @parser = parser_class.new(normalize_rss(rss)) end
Class Attribute Details
.default_parser (rw)
[ GitHub ]# File 'lib/rss/parser.rb', line 61
def default_parser @@default_parser || AVAILABLE_PARSERS.first end
.default_parser=(new_value) (rw)
Set @@default_parser to new_value if it is one of the available parsers. Else raise NotValidXMLParser error.
# File 'lib/rss/parser.rb', line 67
def default_parser=(new_value) if AVAILABLE_PARSERS.include?(new_value) @@default_parser = new_value else raise NotValidXMLParser.new(new_value) end end
Class Method Details
.parse(rss, do_validate = true, ignore_unknown_element = true, parser_class = default_parser)
[ GitHub ]# File 'lib/rss/parser.rb', line 75
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
Instance Method Details
#maybe_xml?(source) ⇒ Boolean
(private)
maybe_xml? tests if source is a string that looks like XML.
# File 'lib/rss/parser.rb', line 113
def maybe_xml?(source) source.is_a?(String) and /</ =~ source end
#normalize_rss(rss) (private)
# File 'lib/rss/parser.rb', line 98
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) (private)
Attempt to convert rss to a URI, but just return it if there's a ::URI::Error