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.
-
#feed_link ⇒ String
Feed link URL.
Instance Method Summary collapse
-
#author ⇒ String
Extract the author.
-
#description ⇒ String
Extract the description.
-
#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
Returns a new instance of ItemParser.
19 20 21 22 |
# File 'lib/yarss/rdf/item_parser.rb', line 19 def initialize(data, feed_link: '') self.data = data self.feed_link = feed_link 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 |
#feed_link ⇒ String
Feed link URL.
15 16 17 |
# File 'lib/yarss/rdf/item_parser.rb', line 15 def feed_link @feed_link end |
Instance Method Details
#author ⇒ String
Extract the author.
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/yarss/rdf/item_parser.rb', line 99 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.
114 115 116 117 118 119 |
# File 'lib/yarss/rdf/item_parser.rb', line 114 def description description = Attribute.value(data.fetch('description')) Attribute.absolutize_urls(description, feed_link) rescue KeyError => e raise ParseError, e end |
#id ⇒ String
Extract the ID.
46 47 48 49 50 51 52 53 54 |
# File 'lib/yarss/rdf/item_parser.rb', line 46 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.
88 89 90 91 92 |
# File 'lib/yarss/rdf/item_parser.rb', line 88 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.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/yarss/rdf/item_parser.rb', line 30 def parse Item.new( id: id, title: title, updated_at: updated, link: link, author: , content: description ) end |
#title ⇒ String
Extract the title.
61 62 63 64 65 |
# File 'lib/yarss/rdf/item_parser.rb', line 61 def title Attribute.value(data.fetch('title')) rescue KeyError => e raise ParseError, e end |
#updated ⇒ DateTime
Extract the updated date.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/yarss/rdf/item_parser.rb', line 72 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 |