Class: GoogleContactsApi::ResultSet
- Inherits:
-
Object
- Object
- GoogleContactsApi::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/google_contacts_api/result_set.rb
Overview
Base class for GroupSet and ContactSet
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
-
#items_per_page ⇒ Object
Returns the value of attribute items_per_page.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#start_index ⇒ Object
Returns the value of attribute start_index.
-
#total_results ⇒ Object
Returns the value of attribute total_results.
Instance Method Summary collapse
-
#each ⇒ Object
Yields to block for each result.
-
#has_more? ⇒ Boolean
Return true if there are more results with the same parameters you used.
-
#initialize(response_body, api = nil) ⇒ ResultSet
constructor
Initialize a new ResultSet from the response, with the given GoogleContacts::Api object if specified.
-
#inspect ⇒ Object
:nodoc:.
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
#api ⇒ Object (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_page ⇒ Object
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 |
#parsed ⇒ Object
Returns the value of attribute parsed.
8 9 10 |
# File 'lib/google_contacts_api/result_set.rb', line 8 def parsed @parsed end |
#start_index ⇒ Object
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_results ⇒ Object
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
#each ⇒ Object
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
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 |
#inspect ⇒ Object
: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 |