Class: VORuby::ADQL::V1_0::Atom

Inherits:
ScalarExpression show all
Defined in:
lib/voruby/adql/1.0/adql.rb

Overview

Encapsulates basic literals such as Strings, Integers and Real numbers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(l, u = nil) ⇒ Atom

Returns a new instance of Atom.



353
354
355
356
357
# File 'lib/voruby/adql/1.0/adql.rb', line 353

def initialize(l, u=nil)
  super()
  self.literal = l
  self.unit = u
end

Instance Attribute Details

#literalObject

Returns the value of attribute literal.



349
350
351
# File 'lib/voruby/adql/1.0/adql.rb', line 349

def literal
  @literal
end

#unitObject

Returns the value of attribute unit.



349
350
351
# File 'lib/voruby/adql/1.0/adql.rb', line 349

def unit
  @unit
end

Class Method Details

.from_xml(xml) ⇒ Object



404
405
406
407
408
409
410
411
412
413
414
# File 'lib/voruby/adql/1.0/adql.rb', line 404

def self.from_xml(xml)
  root = element_from(xml)
  
  unit_el = REXML::XPath.first(root, 'x:Unit', {'x' => obj_ns.uri})
  unit = unit_el ? unit_el.text : nil
  
  self.new(
    xml_to_obj(REXML::XPath.first(root, 'x:Literal', {'x' => obj_ns.uri})),
    unit
  )
end

.xml_typeObject



351
# File 'lib/voruby/adql/1.0/adql.rb', line 351

def self.xml_type; 'atomType' end

Instance Method Details

#==(a) ⇒ Object



380
381
382
383
# File 'lib/voruby/adql/1.0/adql.rb', line 380

def ==(a)
  self.literal == a.literal and
  self.unit == a.unit
end

#to_sObject



385
386
387
# File 'lib/voruby/adql/1.0/adql.rb', line 385

def to_s
  self.literal.to_s
end

#to_xml(name = nil) ⇒ Object



389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/voruby/adql/1.0/adql.rb', line 389

def to_xml(name=nil)
  el = super(name)
  
  el.add_element(self.literal.to_xml('Literal'))
  
  if self.unit
    unit_el = element('Unit')
    unit_el.text = self.unit.to_s
    el.add_element(unit_el)
  end
  
  collapse_namespaces(el)
  el
end