Class: Reviewed::Collection
- Inherits:
-
Object
- Object
- Reviewed::Collection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/reviewed/collection.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#items ⇒ Object
Returns the value of attribute items.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#page_attributes ⇒ Object
Returns the value of attribute page_attributes.
-
#params ⇒ Object
Returns the value of attribute params.
-
#raw_response ⇒ Object
Returns the value of attribute raw_response.
Instance Method Summary collapse
-
#initialize(client, klass, response, params = {}) ⇒ Collection
constructor
A new instance of Collection.
- #limit_value ⇒ Object
- #method_missing(sym, *args, &block) ⇒ Object
- #next_page ⇒ Object
- #num_pages ⇒ Object
- #previous_page ⇒ Object
- #total_count ⇒ Object
Constructor Details
#initialize(client, klass, response, params = {}) ⇒ Collection
Returns a new instance of Collection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/reviewed/collection.rb', line 11 def initialize(client, klass, response, params={}) body = response.body data = body.data @client = client @klass = klass @params = params @items = [] @page_attributes = body.pagination || {} data.each do |obj| self.items << klass.new(obj, client) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/reviewed/collection.rb', line 48 def method_missing(sym, *args, &block) clean_sym = sym.to_s.gsub(/\?/, '').to_sym if @page_attributes.has_key?(clean_sym) @page_attributes[clean_sym] else super end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def client @client end |
#items ⇒ Object
Returns the value of attribute items.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def items @items end |
#klass ⇒ Object
Returns the value of attribute klass.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def klass @klass end |
#page_attributes ⇒ Object
Returns the value of attribute page_attributes.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def page_attributes @page_attributes end |
#params ⇒ Object
Returns the value of attribute params.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def params @params end |
#raw_response ⇒ Object
Returns the value of attribute raw_response.
9 10 11 |
# File 'lib/reviewed/collection.rb', line 9 def raw_response @raw_response end |
Instance Method Details
#limit_value ⇒ Object
26 27 28 |
# File 'lib/reviewed/collection.rb', line 26 def limit_value per_page end |
#next_page ⇒ Object
38 39 40 41 |
# File 'lib/reviewed/collection.rb', line 38 def next_page return nil if @page_attributes[:last_page] fetch_page(@page_attributes[:next_page]) end |
#num_pages ⇒ Object
30 31 32 |
# File 'lib/reviewed/collection.rb', line 30 def num_pages total_pages end |
#previous_page ⇒ Object
43 44 45 46 |
# File 'lib/reviewed/collection.rb', line 43 def previous_page return nil if @page_attributes[:first_page] fetch_page(@page_attributes[:previous_page]) end |
#total_count ⇒ Object
34 35 36 |
# File 'lib/reviewed/collection.rb', line 34 def total_count total end |