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 that generically represents a set of results.
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.
13 14 15 16 17 18 19 20 |
# File 'lib/google_contacts_api/result_set.rb', line 13 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.
8 9 10 |
# File 'lib/google_contacts_api/result_set.rb', line 8 def api @api end |
#items_per_page ⇒ Object
Returns the value of attribute items_per_page.
9 10 11 |
# File 'lib/google_contacts_api/result_set.rb', line 9 def items_per_page @items_per_page end |
#parsed ⇒ Object
Returns the value of attribute parsed.
9 10 11 |
# File 'lib/google_contacts_api/result_set.rb', line 9 def parsed @parsed end |
#start_index ⇒ Object
Returns the value of attribute start_index.
9 10 11 |
# File 'lib/google_contacts_api/result_set.rb', line 9 def start_index @start_index end |
#total_results ⇒ Object
Returns the value of attribute total_results.
9 10 11 |
# File 'lib/google_contacts_api/result_set.rb', line 9 def total_results @total_results end |
Instance Method Details
#each ⇒ Object
Yields to block for each result. Returns an Enumerator if no block is passed.
24 25 26 27 |
# File 'lib/google_contacts_api/result_set.rb', line 24 def each return to_enum(:each) unless block_given? @results.each { |x| yield x } end |
#has_more? ⇒ Boolean
Return true if there are more results with the same parameters you used
31 32 33 34 |
# File 'lib/google_contacts_api/result_set.rb', line 31 def has_more? # 1-based indexing @start_index - 1 + @items_per_page <= @total_results end |
#inspect ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/google_contacts_api/result_set.rb', line 36 def inspect #:nodoc: "<#{self.class}: @start_index=#{@start_index}, @items_per_page=#{@items_per_page}, @total_results=#{@total_results}>" end |