class HorizonClient::Entity

Attributes

node[R]

Public Class Methods

new(node) click to toggle source
# File lib/horizon_client/entity.rb, line 5
def initialize(node)
  @node = node
end

Public Instance Methods

[](name) click to toggle source
# File lib/horizon_client/entity.rb, line 9
def [](name)
  attr_node = node.locate(name).first
  get_value attr_node
end
[]=(name, value) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

find_or_build_attribute(path, parent) click to toggle source
# File lib/horizon_client/entity.rb, line 30
def find_or_build_attribute(path, parent)
  name = path.shift
  unless child = parent.locate(name).first
    child = Ox::Element.new(name)
    parent << child
  end
  path.empty? ? child : find_or_build_attribute(path, child)
end
get_value(node) click to toggle source
# File lib/horizon_client/entity.rb, line 39
def get_value(node)
  if node.respond_to?('href')
    node.href.text
  else
    node.text
  end
end