Class: Dentaku::BulkExpressionSolver
- Inherits:
-
Object
- Object
- Dentaku::BulkExpressionSolver
show all
- Defined in:
- lib/dentaku/bulk_expression_solver.rb
Defined Under Namespace
Classes: PermissiveEvaluator, StrictEvaluator
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BulkExpressionSolver.
32
33
34
35
|
# File 'lib/dentaku/bulk_expression_solver.rb', line 32
def initialize(expressions, calculator)
@expression_hash = FlatHash.from_hash(expressions)
@calculator = calculator
end
|
Instance Method Details
#dependencies ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/dentaku/bulk_expression_solver.rb', line 55
def dependencies
Hash[expression_deps].tap do |d|
d.values.each do |deps|
unresolved = deps.reject { |ud| d.has_key?(ud) }
unresolved.each { |u| add_dependencies(d, u) }
end
end
end
|
#solve(&block) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/dentaku/bulk_expression_solver.rb', line 42
def solve(&block)
@evaluator ||= PermissiveEvaluator.new(calculator, block)
error_handler = block || return_undefined_handler
results = load_results(&error_handler)
FlatHash.expand(
expression_hash.each_with_object({}) do |(k, v), r|
default = v.nil? ? v : :undefined
r[k] = results.fetch(k.to_s, default)
end
)
end
|
#solve! ⇒ Object
37
38
39
40
|
# File 'lib/dentaku/bulk_expression_solver.rb', line 37
def solve!
@evaluator = StrictEvaluator.new(calculator)
solve(&raise_exception_handler)
end
|