Class: HorizonClient::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/horizon_client/collection.rb

Direct Known Subclasses

Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Collection

Returns a new instance of Collection.



7
8
9
10
11
12
# File 'lib/horizon_client/collection.rb', line 7

def initialize(node)
  @node = node
  @rows = @node.locate(row_element_name).map do |row|
    Entity.new(row)
  end
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



5
6
7
# File 'lib/horizon_client/collection.rb', line 5

def node
  @node
end

Instance Method Details

#buildObject



14
15
16
17
18
19
20
# File 'lib/horizon_client/collection.rb', line 14

def build
  row = Ox::Element.new(row_element_name)
  node << row
  entity = Entity.new(row)
  @rows.push(entity)
  entity
end

#each(&block) ⇒ Object



26
27
28
# File 'lib/horizon_client/collection.rb', line 26

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

#rowsObject



22
23
24
# File 'lib/horizon_client/collection.rb', line 22

def rows
  @rows
end