Class: VORuby::ADQL::V1_0::AliasSelectionItem

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

Overview

Used to select an expression as a new alias column

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(expression, as = nil) ⇒ AliasSelectionItem

Returns a new instance of AliasSelectionItem.



694
695
696
697
# File 'lib/voruby/adql/1.0/adql.rb', line 694

def initialize(expression, as=nil)
  self.expression = expression
  self.as = as
end

Instance Attribute Details

#asObject

Returns the value of attribute as.



690
691
692
# File 'lib/voruby/adql/1.0/adql.rb', line 690

def as
  @as
end

#expressionObject

Returns the value of attribute expression.



690
691
692
# File 'lib/voruby/adql/1.0/adql.rb', line 690

def expression
  @expression
end

Class Method Details

.from_xml(xml) ⇒ Object



730
731
732
733
734
735
736
737
738
# File 'lib/voruby/adql/1.0/adql.rb', line 730

def self.from_xml(xml)
  root = element_from(xml)
  
  as = root.attributes.get_attribute_ns(obj_ns.uri, 'As')
  self.new(
    xml_to_obj(REXML::XPath.first(root, 'x:Expression', {'x' => obj_ns.uri})),
    as ? as.value : nil
  )
end

.xml_typeObject



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

def self.xml_type; 'aliasSelectionItemType' end

Instance Method Details

#==(a) ⇒ Object



709
710
711
712
# File 'lib/voruby/adql/1.0/adql.rb', line 709

def ==(a)
  self.expression == a.expression and
  self.as == a.as
end

#to_sObject



714
715
716
717
718
# File 'lib/voruby/adql/1.0/adql.rb', line 714

def to_s
  a = self.expression.to_s
  a = "#{a} AS #{as}" if self.as
  a
end

#to_xml(name = nil) ⇒ Object



720
721
722
723
724
725
726
727
728
# File 'lib/voruby/adql/1.0/adql.rb', line 720

def to_xml(name=nil)
  el = super(name)
  
  el.attributes["#{obj_ns.prefix}:As"] = self.as if self.as
  el.add_element(self.expression.to_xml('Expression'))
  
  collapse_namespaces(el)
  el
end