Class: VORuby::STC::V1_30::AstronTimeType

Inherits:
Object
  • Object
show all
Includes:
SerializableToXml
Defined in:
lib/voruby/stc/1.30/stc.rb

Overview

The generalized astronomical time type and consists of one, two, or three elements: optional TimeScale, optional relative time offset, and an absolute time (ISO8601 or a decimal JD or MJD; or it may be an IDREF to one of those three); TimeScale may be omitted only if the element is part of AstroCoords, referring to an AstroCoordSystem that specifies a TimeScale.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ AstronTimeType

Returns a new instance of AstronTimeType.



487
488
489
490
# File 'lib/voruby/stc/1.30/stc.rb', line 487

def initialize(options={})
  raise_argument_required_error('absolute time') if !options.has_key?(:absolute_time)
  options.each { |key, v| send("#{key}=", v) }
end

Instance Attribute Details

#absolute_timeObject

Returns the value of attribute absolute_time.



485
486
487
# File 'lib/voruby/stc/1.30/stc.rb', line 485

def absolute_time
  @absolute_time
end

#time_offsetObject

Returns the value of attribute time_offset.



485
486
487
# File 'lib/voruby/stc/1.30/stc.rb', line 485

def time_offset
  @time_offset
end

#timescaleObject

Returns the value of attribute timescale.



485
486
487
# File 'lib/voruby/stc/1.30/stc.rb', line 485

def timescale
  @timescale
end

Class Method Details

.from_xml(xml) ⇒ Object



533
534
535
536
537
538
539
540
541
542
# File 'lib/voruby/stc/1.30/stc.rb', line 533

def self.from_xml(xml)
  root = element_from(xml)
  
  timescale_el = REXML::XPath.first(root, 'x:Timescale', {'x' => obj_ns.uri})
  self.new(
    :timescale => timescale_el ? TimeScaleType.new(timescale_el.text) : nil,
    :time_offset => xml_to_obj(root, TimeOffset, true),
    :absolute_time => xml_to_obj(root, AbsoluteTime, true)
  )
end

Instance Method Details

#==(at) ⇒ Object



512
513
514
515
516
# File 'lib/voruby/stc/1.30/stc.rb', line 512

def ==(at)
  self.timescale == at.timescale and
  self.time_offset == at.time_offset and
  self.absolute_time == at.absolute_time
end

#to_xml(name = nil) ⇒ Object



518
519
520
521
522
523
524
525
526
527
528
529
530
531
# File 'lib/voruby/stc/1.30/stc.rb', line 518

def to_xml(name=nil)
  el = element(name)
  
  if self.timescale
    timescale_el = REXML::Element.new("#{obj_ns.prefix}:Timescale")
    timescale_el.text = self.timescale.to_s
    el.add_element(timescale_el)
  end
  el.add_element(self.time_offset.to_xml) if self.time_offset
  el.add_element(self.absolute_time.to_xml) if self.absolute_time
  
  collapse_namespaces(el)
  el
end