Class: Yarss::Atom::FeedParser
- Inherits:
-
Object
- Object
- Yarss::Atom::FeedParser
- Defined in:
- lib/yarss/atom/feed_parser.rb
Overview
Extract title, link, description and items from a parsed Atom feed.
Instance Attribute Summary collapse
-
#data ⇒ Hash
Parsed Atom feed.
Instance Method Summary collapse
-
#description ⇒ String
Extract the description.
-
#feed ⇒ Hash
Extract the feed data.
-
#initialize(data) ⇒ FeedParser
constructor
A new instance of FeedParser.
-
#items ⇒ Array<Item>
Extract and parse the items.
-
#link ⇒ String
Extract the link.
-
#parse ⇒ Feed
Parse out the feed title, link, description and items and wrap them in a data object.
-
#title ⇒ String
Extract the title.
Constructor Details
#initialize(data) ⇒ FeedParser
Returns a new instance of FeedParser.
18 19 20 |
# File 'lib/yarss/atom/feed_parser.rb', line 18 def initialize(data) self.data = data end |
Instance Attribute Details
#data ⇒ Hash
Parsed Atom feed.
15 16 17 |
# File 'lib/yarss/atom/feed_parser.rb', line 15 def data @data end |
Instance Method Details
#description ⇒ String
Extract the description.
69 70 71 |
# File 'lib/yarss/atom/feed_parser.rb', line 69 def description Attribute.value(feed['subtitle'] || '') end |
#feed ⇒ Hash
Extract the feed data.
42 43 44 45 46 |
# File 'lib/yarss/atom/feed_parser.rb', line 42 def feed @feed ||= data.fetch('feed') rescue KeyError => e raise ParseError, e end |
#items ⇒ Array<Item>
Extract and parse the items.
78 79 80 81 82 83 84 |
# File 'lib/yarss/atom/feed_parser.rb', line 78 def items items = feed.fetch('entry') items = [items] unless items.is_a?(Array) items.map { |d| ItemParser.new(d).parse } rescue KeyError => e raise ParseError, e end |
#link ⇒ String
Extract the link.
62 63 64 |
# File 'lib/yarss/atom/feed_parser.rb', line 62 def link Attribute.link_value(feed['link'] || '') end |
#parse ⇒ Feed
Parse out the feed title, link, description and items and wrap them in a data object.
28 29 30 31 32 33 34 35 |
# File 'lib/yarss/atom/feed_parser.rb', line 28 def parse Feed.new( title: title, link: link, description: description, items: items ) end |
#title ⇒ String
Extract the title.
53 54 55 56 57 |
# File 'lib/yarss/atom/feed_parser.rb', line 53 def title Attribute.value(feed.fetch('title')) rescue KeyError => e raise ParseError, e end |