Class: FidorApi::Collection
- Inherits:
-
Object
- Object
- FidorApi::Collection
- Includes:
- ActiveModel::Model, Enumerable
- Defined in:
- lib/fidor_api/collection.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#limit_value ⇒ Object
Returns the value of attribute limit_value.
-
#records ⇒ Object
Returns the value of attribute records.
-
#total_entries ⇒ Object
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#last_page? ⇒ Boolean
— kaminari stuff – maybe move somewhere else.
- #next_page ⇒ Object
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def current_page @current_page end |
#limit_value ⇒ Object
Returns the value of attribute limit_value.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def limit_value @limit_value end |
#records ⇒ Object
Returns the value of attribute records.
7 8 9 |
# File 'lib/fidor_api/collection.rb', line 7 def records @records end |
#total_entries ⇒ Object
Returns the value of attribute total_entries.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def total_entries @total_entries end |
#total_pages ⇒ Object
Returns the value of attribute total_pages.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def total_pages @total_pages end |
Class Method Details
.build(klass, response) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fidor_api/collection.rb', line 10 def self.build(klass, response) new.tap do |object| data = response["data"] collection = response["collection"] object.records = data.map do |record| class_to_instantiate = if block_given? yield(record) else klass end class_to_instantiate.new(record) end object.total_pages = collection["total_pages"] object.current_page = collection["current_page"] object.limit_value = collection["per_page"] object.total_entries = collection["total_entries"] end end |
Instance Method Details
#each(&block) ⇒ Object
32 33 34 |
# File 'lib/fidor_api/collection.rb', line 32 def each(&block) records.each(&block) end |
#last_page? ⇒ Boolean
— kaminari stuff – maybe move somewhere else
37 38 39 |
# File 'lib/fidor_api/collection.rb', line 37 def last_page? current_page == total_pages end |
#next_page ⇒ Object
41 42 43 |
# File 'lib/fidor_api/collection.rb', line 41 def next_page current_page + 1 end |