Class: VSql::SelectExpression

Inherits:
VSqlSyntaxNode
  • Object
show all
Defined in:
lib/vsql_node_extensions.rb

Instance Method Summary collapse

Instance Method Details

#alias_nodeObject



151
152
153
# File 'lib/vsql_node_extensions.rb', line 151

def alias_node
  @alias_node ||= Helpers.find_elements(self, Alias, Query).first
end

#expression_sqlObject



148
149
# File 'lib/vsql_node_extensions.rb', line 148

def expression_sql
end

#nameObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/vsql_node_extensions.rb', line 159

def name
  case
  when alias_node
    alias_node.text_value
  when root_nodes.length == 1 && root_nodes.first.is_a?(Function)
    root_nodes.first.name
  when root_nodes.length == 1 && root_nodes.first.is_a?(FieldRef)
    element =
      Helpers.find_elements(self, FieldGlob).last ||
      Helpers.find_elements(self, Name).last
    element.text_value
  else "?column?"
  end
end

#root_nodesObject



155
156
157
# File 'lib/vsql_node_extensions.rb', line 155

def root_nodes
  elements[0].elements.select { |e| ! e.text_value.empty? }
end