Class: VORuby::STC::V1_30::JDTimeType

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

Overview

A decimal type for JD and MJD, with optional referencing.

Direct Known Subclasses

JDTime, MJDTime

Instance Attribute Summary collapse

Attributes included from STCReference

#id, #idref, #ucd, #xlink_href, #xlink_type

Class Method Summary collapse

Instance Method Summary collapse

Methods included from STCReference

#stc_reference_eq, stc_reference_from_xml, #stc_reference_to_xml

Methods included from SerializableToXml

#element

Constructor Details

#initialize(value, options = {}) ⇒ JDTimeType

Returns a new instance of JDTimeType.



339
340
341
342
# File 'lib/voruby/stc/1.30/stc.rb', line 339

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

Instance Attribute Details

#valueObject

Returns the value of attribute value.



337
338
339
# File 'lib/voruby/stc/1.30/stc.rb', line 337

def value
  @value
end

Class Method Details

.from_xml(xml) ⇒ Object



367
368
369
370
371
372
373
374
# File 'lib/voruby/stc/1.30/stc.rb', line 367

def self.from_xml(xml)
  root = element_from(xml)
  
  value = Float(root.text)
  options = STCReference.stc_reference_from_xml(root)
  
  self.new(value, options)
end

Instance Method Details

#==(t) ⇒ Object



349
350
351
352
# File 'lib/voruby/stc/1.30/stc.rb', line 349

def ==(t)
  self.stc_reference_eq(t) and
  self.value == t.value
end

#to_datetimeObject



354
355
356
# File 'lib/voruby/stc/1.30/stc.rb', line 354

def to_datetime
  DateTime.jd(self.value)
end

#to_xml(name = nil) ⇒ Object



358
359
360
361
362
363
364
365
# File 'lib/voruby/stc/1.30/stc.rb', line 358

def to_xml(name=nil)
  el = stc_reference_to_xml(element(name))
  
  el.text = self.value.to_s
  
  collapse_namespaces(el)
  el
end