Class: RSS::Parser
Constant Summary collapse
- @@default_parser =
nil
Class Method Summary collapse
- .default_parser ⇒ Object
-
.default_parser=(new_value) ⇒ Object
Set @@default_parser to new_value if it is one of the available parsers.
- .parse(rss, *args) ⇒ Object
Instance Method Summary collapse
-
#initialize(rss, parser_class = self.class.default_parser) ⇒ Parser
constructor
A new instance of Parser.
Constructor Details
#initialize(rss, parser_class = self.class.default_parser) ⇒ Parser
Returns a new instance of Parser.
107 108 109 |
# File 'lib/rss/parser.rb', line 107 def initialize(rss, parser_class=self.class.default_parser) @parser = parser_class.new(normalize_rss(rss)) end |
Class Method Details
.default_parser ⇒ Object
61 62 63 |
# File 'lib/rss/parser.rb', line 61 def default_parser @@default_parser || AVAILABLE_PARSERS.first end |
.default_parser=(new_value) ⇒ Object
Set @@default_parser to new_value if it is one of the available parsers. Else raise NotValidXMLParser error.
67 68 69 70 71 72 73 |
# 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 |
.parse(rss, *args) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rss/parser.rb', line 75 def parse(rss, *args) if args.last.is_a?(Hash) = args.pop else = {} end do_validate = boolean_argument(args[0], [:validate], true) ignore_unknown_element = boolean_argument(args[1], [:ignore_unknown_element], true) parser_class = args[2] || [:parser_class] || default_parser parser = new(rss, parser_class) parser.do_validate = do_validate parser.ignore_unknown_element = ignore_unknown_element parser.parse end |