Class: Brule::Engine
- Inherits:
-
Object
- Object
- Brule::Engine
- Defined in:
- lib/brule/engine.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #call(context = {}) ⇒ Object
- #history(key:) ⇒ Object
-
#initialize(rules:) ⇒ Engine
constructor
A new instance of Engine.
Constructor Details
#initialize(rules:) ⇒ Engine
Returns a new instance of Engine.
5 6 7 8 |
# File 'lib/brule/engine.rb', line 5 def initialize(rules:) @rules = rules @history = {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/brule/engine.rb', line 3 def context @context end |
Instance Method Details
#call(context = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/brule/engine.rb', line 10 def call(context = {}) @history = {} @context = context snapshot!(tag: :initial) @rules.each { |rule| apply(rule) } result end |
#history(key:) ⇒ Object
18 19 20 |
# File 'lib/brule/engine.rb', line 18 def history(key:) @history.map { |tag, content| [tag, content.fetch(key, nil)] } end |