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
-
#author ⇒ String
Extract the author.
-
#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
#author ⇒ String
Extract the author.
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/yarss/rdf/item_parser.rb', line 92 def = if data['dc:creator'] data['dc:creator'] else data.fetch('creator') end Attribute.value() rescue KeyError => e raise ParseError, e end |
#description ⇒ String
Extract the description.
107 108 109 110 111 |
# File 'lib/yarss/rdf/item_parser.rb', line 107 def description Attribute.value(data.fetch('description')) rescue KeyError => e raise ParseError, e end |
#id ⇒ String
Extract the ID.
39 40 41 42 43 44 45 46 47 |
# File 'lib/yarss/rdf/item_parser.rb', line 39 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.
81 82 83 84 85 |
# File 'lib/yarss/rdf/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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/yarss/rdf/item_parser.rb', line 23 def parse Item.new( id: id, title: title, updated_at: updated, link: link, author: , content: description ) end |
#title ⇒ String
Extract the title.
54 55 56 57 58 |
# File 'lib/yarss/rdf/item_parser.rb', line 54 def title Attribute.value(data.fetch('title')) rescue KeyError => e raise ParseError, e end |
#updated ⇒ DateTime
Extract the updated date.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/yarss/rdf/item_parser.rb', line 65 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 |