Class: FidorApi::Collection
- Inherits:
-
Object
- Object
- FidorApi::Collection
- Includes:
- Enumerable, KaminariSupport
- Defined in:
- lib/fidor_api/collection.rb,
lib/fidor_api/collection/kaminari_support.rb
Defined Under Namespace
Modules: KaminariSupport
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_entries ⇒ Object
readonly
Returns the value of attribute total_entries.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(klass:, raw:) ⇒ Collection
constructor
A new instance of Collection.
Methods included from KaminariSupport
#last_page?, #limit_value, #next_page
Constructor Details
#initialize(klass:, raw:) ⇒ Collection
Returns a new instance of Collection.
14 15 16 17 18 19 20 |
# File 'lib/fidor_api/collection.rb', line 14 def initialize(klass:, raw:) @current_page = raw.fetch('collection').fetch('current_page') @per_page = raw.fetch('collection').fetch('per_page') @total_entries = raw.fetch('collection').fetch('total_entries') @total_pages = raw.fetch('collection').fetch('total_pages') @records = raw.fetch('data').map { |attributes| klass.new(attributes) } end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def current_page @current_page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def per_page @per_page end |
#total_entries ⇒ Object (readonly)
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 (readonly)
Returns the value of attribute total_pages.
8 9 10 |
# File 'lib/fidor_api/collection.rb', line 8 def total_pages @total_pages end |
Instance Method Details
#each(&block) ⇒ Object
22 23 24 |
# File 'lib/fidor_api/collection.rb', line 22 def each(&block) records.each(&block) end |