Class: Yarss::Rdf::FeedParser
- Inherits:
-
Object
- Object
- Yarss::Rdf::FeedParser
- Defined in:
- lib/yarss/rdf/feed_parser.rb
Overview
Extract title, link, description and items from a parsed Rdf feed.
Instance Attribute Summary collapse
-
#data ⇒ Hash
Parsed Rdf feed.
Instance Method Summary collapse
-
#channel ⇒ Hash
Extract the channel data.
-
#description ⇒ String
Extract the description.
-
#feed ⇒ Hash
Extract the feed data.
-
#initialize(data) ⇒ FeedParser
constructor
A new instance of FeedParser.
-
#items ⇒ Array<Item>
Extract and parse the items.
-
#link ⇒ String
Extract the link.
-
#parse ⇒ Feed
Parse out the feed title, link, description and items and wrap them in a data object.
-
#title ⇒ String
Extract the title.
Constructor Details
#initialize(data) ⇒ FeedParser
Returns a new instance of FeedParser.
18 19 20 |
# File 'lib/yarss/rdf/feed_parser.rb', line 18 def initialize(data) self.data = data end |
Instance Attribute Details
#data ⇒ Hash
Parsed Rdf feed.
15 16 17 |
# File 'lib/yarss/rdf/feed_parser.rb', line 15 def data @data end |
Instance Method Details
#channel ⇒ Hash
Extract the channel data.
59 60 61 62 63 |
# File 'lib/yarss/rdf/feed_parser.rb', line 59 def channel @channel ||= feed.fetch('channel') rescue KeyError => e raise ParseError, e end |
#description ⇒ String
Extract the description.
90 91 92 93 94 |
# File 'lib/yarss/rdf/feed_parser.rb', line 90 def description Attribute.value(channel.fetch('description')) rescue KeyError => e raise ParseError, e end |
#feed ⇒ Hash
Extract the feed data.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/yarss/rdf/feed_parser.rb', line 42 def feed @feed ||= begin if data['RDF'] data['RDF'] else data.fetch('rdf:RDF') end end rescue KeyError => e raise ParseError, e end |
#items ⇒ Array<Item>
Extract and parse the items.
101 102 103 104 105 106 107 |
# File 'lib/yarss/rdf/feed_parser.rb', line 101 def items items = feed.fetch('item') items = [items] unless items.is_a?(Array) items.map { |d| ItemParser.new(d).parse } rescue KeyError => e raise ParseError, e end |
#link ⇒ String
Extract the link.
81 82 83 84 85 |
# File 'lib/yarss/rdf/feed_parser.rb', line 81 def link Attribute.link_value(channel.fetch('link')) rescue KeyError => e raise ParseError, e end |
#parse ⇒ Feed
Parse out the feed title, link, description and items and wrap them in a data object.
28 29 30 31 32 33 34 35 |
# File 'lib/yarss/rdf/feed_parser.rb', line 28 def parse Feed.new( title: title, link: link, description: description, items: items ) end |
#title ⇒ String
Extract the title.
70 71 72 73 74 |
# File 'lib/yarss/rdf/feed_parser.rb', line 70 def title Attribute.value(channel.fetch('title')) rescue KeyError => e raise ParseError, e end |