Class: Arrow::Expression

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/expression.rb

Class Method Summary collapse

Class Method Details

.try_convert(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/arrow/expression.rb', line 22

def try_convert(value)
  case value
  when Symbol
    FieldExpression.new(value.to_s)
  when ::Array
    function_name, *arguments = value
    case function_name
    when String, Symbol
      function_name = function_name.to_s
    else
      return nil
    end
    options = nil
    if arguments.last.is_a?(FunctionOptions)
      options = arguments.pop
    elsif arguments.last.is_a?(Hash)
      function = Function.find(function_name)
      if function
        options = function.resolve_options(arguments.pop)
      end
    end
    CallExpression.new(function_name, arguments, options)
  else
    datum = Datum.try_convert(value)
    return nil if datum.nil?
    LiteralExpression.new(datum)
  end
end