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.
Instance Method Summary collapse
-
#content ⇒ String
Extract the content.
-
#id ⇒ String
Extract the ID.
-
#initialize(data) ⇒ 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) ⇒ ItemParser
Returns a new instance of ItemParser.
15 16 17 |
# File 'lib/yarss/atom/item_parser.rb', line 15 def initialize(data) self.data = data 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 |
Instance Method Details
#content ⇒ String
Extract the content.
82 83 84 85 86 87 |
# File 'lib/yarss/atom/item_parser.rb', line 82 def content summary = Attribute.value(data['summary'] || '') content = Attribute.value(data['content'] || '') return content unless content.empty? summary end |
#id ⇒ String
Extract the ID.
40 41 42 43 44 |
# File 'lib/yarss/atom/item_parser.rb', line 40 def id data.fetch('id') rescue KeyError => e raise ParseError, e end |
#link ⇒ String
Extract the link.
73 74 75 76 77 |
# File 'lib/yarss/atom/item_parser.rb', line 73 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.
25 26 27 28 29 30 31 32 33 |
# File 'lib/yarss/atom/item_parser.rb', line 25 def parse Item.new( id: id, title: title, updated_at: updated, link: link, content: content ) end |
#title ⇒ String
Extract the title.
51 52 53 54 55 |
# File 'lib/yarss/atom/item_parser.rb', line 51 def title Attribute.value(data.fetch('title')) rescue KeyError => e raise ParseError, e end |
#updated ⇒ DateTime
Extract the updated date.
62 63 64 65 66 |
# File 'lib/yarss/atom/item_parser.rb', line 62 def updated DateTime.parse(data.fetch('updated')) rescue KeyError, ArgumentError => e raise ParseError, e end |