Class: HorizonClient::Entity

Inherits:
Object
  • Object
show all
Defined in:
lib/horizon_client/entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Entity

Returns a new instance of Entity.



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

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



3
4
5
# File 'lib/horizon_client/entity.rb', line 3

def node
  @node
end

Instance Method Details

#[](name) ⇒ Object



9
10
11
12
# File 'lib/horizon_client/entity.rb', line 9

def [](name)
  attr_node = node.locate(name).first
  get_value attr_node
end

#[]=(name, value) ⇒ Object



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

def []=(name, value)
  elem = find_or_build_attribute(name.split('/'), node)

  # needed in case element is in '</elem>' form
  check = elem.text

  elem.replace_text(value)
end

#get_collection(name) ⇒ Object



23
24
25
26
# File 'lib/horizon_client/entity.rb', line 23

def get_collection(name)
  collection_node = find_or_build_attribute(name.split('/'), node)
  Collection.new(collection_node)
end