Class: RssFeed::Parser
Overview
The Parser class is responsible for parsing RSS feeds.
Instance Attribute Summary collapse
-
#feed_urls ⇒ Object
readonly
Returns the value of attribute feed_urls.
-
#uri_parser ⇒ Object
readonly
Returns the value of attribute uri_parser.
-
#xml_parser ⇒ Object
readonly
Returns the value of attribute xml_parser.
Instance Method Summary collapse
-
#initialize(feed_urls, options = {}) ⇒ Parser
constructor
Initialize the Parser with a list of feed URLs.
-
#parse ⇒ Hash
Parse the RSS feeds and extract channel and item information.
- #parse_as_object ⇒ Object
Constructor Details
#initialize(feed_urls, options = {}) ⇒ Parser
Initialize the Parser with a list of feed URLs.
19 20 21 22 23 24 25 |
# File 'lib/rss_feed/parser.rb', line 19 def initialize(feed_urls, = {}) @feed_urls = feed_urls @xml_parser = .fetch(:xml_parser, Nokogiri) @uri_parser = .fetch(:uri_parser, URI) @timeout = .fetch(:timeout, 10) # Default timeout: 10 seconds @logger = [:logger] end |
Instance Attribute Details
#feed_urls ⇒ Object (readonly)
Returns the value of attribute feed_urls.
14 15 16 |
# File 'lib/rss_feed/parser.rb', line 14 def feed_urls @feed_urls end |
#uri_parser ⇒ Object (readonly)
Returns the value of attribute uri_parser.
14 15 16 |
# File 'lib/rss_feed/parser.rb', line 14 def uri_parser @uri_parser end |
#xml_parser ⇒ Object (readonly)
Returns the value of attribute xml_parser.
14 15 16 |
# File 'lib/rss_feed/parser.rb', line 14 def xml_parser @xml_parser end |
Instance Method Details
#parse ⇒ Hash
Parse the RSS feeds and extract channel and item information.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rss_feed/parser.rb', line 30 def parse document = fetch_and_parse_xml(feed_urls) channel = RssFeed::Feed::Channel.new(document) channel_info = extract_channel_info(channel) items = RssFeed::Feed::Item.new(document) item_info = extract_item_info(items) { 'channel' => channel_info, 'items' => item_info } end |
#parse_as_object ⇒ Object
41 42 43 |
# File 'lib/rss_feed/parser.rb', line 41 def parse_as_object DynamicObject.new(parse) end |