Class: Oos4ruby::Feed
- Inherits:
-
Object
- Object
- Oos4ruby::Feed
- Defined in:
- lib/oos4ruby/feed.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#next ⇒ Object
readonly
Returns the value of attribute next.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#total_size ⇒ Object
readonly
Returns the value of attribute total_size.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(entries, xml) ⇒ Feed
constructor
A new instance of Feed.
- #next? ⇒ Boolean
- #previous? ⇒ Boolean
- #self_link ⇒ Object
- #self_link? ⇒ Boolean
Constructor Details
#initialize(entries, xml) ⇒ Feed
9 10 11 12 13 14 15 16 17 |
# File 'lib/oos4ruby/feed.rb', line 9 def initialize(entries, xml) @entries = entries @xml = xml @next = Feed.get_link('next', xml) @previous = Feed.get_link 'previous', xml @self = Feed.get_link 'self', xml @size = REXML::XPath.first(xml, "./os:itemsPerPage/text()", XmlNamespaces) @total_size = REXML::XPath.first(xml, "./os:totalResults/text()", XmlNamespaces) end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def entries @entries end |
#next ⇒ Object (readonly)
Returns the value of attribute next.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def next @next end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def previous @previous end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def size @size end |
#total_size ⇒ Object (readonly)
Returns the value of attribute total_size.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def total_size @total_size end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
7 8 9 |
# File 'lib/oos4ruby/feed.rb', line 7 def xml @xml end |
Class Method Details
.get_link(rel, xml) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/oos4ruby/feed.rb', line 19 def self.get_link(rel, xml) link = REXML::XPath.first(xml, "./atom:link[@rel=\"#{rel}\"]", XmlNamespaces) if link uri = URI.parse link.attributes['href'] if uri.absolute? return uri else return URI.parse(OOS_URL).merge(uri) end end end |
.read(body) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/oos4ruby/feed.rb', line 31 def Feed.read(body) feed = nil begin feed = REXML::Document.new(body, { :raw => nil }).root entries = REXML::XPath.match(feed, "./atom:entry", XmlNamespaces) entries.map! { |entry| Entry.new(entry) } feed = Feed.new( entries, feed ) rescue => ex puts ex. puts ex.backtrace.join("\n") end return feed end |
Instance Method Details
#next? ⇒ Boolean
61 62 63 |
# File 'lib/oos4ruby/feed.rb', line 61 def next? !@next.nil? end |
#previous? ⇒ Boolean
57 58 59 |
# File 'lib/oos4ruby/feed.rb', line 57 def previous? !@previous.nil? end |
#self_link ⇒ Object
49 50 51 |
# File 'lib/oos4ruby/feed.rb', line 49 def self_link @self end |
#self_link? ⇒ Boolean
53 54 55 |
# File 'lib/oos4ruby/feed.rb', line 53 def self_link? !@self.nil? end |