Module: Html2rss::Syndication::Parser
- Defined in:
- lib/html2rss/syndication/parser.rb
Overview
Parses RSS 2.0 and Atom documents into AutoSource article hashes.
Class Method Summary collapse
- .parse(body, base_url: nil) ⇒ Array<Hash{Symbol => Object}>
-
.parse_response(response) ⇒ Array<Hash{Symbol => Object}>
Article hashes (may be empty).
Class Method Details
.parse(body, base_url: nil) ⇒ Array<Hash{Symbol => Object}>
26 27 28 29 30 31 32 33 34 |
# File 'lib/html2rss/syndication/parser.rb', line 26 def parse(body, base_url: nil) feed = RSS::Parser.parse(body.to_s, false) return [] unless feed items_from(feed, base_url:).filter_map { |item| article_hash(item, base_url:) } rescue RSS::Error => error Log.warn("Syndication::Parser: failed to parse feed (#{error.class}: #{error.})") [] end |
.parse_response(response) ⇒ Array<Hash{Symbol => Object}>
Returns article hashes (may be empty).
16 17 18 19 20 |
# File 'lib/html2rss/syndication/parser.rb', line 16 def parse_response(response) raise ArgumentError, 'response is not a syndication feed' unless response.feed_response? parse(response.body, base_url: response.url) end |