Class: VORuby::STC::V1_10::Coords::Velocity1D

Inherits:
ScalarCoordinateType show all
Includes:
Velocity
Defined in:
lib/voruby/stc/1.10/coords.rb

Overview

1-D Velocity coordinate

Instance Attribute Summary

Attributes included from Velocity

#unit, #vel_time_unit

Attributes inherited from ScalarCoordinateType

#error, #pix_size, #resolution, #size, #value

Attributes inherited from CoordinateType

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Velocity

#==

Methods included from SerializableToXml

#element

Methods inherited from ScalarCoordinateType

#==

Methods inherited from CoordinateType

#==

Constructor Details

#initialize(options = {}) ⇒ Velocity1D

Returns a new instance of Velocity1D.



1572
1573
1574
1575
1576
# File 'lib/voruby/stc/1.10/coords.rb', line 1572

def initialize(options={})
  raise_argument_required_error('unit') if !options.has_key?(:unit)
  raise_argument_required_error('velocity time unit') if !options.has_key?(:vel_time_unit)
  super(options)
end

Class Method Details

.from_xml(xml) ⇒ Object



1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
# File 'lib/voruby/stc/1.10/coords.rb', line 1598

def self.from_xml(xml)
  root = element_from(xml)

  options = {
   :name => REXML::XPath.first(root, 'x:Name', {'x' => obj_ns.uri}).text
  }
  unit = root.attributes.get_attribute_ns(obj_ns.uri, 'unit')
  options[:unit] = PosUnit.new(unit.value)
  vel_time_unit = root.attributes.get_attribute_ns(obj_ns.uri, 'vel_time_unit')
  options[:vel_time_unit] = VelTimeUnit.new(vel_time_unit.value)
  options[:value] = xml_to_obj(root, CValue, true)
  options[:error] = xml_to_obj(root, CError)
  options[:resolution] = xml_to_obj(root, CResolution)
  options[:size] = xml_to_obj(root, CSize)
  options[:pix_size] = xml_to_obj(root, CPixSize)

  Velocity1D.new(options)
end

Instance Method Details

#to_xmlObject



1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
# File 'lib/voruby/stc/1.10/coords.rb', line 1578

def to_xml
  el = element()
  el.attributes["#{obj_ns.prefix}:unit"] = self.unit.to_s
  el.attributes["#{obj_ns.prefix}:vel_time_unit"] = self.vel_time_unit.to_s
  
  name = REXML::Element.new("#{obj_ns.prefix}:Name")
  name.text = self.name

  el.add_element(name)
  el.add_element(self.value.to_xml) if self.value
  self.error.each { |e| el.add_element(e.to_xml) } if self.error
  self.resolution.each { |r| el.add_element(r.to_xml) } if self.resolution
  self.size.each { |s| el.add_element(s.to_xml) } if self.size
  self.pix_size.each { |p| el.add_element(p.to_xml) } if self.pix_size
  
  collapse_namespaces(el)

  el
end