Class: RZoopla::BaseCollection
- Inherits:
-
Object
- Object
- RZoopla::BaseCollection
- Includes:
- Enumerable
- Defined in:
- lib/zoopla/base_collection.rb,
lib/rzoopla/base_collection.rb
Direct Known Subclasses
Constant Summary collapse
- ATTRIBUTES =
[:result_count, :page_number, :page_size, :results]
- DEFAULT_PAGINATION_OPTIONS =
{ page_number: 1, page_size: 10 }
Class Method Summary collapse
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(options = {}) ⇒ BaseCollection
constructor
A new instance of BaseCollection.
- #size ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ BaseCollection
Returns a new instance of BaseCollection.
13 14 15 16 17 |
# File 'lib/zoopla/base_collection.rb', line 13 def initialize( = {}) ATTRIBUTES.each do |attr| instance_variable_set("@#{attr}", [attr]) end end |
Class Method Details
.where(options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/zoopla/base_collection.rb', line 31 def self.where( = {}) opt = DEFAULT_PAGINATION_OPTIONS.clone.merge() result = RZoopla::Utils.symbolize_keys(RZoopla::Client.get(end_point, opt)) new( page_number: opt[:page_number], page_size: opt[:page_size], result_count: result[:result_count], results: extract_results(result) ) end |
Instance Method Details
#[](index) ⇒ Object
27 28 29 |
# File 'lib/zoopla/base_collection.rb', line 27 def [](index) @results[index] end |
#each(&block) ⇒ Object
19 20 21 |
# File 'lib/zoopla/base_collection.rb', line 19 def each(&block) @results.each(&block) end |
#size ⇒ Object
23 24 25 |
# File 'lib/zoopla/base_collection.rb', line 23 def size @results.size end |