Class: Yarss::Rdf::ItemParser
- Inherits:
-
Object
- Object
- Yarss::Rdf::ItemParser
- Defined in:
- lib/yarss/rdf/item_parser.rb
Overview
Extract id, title, updated, link and content from a feed item.
Instance Attribute Summary collapse
-
#data ⇒ Hash
Parsed Rdf feed item.
Instance Method Summary collapse
-
#description ⇒ String
Extract the description.
-
#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.
13 14 15 |
# File 'lib/yarss/rdf/item_parser.rb', line 13 def initialize(data) self.data = data end |
Instance Attribute Details
#data ⇒ Hash
Parsed Rdf feed item.
10 11 12 |
# File 'lib/yarss/rdf/item_parser.rb', line 10 def data @data end |
Instance Method Details
#description ⇒ String
Extract the description.
89 90 91 92 93 |
# File 'lib/yarss/rdf/item_parser.rb', line 89 def description Attribute.value(data.fetch('description')) rescue KeyError => e raise ParseError, e end |
#id ⇒ String
Extract the ID.
38 39 40 41 42 43 44 45 46 |
# File 'lib/yarss/rdf/item_parser.rb', line 38 def id if data['about'] data['about'] else data.fetch('rdf:about') end rescue KeyError => e raise ParseError, e end |
#link ⇒ String
Extract the link.
80 81 82 83 84 |
# File 'lib/yarss/rdf/item_parser.rb', line 80 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.
23 24 25 26 27 28 29 30 31 |
# File 'lib/yarss/rdf/item_parser.rb', line 23 def parse Item.new( id: id, title: title, updated_at: updated, link: link, content: description ) end |
#title ⇒ String
Extract the title.
53 54 55 56 57 |
# File 'lib/yarss/rdf/item_parser.rb', line 53 def title Attribute.value(data.fetch('title')) rescue KeyError => e raise ParseError, e end |
#updated ⇒ DateTime
Extract the updated date.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/yarss/rdf/item_parser.rb', line 64 def updated date = if data['date'] data['date'] else data.fetch('dc:date') end DateTime.parse(date) rescue KeyError, ArgumentError => e raise ParseError, e end |