class Microstation::TaggedElement::Set
Attributes
element[R]
Public Class Methods
new(name,element)
click to toggle source
# File lib/microstation/tagged_element.rb, line 9 def initialize(name,element) @name = name @element = element end
Public Instance Methods
[](name)
click to toggle source
# File lib/microstation/tagged_element.rb, line 29 def [](name) find_attribute(name) end
attributes()
click to toggle source
# File lib/microstation/tagged_element.rb, line 33 def attributes @elements.map{|e| e.name} end
element_value(name)
click to toggle source
# File lib/microstation/tagged_element.rb, line 41 def element_value(name) find_attribute(name).value end
elements=(elements)
click to toggle source
# File lib/microstation/tagged_element.rb, line 18 def elements=(elements) elements.each do |ele| ele.base_element = @element end @elements = elements end
find_attribute(name)
click to toggle source
# File lib/microstation/tagged_element.rb, line 25 def find_attribute(name) @elements.find{|a| a.name == name.to_s} end
method_missing(meth,*args,&block)
click to toggle source
Calls superclass method
# File lib/microstation/tagged_element.rb, line 69 def method_missing(meth,*args,&block) # binding.pry 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/tagged_element.rb, line 14 def name @name end
stringify_keys(hash)
click to toggle source
# File lib/microstation/tagged_element.rb, line 53 def stringify_keys(hash) result = {} hash.each do |key,value| result[key.to_s] = value end result end
to_hash()
click to toggle source
# File lib/microstation/tagged_element.rb, line 45 def to_hash result = {} @elements.each do |ele| result[ele.name] = ele.value unless (ele.value == "" || ele.value.nil?) end result end
update(value_hash)
click to toggle source
# File lib/microstation/tagged_element.rb, line 61 def update(value_hash) value_hash = stringify_keys(value_hash) 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/tagged_element.rb, line 37 def update_element(name,value) find_attribute(name)._update(value) end