Class: Yarss::Atom::ItemParser
- Inherits:
-
Object
- Object
- Yarss::Atom::ItemParser
- Defined in:
- lib/yarss/atom/item_parser.rb
Overview
Extract id, title, updated, link and content from a feed item.
atomenabled.org/developers/syndication/#requiredEntryElements
Instance Attribute Summary collapse
-
#data ⇒ Hash
Parsed Atom feed item.
-
#feed_link ⇒ String
Feed link URL.
Instance Method Summary collapse
-
#author ⇒ String
Extract the author.
-
#content ⇒ String
Extract the content.
-
#id ⇒ String
Extract the ID.
-
#initialize(data, feed_link: '') ⇒ ItemParser
constructor
A new instance of ItemParser.
-
#link ⇒ String
Extract the link.
-
#parse ⇒ Item
Parse out the feed item id, title, updated, link and content and wrap them in a data object.
-
#title ⇒ String
Extract the title.
-
#updated ⇒ DateTime
Extract the updated date.
Constructor Details
#initialize(data, feed_link: '') ⇒ ItemParser
21 22 23 24 |
# File 'lib/yarss/atom/item_parser.rb', line 21 def initialize(data, feed_link: '') self.data = data self.feed_link = feed_link end |
Instance Attribute Details
#data ⇒ Hash
Parsed Atom feed item.
12 13 14 |
# File 'lib/yarss/atom/item_parser.rb', line 12 def data @data end |
#feed_link ⇒ String
Feed link URL.
17 18 19 |
# File 'lib/yarss/atom/item_parser.rb', line 17 def feed_link @feed_link end |
Instance Method Details
#author ⇒ String
Extract the author.
92 93 94 |
# File 'lib/yarss/atom/item_parser.rb', line 92 def Attribute.(data['author'] || '') end |
#content ⇒ String
Extract the content.
99 100 101 102 103 104 105 |
# File 'lib/yarss/atom/item_parser.rb', line 99 def content summary = Attribute.value(data['summary'] || '') content = Attribute.value(data['content'] || '') content = summary if content.empty? Attribute.absolutize_urls(content, feed_link) end |
#id ⇒ String
Extract the ID.
48 49 50 51 52 |
# File 'lib/yarss/atom/item_parser.rb', line 48 def id data.fetch('id') rescue KeyError => e raise ParseError, e end |
#link ⇒ String
Extract the link.
81 82 83 84 85 |
# File 'lib/yarss/atom/item_parser.rb', line 81 def link Attribute.link_value(data.fetch('link')) rescue KeyError => e raise ParseError, e end |
#parse ⇒ Item
Parse out the feed item id, title, updated, link and content and wrap them in a data object.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/yarss/atom/item_parser.rb', line 32 def parse Item.new( id: id, title: title, updated_at: updated, link: link, author: , content: content ) end |
#title ⇒ String
Extract the title.
59 60 61 62 63 |
# File 'lib/yarss/atom/item_parser.rb', line 59 def title Attribute.value(data.fetch('title')) rescue KeyError => e raise ParseError, e end |
#updated ⇒ DateTime
Extract the updated date.
70 71 72 73 74 |
# File 'lib/yarss/atom/item_parser.rb', line 70 def updated DateTime.parse(data.fetch('updated')) rescue KeyError, ArgumentError => e raise ParseError, e end |