Class: Vhx::VhxListObject

Inherits:
Array
  • Object
show all
Defined in:
lib/vhx/utilities/vhx_list_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, list_type) ⇒ VhxListObject

Returns a new instance of VhxListObject.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/vhx/utilities/vhx_list_object.rb', line 4

def initialize(obj, list_type)
  @obj = obj

  if @obj.is_a?(Array)
    ar = @obj.map{|association_hash| Object.const_get("Vhx::#{vhx_object_type(list_type)}").new(association_hash)}
  elsif @obj.is_a?(Hash)
    @previous, @next = @obj['_links']['prev']['href'], @obj['_links']['next']['href']
    @total   = @obj['total']
    ar = @obj['_embedded'][list_type].map{|association_hash| Object.const_get("Vhx::#{vhx_object_type(list_type)}").new(association_hash)}
  end

  super(ar)
end

Instance Method Details

#nextObject



22
23
24
# File 'lib/vhx/utilities/vhx_list_object.rb', line 22

def next
  @next # TODO
end

#previousObject



18
19
20
# File 'lib/vhx/utilities/vhx_list_object.rb', line 18

def previous
  @previous # TODO
end

#totalObject



26
27
28
# File 'lib/vhx/utilities/vhx_list_object.rb', line 26

def total
  @total
end