Class: FeedNormalizer::FeedNormalizer
- Inherits:
-
Object
- Object
- FeedNormalizer::FeedNormalizer
- Defined in:
- lib/feed-normalizer.rb
Class Method Summary collapse
-
.parse(xml, opts = {}) ⇒ Object
Parses the given xml and attempts to return a normalized Feed object.
Class Method Details
.parse(xml, opts = {}) ⇒ Object
Parses the given xml and attempts to return a normalized Feed object. Setting forced parser to a suitable parser will mean that parser is used first, and if try_others is false, it is the only parser used, otherwise all parsers in the ParserRegistry are attempted next, in order of priority.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/feed-normalizer.rb', line 92 def self.parse(xml, opts = {}) # Get a string ASAP, as multiple read()'s will start returning nil.. xml = xml.respond_to?(:read) ? xml.read : xml.to_s if opts[:force_parser] result = opts[:force_parser].parse(xml) return result if result return nil if opts[:try_others] == false end ParserRegistry.parsers.each do |parser| result = parser.parse(xml) return result if result end # if we got here, no parsers worked. return nil end |