Class: GoogleRest::Results
- Inherits:
-
Object
- Object
- GoogleRest::Results
- Defined in:
- lib/google_rest.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
Returns the value of attribute cursor.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#results ⇒ Object
Returns the value of attribute results.
Instance Method Summary collapse
- #each ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(raw) ⇒ Results
constructor
A new instance of Results.
- #map ⇒ Object
- #page ⇒ Object
- #pages ⇒ Object
- #paginated(current_page = nil) ⇒ Object
- #per_page ⇒ Object
- #total_entries ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(raw) ⇒ Results
Returns a new instance of Results.
12 13 14 15 16 17 |
# File 'lib/google_rest.rb', line 12 def initialize(raw) self.raw = raw data = (raw || {}) self.cursor = data["cursor"] self.results = data["results"] || [] end |
Instance Attribute Details
#cursor ⇒ Object
Returns the value of attribute cursor.
10 11 12 |
# File 'lib/google_rest.rb', line 10 def cursor @cursor end |
#raw ⇒ Object
Returns the value of attribute raw.
10 11 12 |
# File 'lib/google_rest.rb', line 10 def raw @raw end |
#results ⇒ Object
Returns the value of attribute results.
10 11 12 |
# File 'lib/google_rest.rb', line 10 def results @results end |
Instance Method Details
#each ⇒ Object
23 24 25 |
# File 'lib/google_rest.rb', line 23 def each results.each { |r| yield r } end |
#empty? ⇒ Boolean
19 20 21 |
# File 'lib/google_rest.rb', line 19 def empty? raw.blank? end |
#map ⇒ Object
27 28 29 |
# File 'lib/google_rest.rb', line 27 def map results.map { |r| yield r } end |
#page ⇒ Object
31 32 33 |
# File 'lib/google_rest.rb', line 31 def page cursor["currentPageIndex"].blank? ? 1 : cursor["currentPageIndex"] end |
#pages ⇒ Object
35 36 37 |
# File 'lib/google_rest.rb', line 35 def pages (cursor["pages"] || []) end |
#paginated(current_page = nil) ⇒ Object
55 56 57 |
# File 'lib/google_rest.rb', line 55 def paginated(current_page = nil) results.paginate(:page => current_page || page, :per_page => per_page, :total_entries => total_entries) end |
#per_page ⇒ Object
51 52 53 |
# File 'lib/google_rest.rb', line 51 def per_page 8 end |
#total_entries ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/google_rest.rb', line 43 def total_entries if pages.last pages.last["start"].to_i + GoogleRest::PER_PAGE - 1 else 0 end end |
#total_pages ⇒ Object
39 40 41 |
# File 'lib/google_rest.rb', line 39 def total_pages (cursor["pages"] || []).length end |