Class: Brule::Engine

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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