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_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_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 |
# 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 { |record| klass.new(record) } object.total_pages = collection["total_pages"] object.current_page = collection["current_page"] object.limit_value = collection["per_page"] end end |
Instance Method Details
#each(&block) ⇒ Object
23 24 25 |
# File 'lib/fidor_api/collection.rb', line 23 def each(&block) records.each(&block) end |
#last_page? ⇒ Boolean
— kaminari stuff – maybe move somewhere else
28 29 30 |
# File 'lib/fidor_api/collection.rb', line 28 def last_page? current_page == total_pages end |
#next_page ⇒ Object
32 33 34 |
# File 'lib/fidor_api/collection.rb', line 32 def next_page current_page + 1 end |