Class: Raas::PageModel

Inherits:
BaseModel show all
Defined in:
lib/raas/models/page_model.rb

Overview

Represents the pagination information returned in a paginated API call

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(number = nil, elements_per_block = nil, result_count = nil, total_count = nil) ⇒ PageModel

Returns a new instance of PageModel.



33
34
35
36
37
38
39
40
41
# File 'lib/raas/models/page_model.rb', line 33

def initialize(number = nil,
               elements_per_block = nil,
               result_count = nil,
               total_count = nil)
  @number = number
  @elements_per_block = elements_per_block
  @result_count = result_count
  @total_count = total_count
end

Instance Attribute Details

#elements_per_blockInteger

The number of elements per page

Returns:

  • (Integer)


13
14
15
# File 'lib/raas/models/page_model.rb', line 13

def elements_per_block
  @elements_per_block
end

#numberInteger

The page number

Returns:

  • (Integer)


9
10
11
# File 'lib/raas/models/page_model.rb', line 9

def number
  @number
end

#result_countInteger

The number of results returned

Returns:

  • (Integer)


17
18
19
# File 'lib/raas/models/page_model.rb', line 17

def result_count
  @result_count
end

#total_countInteger

The total number of results

Returns:

  • (Integer)


21
22
23
# File 'lib/raas/models/page_model.rb', line 21

def total_count
  @total_count
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/raas/models/page_model.rb', line 44

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  number = hash['number']
  elements_per_block = hash['elementsPerBlock']
  result_count = hash['resultCount']
  total_count = hash['totalCount']

  # Create object from extracted values.
  PageModel.new(number,
                elements_per_block,
                result_count,
                total_count)
end

.namesObject

A mapping from model property names to API property names.



24
25
26
27
28
29
30
31
# File 'lib/raas/models/page_model.rb', line 24

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['number'] = 'number'
  @_hash['elements_per_block'] = 'elementsPerBlock'
  @_hash['result_count'] = 'resultCount'
  @_hash['total_count'] = 'totalCount'
  @_hash
end