class Microstation::TS::Instance

Attributes

elements[R]
microstation_id[R]
microstation_model[R]
tagset[R]

Public Class Methods

new(ts,id, elements, model) click to toggle source
# File lib/microstation/ts/instance.rb, line 22
def initialize(ts,id, elements, model)
  @tagset = ts
  @microstation_id = id
  @elements = elements
  @microstation_model = model
end

Public Instance Methods

[](name) click to toggle source
# File lib/microstation/ts/instance.rb, line 41
def [](name)
  find_attribute(name)
end
[]=(name,value) click to toggle source
# File lib/microstation/ts/instance.rb, line 53
def []=(name,value)
  update_element(name,value)
end
attribute_hash() click to toggle source
# File lib/microstation/ts/instance.rb, line 69
def attribute_hash
  result = {"microstation_id" => microstation_id}
  each_pair do |name, value|
    result[name] = value
  end
  result
end
attributes() click to toggle source
# File lib/microstation/ts/instance.rb, line 45
def attributes
  @elements.map{|e| e.name}
end
each() { |el| ... } click to toggle source
# File lib/microstation/ts/instance.rb, line 103
def each
  @elements.each do |el|
    yield el
  end
end
each_pair() { |name, value| ... } click to toggle source
# File lib/microstation/ts/instance.rb, line 109
def each_pair
  @elements.each do |el|
    yield el.name, el.value
  end
end
element_value(name) click to toggle source
# File lib/microstation/ts/instance.rb, line 57
def element_value(name)
  find_attribute(name).value
end
find(&block) click to toggle source
# File lib/microstation/ts/instance.rb, line 99
def find(&block)
  select(&block).first
end
find_attribute(name) click to toggle source
# File lib/microstation/ts/instance.rb, line 37
def find_attribute(name)
  @elements.find{|a| a.name == name.to_s}
end
map_v() { |v| ... } click to toggle source
# File lib/microstation/ts/instance.rb, line 115
def map_v
  each_pair do |k,v|
    new_v = yield v
    update_element(k,new_v)
  end
end
method_missing(meth,*args,&block) click to toggle source
Calls superclass method
# File lib/microstation/ts/instance.rb, line 130
def method_missing(meth,*args,&block)
  base = meth.to_s.sub("=", "")
  if attributes.include?(base)
    if meth.match /(=)/
      update_element(base,*args)
    else
      element_value(base.to_s)
    end
  else
    super(meth,*args,&block)
  end
end
name() click to toggle source
# File lib/microstation/ts/instance.rb, line 29
def name
  tagset.name
end
pair(el) click to toggle source
# File lib/microstation/ts/instance.rb, line 85
def pair(el)
  [el.name, el.value]
end
select() { |k,v| ... } click to toggle source
# File lib/microstation/ts/instance.rb, line 89
def select
  result = []
  each do |el|
    k,v = pair(el)
    save = yield k,v
    result << find_attribute(k) if save
  end
  self.class.new(tagset,result)
end
to_h() click to toggle source
# File lib/microstation/ts/instance.rb, line 77
def to_h
  result = {'tagset_name'=> tagset.name, 'microstation_id' => microstation_id,
            'microstation_model' => microstation_model, }
  result['attributes'] = attribute_hash
  result
end
to_hash() click to toggle source
# File lib/microstation/ts/instance.rb, line 61
def to_hash
  result = {}
  @elements.each do |ele|
    result[ele.name] = ele.value unless (ele.value == "" || ele.value.nil?)
  end
  result
end
to_s() click to toggle source
# File lib/microstation/ts/instance.rb, line 33
def to_s
  "TS:Instance #{tagset.name}"
end
update(value_hash) click to toggle source
# File lib/microstation/ts/instance.rb, line 122
def update(value_hash)
  value_hash = value_hash.transform{|k,v| [k.to_s,v.to_s] }
  valid_atts = attributes & value_hash.keys
  valid_atts.each do |att|
    update_element(att,value_hash[att])
  end
end
update_element(name,value) click to toggle source
# File lib/microstation/ts/instance.rb, line 49
def update_element(name,value)
  find_attribute(name).update(value)
end