Class: VORuby::STC::V1_10::STC::TimeFrameType

Inherits:
CoordFrameType show all
Defined in:
lib/voruby/stc/1.10/stc.rb

Overview

The time reference frame consists of a timescale, a reference position, and optionally a reference direction (needed when transformations have been applied)

Direct Known Subclasses

TimeFrame

Instance Attribute Summary collapse

Attributes inherited from CoordFrameType

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(options = {}) ⇒ TimeFrameType

Returns a new instance of TimeFrameType.



1185
1186
1187
1188
# File 'lib/voruby/stc/1.10/stc.rb', line 1185

def initialize(options={})
  raise_argument_error('reference position') if !options.has_key?(:reference_position)
  super(options)
end

Instance Attribute Details

#reference_positionObject

Returns the value of attribute reference_position.



1183
1184
1185
# File 'lib/voruby/stc/1.10/stc.rb', line 1183

def reference_position
  @reference_position
end

#time_ref_directionObject

Returns the value of attribute time_ref_direction.



1183
1184
1185
# File 'lib/voruby/stc/1.10/stc.rb', line 1183

def time_ref_direction
  @time_ref_direction
end

Class Method Details

.from_xml(xml) ⇒ Object



1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'lib/voruby/stc/1.10/stc.rb', line 1241

def self.from_xml(xml)
  root = element_from(xml)
  
  options = {
    :reference_position => xml_to_obj(root, ReferencePosition, true),
    :time_scale => TimeScale.new(REXML::XPath.first(root, 'x:TimeScale', {'x' => obj_ns.uri}).text)
  }
  
  name = REXML::XPath.first(root, 'x:Name', {'x' => obj_ns.uri})
  options[:name] = name.text if name
  
  time_ref_dir = REXML::XPath.first(root, 'x:TimeRefDirection', {'x' => obj_ns.uri})
  options[:time_ref_direction] = AstroCoords.from_xml(time_ref_dir) if time_ref_dir
  
  self.new(options)
end

Instance Method Details

#==(f) ⇒ Object



1217
1218
1219
1220
1221
1222
# File 'lib/voruby/stc/1.10/stc.rb', line 1217

def ==(f)
  super(f) and
  self.time_scale == f.time_scale and
  self.reference_position == f.reference_position and
  self.time_ref_direction == f.time_ref_direction
end

#time_scaleObject



1199
1200
1201
# File 'lib/voruby/stc/1.10/stc.rb', line 1199

def time_scale
  @time_scale || TimeScale.new('TT')
end

#time_scale=(s) ⇒ Object

The time reference frame consists of a time scale, a time format, and a reference time, if needed



1191
1192
1193
1194
1195
1196
1197
# File 'lib/voruby/stc/1.10/stc.rb', line 1191

def time_scale=(s)
  if s
    s = TimeScale.new(s) if s.is_a?(String)
    raise_type_mismatch_error(s, TimeScale)
  end
  @time_scale = s
end

#to_xml(name = nil) ⇒ Object



1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
# File 'lib/voruby/stc/1.10/stc.rb', line 1224

def to_xml(name=nil)
  el = super(name)
  
  coords_ns = NAMESPACES['VORuby::STC::V1_10::Coords']
  el.add_namespace(coords_ns.prefix, coords_ns.uri)
  
  time_scale = REXML::Element.new("#{obj_ns.prefix}:TimeScale")
  time_scale.text = self.time_scale.to_s
  el.add_element(time_scale)
  
  el.add_element(self.reference_position.to_xml)
  el.add_element(self.time_ref_direction.to_xml('TimeRefDirection', obj_ns)) if self.time_ref_direction
  
  collapse_namespaces(el)
  el
end