Class: Fopost::Page

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

Overview

One page of a list endpoint: its items plus the pagination meta.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items: [], meta: PageMeta.new) ⇒ Page

Returns a new instance of Page.



141
142
143
144
# File 'lib/fopost/models.rb', line 141

def initialize(items: [], meta: PageMeta.new)
  @items = items
  @meta = meta
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



139
140
141
# File 'lib/fopost/models.rb', line 139

def items
  @items
end

#metaObject (readonly)

Returns the value of attribute meta.



139
140
141
# File 'lib/fopost/models.rb', line 139

def meta
  @meta
end

Instance Method Details

#[](index) ⇒ Object



153
154
155
# File 'lib/fopost/models.rb', line 153

def [](index)
  items[index]
end

#each(&block) ⇒ Object



146
147
148
149
150
151
# File 'lib/fopost/models.rb', line 146

def each(&block)
  return items.each unless block

  items.each(&block)
  self
end

#empty?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/fopost/models.rb', line 163

def empty?
  items.empty?
end

#inspectObject



167
168
169
# File 'lib/fopost/models.rb', line 167

def inspect
  "#<Fopost::Page items=#{items.size} total=#{meta.total.inspect}>"
end

#sizeObject Also known as: length, count



157
158
159
# File 'lib/fopost/models.rb', line 157

def size
  items.size
end