Class: GoApiClient::Atom::FeedPage

Inherits:
Object
  • Object
show all
Includes:
Helpers::SimpleAttributesSupport
Defined in:
lib/go_api_client/atom/feed_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, attributes = {}) ⇒ FeedPage

Returns a new instance of FeedPage.



9
10
11
12
# File 'lib/go_api_client/atom/feed_page.rb', line 9

def initialize(root, attributes={})
  @root = root
  super(attributes)
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



5
6
7
# File 'lib/go_api_client/atom/feed_page.rb', line 5

def entries
  @entries
end

#next_pageObject

Returns the value of attribute next_page.



5
6
7
# File 'lib/go_api_client/atom/feed_page.rb', line 5

def next_page
  @next_page
end

#updated_atObject

Returns the value of attribute updated_at.



5
6
7
# File 'lib/go_api_client/atom/feed_page.rb', line 5

def updated_at
  @updated_at
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/go_api_client/atom/feed_page.rb', line 5

def url
  @url
end

Instance Method Details

#contains_entry?(entry_or_id) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/go_api_client/atom/feed_page.rb', line 35

def contains_entry?(entry_or_id)
  if entry_or_id.is_a?(String)
    entries.find {|e| e.id == entry_or_id}
  else
    entries.include?(entry_or_id)
  end
end

#entries_after(entry_or_id) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/go_api_client/atom/feed_page.rb', line 25

def entries_after(entry_or_id)
  index = if entry_or_id.is_a?(String)
            entries.find_index {|e| e.id == entry_or_id}
          else
            entries.find_index {|e| e == entry_or_id}
          end

  index.zero? ? [] : entries[0..index-1]
end

#parse!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/go_api_client/atom/feed_page.rb', line 14

def parse!
  self.updated_at = Time.parse(@root.xpath('xmlns:updated').first.content).utc
  self.next_page  = href_from(@root.xpath("xmlns:link[@rel='next']"))
  self.url        = href_from(@root.xpath("xmlns:link[@rel='self']"))
  self.entries    = @root.xpath("xmlns:entry").collect do |entry|
    Entry.new(entry).parse!
  end
  @root = nil
  self
end