Class: GoogleContactsApi::ResultSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google_contacts_api/result_set.rb

Overview

Base class for GroupSet and ContactSet

Direct Known Subclasses

ContactSet, GroupSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response_body, api = nil) ⇒ ResultSet

Initialize a new ResultSet from the response, with the given GoogleContacts::Api object if specified.



12
13
14
15
16
17
18
19
# File 'lib/google_contacts_api/result_set.rb', line 12

def initialize(response_body, api = nil)
  @api = api
  @parsed = Hashie::Mash.new(JSON.parse(response_body))
  @total_results = @parsed.feed["openSearch$totalResults"]["$t"].to_i
  @start_index = @parsed.feed["openSearch$startIndex"]["$t"].to_i
  @items_per_page = @parsed.feed["openSearch$itemsPerPage"]["$t"].to_i
  @results = []
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



7
8
9
# File 'lib/google_contacts_api/result_set.rb', line 7

def api
  @api
end

#items_per_pageObject

Returns the value of attribute items_per_page.



8
9
10
# File 'lib/google_contacts_api/result_set.rb', line 8

def items_per_page
  @items_per_page
end

#parsedObject

Returns the value of attribute parsed.



8
9
10
# File 'lib/google_contacts_api/result_set.rb', line 8

def parsed
  @parsed
end

#start_indexObject

Returns the value of attribute start_index.



8
9
10
# File 'lib/google_contacts_api/result_set.rb', line 8

def start_index
  @start_index
end

#total_resultsObject

Returns the value of attribute total_results.



8
9
10
# File 'lib/google_contacts_api/result_set.rb', line 8

def total_results
  @total_results
end

Instance Method Details

#eachObject

Yields to block for each result



22
23
24
# File 'lib/google_contacts_api/result_set.rb', line 22

def each
  @results.each { |x| yield x }
end

#has_more?Boolean

Return true if there are more results with the same parameters you used

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/google_contacts_api/result_set.rb', line 28

def has_more?
  # 1-based indexing
  @start_index - 1 + @items_per_page <= @total_results
end

#inspectObject

:nodoc:



33
34
35
# File 'lib/google_contacts_api/result_set.rb', line 33

def inspect #:nodoc:
  "<#{self.class}: @start_index=#{@start_index}, @items_per_page=#{@items_per_page}, @total_results=#{@total_results}>"
end