Class: Dentaku::AST::Function
Direct Known Subclasses
All, Any, Count, Duration, Filter, If, Map, Pluck, RubyMath, StringFunctions::Base
Constant Summary collapse
- DIG =
Returns with the number of significant decimal digits to use.
Float::DIG + 1
Class Method Summary collapse
- .get(name) ⇒ Object
-
.numeric(value) ⇒ Numeric
An Exception will be raised if a value is passed that cannot be cast to a Number.
- .register(name, type, implementation) ⇒ Object
- .register_class(name, function_class) ⇒ Object
- .registry ⇒ Object
Instance Method Summary collapse
-
#deferred_args ⇒ Object
override if your function implementation needs to defer evaluation of any arguments.
- #dependencies(context = {}) ⇒ Object
-
#initialize(*args) ⇒ Function
constructor
A new instance of Function.
Methods inherited from Node
arity, peek, precedence, #type
Constructor Details
#initialize(*args) ⇒ Function
Returns a new instance of Function.
10 11 12 |
# File 'lib/dentaku/ast/function.rb', line 10 def initialize(*args) @args = args end |
Class Method Details
.get(name) ⇒ Object
27 28 29 |
# File 'lib/dentaku/ast/function.rb', line 27 def self.get(name) registry.get(name) end |
.numeric(value) ⇒ Numeric
An Exception will be raised if a value is passed that cannot be cast to a Number.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dentaku/ast/function.rb', line 45 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) ⇒ Object
31 32 33 |
# File 'lib/dentaku/ast/function.rb', line 31 def self.register(name, type, implementation) registry.register(name, type, implementation) end |
.register_class(name, function_class) ⇒ Object
35 36 37 |
# File 'lib/dentaku/ast/function.rb', line 35 def self.register_class(name, function_class) registry.register_class(name, function_class) end |
.registry ⇒ Object
39 40 41 |
# File 'lib/dentaku/ast/function.rb', line 39 def self.registry @registry ||= FunctionRegistry.new end |
Instance Method Details
#deferred_args ⇒ Object
override if your function implementation needs to defer evaluation of any arguments
23 24 25 |
# File 'lib/dentaku/ast/function.rb', line 23 def deferred_args [] end |
#dependencies(context = {}) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/dentaku/ast/function.rb', line 14 def dependencies(context = {}) deferred = deferred_args @args.each_with_index .reject { |_, i| deferred.include? i } .flat_map { |a, _| a.dependencies(context) } end |