Class: FidorApi::Collection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_pageObject (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_pageObject (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_entriesObject (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_pagesObject (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