Class: VORuby::STC::V1_10::Coords::Position1D

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

Overview

1-D Position coordinate

Instance Attribute Summary collapse

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 SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ Position1D

Returns a new instance of Position1D.



1375
1376
1377
1378
# File 'lib/voruby/stc/1.10/coords.rb', line 1375

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

Instance Attribute Details

#unitObject

Returns the value of attribute unit.



1373
1374
1375
# File 'lib/voruby/stc/1.10/coords.rb', line 1373

def unit
  @unit
end

Class Method Details

.from_xml(xml) ⇒ Object



1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
# File 'lib/voruby/stc/1.10/coords.rb', line 1405

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) if unit
  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)

  Position1D.new(options)
end

Instance Method Details

#==(p) ⇒ Object



1422
1423
1424
1425
# File 'lib/voruby/stc/1.10/coords.rb', line 1422

def ==(p)
  super(p) and
  self.unit == p.unit
end

#to_xmlObject



1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
# File 'lib/voruby/stc/1.10/coords.rb', line 1386

def to_xml
  el = element()
  el.attributes["#{obj_ns.prefix}:unit"] = self.unit.to_s if self.unit

  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