Class: FidorApi::Collection

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Enumerable
Defined in:
lib/fidor_api/collection.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#current_pageObject

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_valueObject

Returns the value of attribute limit_value.



8
9
10
# File 'lib/fidor_api/collection.rb', line 8

def limit_value
  @limit_value
end

#recordsObject

Returns the value of attribute records.



7
8
9
# File 'lib/fidor_api/collection.rb', line 7

def records
  @records
end

#total_pagesObject

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/fidor_api/collection.rb', line 28

def last_page?
  current_page == total_pages
end

#next_pageObject



32
33
34
# File 'lib/fidor_api/collection.rb', line 32

def next_page
  current_page + 1
end