Class: Pandoru::Models::Collection

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pandoru/models/_base.rb

Overview

Base class for collections of models

Instance Attribute Summary

Attributes inherited from Base

#data

Instance Method Summary collapse

Methods inherited from Base

date_field, field, fields, from_json, from_json_list, #inspect, #populate_from_json, #to_h

Constructor Details

#initialize(data = {}, api_client = nil) ⇒ Collection

Returns a new instance of Collection.



112
113
114
115
# File 'lib/pandoru/models/_base.rb', line 112

def initialize(data = {}, api_client = nil)
  super
  @items = []
end

Instance Method Details

#<<(item) ⇒ Object



117
118
119
# File 'lib/pandoru/models/_base.rb', line 117

def <<(item)
  @items << item
end

#[](index) ⇒ Object



121
122
123
# File 'lib/pandoru/models/_base.rb', line 121

def [](index)
  @items[index]
end

#each(&block) ⇒ Object



125
126
127
# File 'lib/pandoru/models/_base.rb', line 125

def each(&block)
  @items.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


135
136
137
# File 'lib/pandoru/models/_base.rb', line 135

def empty?
  @items.empty?
end

#firstObject



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

def first
  @items.first
end

#lastObject



143
144
145
# File 'lib/pandoru/models/_base.rb', line 143

def last
  @items.last
end

#lengthObject Also known as: size, count



129
130
131
# File 'lib/pandoru/models/_base.rb', line 129

def length
  @items.length
end

#to_aObject



147
148
149
# File 'lib/pandoru/models/_base.rb', line 147

def to_a
  @items
end