Class: Contactually::Collection

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/contactually/collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, meta: {}) ⇒ Collection

Returns a new instance of Collection.



8
9
10
11
12
13
14
# File 'lib/contactually/collection.rb', line 8

def initialize(items, meta: {})
  @items = items

  @next_page = meta['next_page']
  @previous_page = meta['previous_page']
  @total = meta['total']
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



6
7
8
# File 'lib/contactually/collection.rb', line 6

def items
  @items
end

#next_pageObject (readonly)

Returns the value of attribute next_page.



6
7
8
# File 'lib/contactually/collection.rb', line 6

def next_page
  @next_page
end

#previous_pageObject (readonly)

Returns the value of attribute previous_page.



6
7
8
# File 'lib/contactually/collection.rb', line 6

def previous_page
  @previous_page
end

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'lib/contactually/collection.rb', line 6

def total
  @total
end

Instance Method Details

#each(&block) ⇒ Object



16
17
18
19
20
# File 'lib/contactually/collection.rb', line 16

def each(&block)
  items.each do |item|
    block.call(item)
  end
end

#has_next_page?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/contactually/collection.rb', line 22

def has_next_page?
  !next_page.nil?
end

#has_previous_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/contactually/collection.rb', line 26

def has_previous_page?
  !previous_page.nil?
end