class Dentaku::AST::Function

Constants

DIG

@return [Integer] with the number of significant decimal digits to use.

Attributes

args[R]

Public Class Methods

get(name) click to toggle source
# File lib/dentaku/ast/function.rb, line 25
def self.get(name)
  registry.get(name)
end
new(*args) click to toggle source
# File lib/dentaku/ast/function.rb, line 12
def initialize(*args)
  @args = args
end
numeric(value) click to toggle source

@return [Numeric] where possible it returns an Integer otherwise a BigDecimal. An Exception will be raised if a value is passed that cannot be cast to a Number.

# File lib/dentaku/ast/function.rb, line 43
def self.numeric(value)
  return value if value.is_a?(::Numeric)

  if value.is_a?(::String)
    number = value[/\A-?\d*\.?\d+\z/]
    return number.include?('.') ? BigDecimal(number, DIG) : number.to_i if number
  end

  raise Dentaku::ArgumentError.for(:incompatible_type, value: value, for: Numeric),
    "'#{value || value.class}' is not coercible to numeric"
end
register(name, type, implementation) click to toggle source
# File lib/dentaku/ast/function.rb, line 29
def self.register(name, type, implementation)
  registry.register(name, type, implementation)
end
register_class(name, function_class) click to toggle source
# File lib/dentaku/ast/function.rb, line 33
def self.register_class(name, function_class)
  registry.register_class(name, function_class)
end
registry() click to toggle source
# File lib/dentaku/ast/function.rb, line 37
def self.registry
  @registry ||= FunctionRegistry.new
end

Public Instance Methods

accept(visitor) click to toggle source
# File lib/dentaku/ast/function.rb, line 16
def accept(visitor)
  visitor.visit_function(self)
end
dependencies(context = {}) click to toggle source
# File lib/dentaku/ast/function.rb, line 20
def dependencies(context = {})
  @args.each_with_index
       .flat_map { |a, _| a.dependencies(context) }
end