Class: VORuby::ADQL::Atom

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

Overview

Encapsulates basic literals such as Strings, Integers and Real numbers.

Instance Attribute Summary collapse

Attributes inherited from ScalarExpression

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ScalarExpression

#is_scalar?

Constructor Details

#initialize(literal, unit = nil) ⇒ Atom

Returns a new instance of Atom.



305
306
307
308
309
310
# File 'lib/voruby/adql/adql.rb', line 305

def initialize(literal, unit=nil)
	super("#{literal}#{unit || ''}")
		
	self.literal = literal
	self.unit = unit
end

Instance Attribute Details

#literalObject

Returns the value of attribute literal.



302
303
304
# File 'lib/voruby/adql/adql.rb', line 302

def literal
  @literal
end

#unitObject

Returns the value of attribute unit.



303
304
305
# File 'lib/voruby/adql/adql.rb', line 303

def unit
  @unit
end

Class Method Details

.from_xml(node) ⇒ Object



334
335
336
337
338
# File 'lib/voruby/adql/adql.rb', line 334

def self.from_xml(node)
  literal_node = REXML::XPath.first(node, 'Literal')
  literal = LiteralType.from_xml(literal_node)
  return Atom.new(literal)
end

Instance Method Details

#to_adqlsObject



55
56
57
58
59
60
61
62
# File 'lib/voruby/adql/transforms.rb', line 55

def to_adqls
  lit_value = self.literal
  if lit_value.is_a?(StringType)
	  "'#{lit_value.to_adqls}#{self.unit || ''}'"
	else
	  "#{lit_value.to_adqls}#{self.unit || ''}"
  end
end

#to_adqlx(element_name) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/voruby/adql/transforms.rb', line 64

def to_adqlx(element_name)
  literal_type = ''
  if self.literal.is_a?(ADQL::RealType)
    literal_type = 'realType'
  elsif self.literal.is_a?(ADQL::IntegerType)
          literal_type = 'integerType'
        elsif self.literal.is_a?(ADQL::StringType)
          literal_type = 'stringType'
        end

  atom = "<#{element_name} xsi:type=\"atomType\">\n"
  atom << self.literal.to_adqlx(literal_type)
  atom << "\n</#{element_name}>\n"

  return atom
end

#to_sObject



330
331
332
# File 'lib/voruby/adql/adql.rb', line 330

def to_s
	"{literal=#{self.literal},unit=#{self.unit}}"
end