Class: Brule::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/brule/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (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