Module: Kumi::Core::Analyzer::ConstantFoldingHelpers
- Defined in:
- lib/kumi/core/analyzer/constant_folding_helpers.rb
Overview
This module provides pure Ruby implementations of primitive functions
specifically for the ConstantEvaluator to use at compile time.
This approach avoids all use of eval and is fast and secure.
It is references by the functions data yamls, as folding_method
Class Method Summary collapse
-
.add(a, b) ⇒ Object
:core :numeric.
-
.all?(collection) ⇒ Boolean
:agg :booleans.
-
.and(a, b) ⇒ Object
:core :booleans.
- .any?(collection) ⇒ Boolean
- .at(collection, index) ⇒ Object
- .avg(collection) ⇒ Object
- .count(collection) ⇒ Object
- .div(a, b) ⇒ Object
- .eq?(a, b) ⇒ Boolean
- .gt?(a, b) ⇒ Boolean
- .gte?(a, b) ⇒ Boolean
-
.length(collection) ⇒ Object
:core :constructor.
-
.lt?(a, b) ⇒ Boolean
:core :comparisons.
- .max(collection) ⇒ Object
- .min(collection) ⇒ Object
- .mod(a, b) ⇒ Object
- .mul(a, b) ⇒ Object
- .neq?(a, b) ⇒ Boolean
- .not?(a) ⇒ Boolean
- .or(a, b) ⇒ Object
-
.select(condition_mask, value_when_true, value_when_false) ⇒ Object
:core :select.
- .sub(a, b) ⇒ Object
-
.sum(collection) ⇒ Object
:agg :numeric.
- .tuple(*args) ⇒ Object
Class Method Details
.add(a, b) ⇒ Object
:core :numeric
25 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 25 def add(a, b) = a + b |
.all?(collection) ⇒ Boolean
:agg :booleans
14 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 14 def all?(collection) = collection.all? |
.and(a, b) ⇒ Object
:core :booleans
33 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 33 def and(a, b) = a && b |
.any?(collection) ⇒ Boolean
15 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 15 def any?(collection) = collection.any? |
.at(collection, index) ⇒ Object
30 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 30 def at(collection, index) = collection[index] |
.avg(collection) ⇒ Object
20 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 20 def avg(collection) = collection.sum.to_f / collection.size |
.count(collection) ⇒ Object
19 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 19 def count(collection) = collection.size |
.div(a, b) ⇒ Object
28 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 28 def div(a, b) = a.to_f / b |
.eq?(a, b) ⇒ Boolean
41 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 41 def eq?(a, b) = a == b |
.gt?(a, b) ⇒ Boolean
39 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 39 def gt?(a, b) = a > b |
.gte?(a, b) ⇒ Boolean
40 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 40 def gte?(a, b) = a >= b |
.length(collection) ⇒ Object
:core :constructor
45 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 45 def length(collection) = collection.size |
.lt?(a, b) ⇒ Boolean
:core :comparisons
38 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 38 def lt?(a, b) = a < b |
.max(collection) ⇒ Object
22 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 22 def max(collection) = collection.max |
.min(collection) ⇒ Object
21 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 21 def min(collection) = collection.min |
.mod(a, b) ⇒ Object
29 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 29 def mod(a, b) = a % b |
.mul(a, b) ⇒ Object
27 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 27 def mul(a, b) = a * b |
.neq?(a, b) ⇒ Boolean
42 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 42 def neq?(a, b) = a != b |
.not?(a) ⇒ Boolean
35 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 35 def not?(a) = !a |
.or(a, b) ⇒ Object
34 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 34 def or(a, b) = a || b |
.select(condition_mask, value_when_true, value_when_false) ⇒ Object
:core :select
49 50 51 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 49 def select(condition_mask, value_when_true, value_when_false) condition_mask ? value_when_true : value_when_false end |
.sub(a, b) ⇒ Object
26 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 26 def sub(a, b) = a - b |
.sum(collection) ⇒ Object
:agg :numeric
18 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 18 def sum(collection) = collection.sum |
.tuple(*args) ⇒ Object
46 |
# File 'lib/kumi/core/analyzer/constant_folding_helpers.rb', line 46 def tuple(*args) = args |