Class: RegistersClient::EntryCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/entry_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(data, page_size = 100) ⇒ EntryCollection

Returns a new instance of EntryCollection.



5
6
7
8
# File 'lib/entry_collection.rb', line 5

def initialize(data, page_size = 100)
  @data = data
  @page_size = page_size
end

Instance Method Details

#eachObject



10
11
12
13
14
# File 'lib/entry_collection.rb', line 10

def each
  @data.each do |entry|
    yield entry
  end
end

#page(page = 1) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/entry_collection.rb', line 16

def page(page = 1)
  if @data.length <= @page_size
    @data
  else
    start_index = (page - 1) * @page_size
    @data.slice(start_index, @page_size)
  end
end