Class: Nytimes::Movies::ResultSet
- Inherits:
-
Object
- Object
- Nytimes::Movies::ResultSet
- Defined in:
- lib/nytimes/movies/result_set.rb
Instance Attribute Summary collapse
-
#num_results ⇒ Object
readonly
Returns the value of attribute num_results.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
Instance Method Summary collapse
-
#batch_size ⇒ Object
(also: #per_page)
The number of results returned in a result set.
-
#first_index ⇒ Object
The first display index of the result set.
-
#initialize(params, json_reply, coerce_type) ⇒ ResultSet
constructor
A new instance of ResultSet.
-
#last_index ⇒ Object
The last display index of the result set.
-
#num_pages ⇒ Object
The calculated number of pages returned from the movies API.
-
#page_number ⇒ Object
The page of this result set.
Constructor Details
#initialize(params, json_reply, coerce_type) ⇒ ResultSet
Returns a new instance of ResultSet.
6 7 8 9 10 11 |
# File 'lib/nytimes/movies/result_set.rb', line 6 def initialize(params, json_reply, coerce_type) @num_results = json_reply['num_results'] @params = params.dup @offset = @params['offset'] || 0 @results = json_reply['results'].map {|r| coerce_type.create_from_api(r)} end |
Instance Attribute Details
#num_results ⇒ Object (readonly)
Returns the value of attribute num_results.
4 5 6 |
# File 'lib/nytimes/movies/result_set.rb', line 4 def num_results @num_results end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
4 5 6 |
# File 'lib/nytimes/movies/result_set.rb', line 4 def offset @offset end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
4 5 6 |
# File 'lib/nytimes/movies/result_set.rb', line 4 def results @results end |
Instance Method Details
#batch_size ⇒ Object Also known as: per_page
The number of results returned in a result set
39 40 41 |
# File 'lib/nytimes/movies/result_set.rb', line 39 def batch_size Review::BATCH_SIZE end |
#first_index ⇒ Object
The first display index of the result set. Note this is a human index, not a programmer index; it starts from 1
15 16 17 |
# File 'lib/nytimes/movies/result_set.rb', line 15 def first_index offset + 1 end |
#last_index ⇒ Object
The last display index of the result set.
21 22 23 |
# File 'lib/nytimes/movies/result_set.rb', line 21 def last_index first_index + batch_size - 1 end |
#num_pages ⇒ Object
The calculated number of pages returned from the movies API.
33 34 35 |
# File 'lib/nytimes/movies/result_set.rb', line 33 def num_pages (num_results.to_f / batch_size).ceil end |
#page_number ⇒ Object
The page of this result set
27 28 29 |
# File 'lib/nytimes/movies/result_set.rb', line 27 def page_number offset / batch_size + 1 end |