Class: VORuby::STC::V1_10::Coords::TimeCoordinate

Inherits:
CoordinateType show all
Includes:
SerializableToXml
Defined in:
lib/voruby/stc/1.10/coords.rb

Overview

Time coordinate type. Single CError, CResolution, CSize, CPixSize elements indicate definite values; pairs indicate ranges.

Instance Attribute Summary collapse

Attributes inherited from CoordinateType

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ TimeCoordinate

Returns a new instance of TimeCoordinate.



774
775
776
# File 'lib/voruby/stc/1.10/coords.rb', line 774

def initialize(options={})
  options.each { |key, value| send("#{key}=", value) }
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



772
773
774
# File 'lib/voruby/stc/1.10/coords.rb', line 772

def error
  @error
end

#pix_sizeObject

Returns the value of attribute pix_size.



772
773
774
# File 'lib/voruby/stc/1.10/coords.rb', line 772

def pix_size
  @pix_size
end

#resolutionObject

Returns the value of attribute resolution.



772
773
774
# File 'lib/voruby/stc/1.10/coords.rb', line 772

def resolution
  @resolution
end

#sizeObject

Returns the value of attribute size.



772
773
774
# File 'lib/voruby/stc/1.10/coords.rb', line 772

def size
  @size
end

#time_instantObject

Returns the value of attribute time_instant.



772
773
774
# File 'lib/voruby/stc/1.10/coords.rb', line 772

def time_instant
  @time_instant
end

Class Method Details

.from_xml(xml) ⇒ Object



867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# File 'lib/voruby/stc/1.10/coords.rb', line 867

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] = TimeUnit.new(unit.value) if unit
  
  time_instant = REXML::XPath.first(root, 'x:TimeInstant', {'x' => obj_ns.uri})
  options[:time_instant] = AstronTime.from_xml(time_instant) if time_instant
  
  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)
  
  TimeCoordinate.new(options)
end

Instance Method Details

#==(tc) ⇒ Object



887
888
889
890
891
892
893
894
895
# File 'lib/voruby/stc/1.10/coords.rb', line 887

def ==(tc)
  super(tc) and
  self.time_instant == tc.time_instant and
  self.error == tc.error and
  self.resolution == tc.resolution and
  self.size == tc.size and
  self.pix_size == tc.pix_size and
  self.unit == tc.unit
end

#to_xml(name = nil) ⇒ Object



848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
# File 'lib/voruby/stc/1.10/coords.rb', line 848

def to_xml(name=nil)
  el = element(name)
  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.time_instant.to_xml('TimeInstant')) if self.time_instant
  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

#unitObject



844
845
846
# File 'lib/voruby/stc/1.10/coords.rb', line 844

def unit
  @unit || TimeUnit.new('s')
end

#unit=(u) ⇒ Object



839
840
841
842
# File 'lib/voruby/stc/1.10/coords.rb', line 839

def unit=(u)
  raise_type_mismatch_error(u, TimeUnit) if u
  @unit = u
end