Class: Brule::Engine
- Inherits:
-
Object
- Object
- Brule::Engine
- Defined in:
- lib/brule.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.
67 68 69 70 |
# File 'lib/brule.rb', line 67 def initialize(rules:) @rules = rules @history = {} end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
65 66 67 |
# File 'lib/brule.rb', line 65 def context @context end |
Instance Method Details
#call(context = {}) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/brule.rb', line 72 def call(context = {}) @history = {} @context = Context.wrap(context) snapshot!(tag: :initial) @rules.each { |rule| apply(rule) } result end |
#history(key:) ⇒ Object
80 81 82 |
# File 'lib/brule.rb', line 80 def history(key:) @history.map { |tag, content| [tag, content.fetch(key, nil)] } end |