Class: Sirportly::DataSet

Inherits:
Array
  • Object
show all
Defined in:
lib/sirportly/data_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, records, klass) ⇒ DataSet

Returns a new instance of DataSet.



4
5
6
7
8
9
10
11
12
13
# File 'lib/sirportly/data_set.rb', line 4

def initialize(client, records, klass)
  @pagination = {}
  if records.is_a?(Hash)
    @pagination = records['pagination']
    records = records['records']
  end

  records.map! { |r| klass.new(client, r) }
  self.push(*records)
end

Instance Method Details

#offsetObject



31
32
33
# File 'lib/sirportly/data_set.rb', line 31

def offset
  @pagination['offset']
end

#pageObject



15
16
17
# File 'lib/sirportly/data_set.rb', line 15

def page
  @pagination['page']
end

#pagesObject



27
28
29
# File 'lib/sirportly/data_set.rb', line 27

def pages
  @pagination['pages']
end

#per_pageObject



23
24
25
# File 'lib/sirportly/data_set.rb', line 23

def per_page
  @pagination['per_page']
end

#total_recordsObject



19
20
21
# File 'lib/sirportly/data_set.rb', line 19

def total_records
  @pagination['total_records']
end