Class: Grammoire::Rule
- Inherits:
-
Object
- Object
- Grammoire::Rule
- Defined in:
- lib/grammoire/rule.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #applies?(context) ⇒ Boolean
- #evaluate(context) ⇒ Object
-
#initialize(name, &setup) ⇒ Rule
constructor
A new instance of Rule.
- #pre_condition(&condition) ⇒ Object
- #produce(&action) ⇒ Object
- #weights(weight) ⇒ Object
Constructor Details
#initialize(name, &setup) ⇒ Rule
Returns a new instance of Rule.
5 6 7 8 9 10 11 |
# File 'lib/grammoire/rule.rb', line 5 def initialize(name, &setup) @name = name weights(1) pre_condition { true } instance_eval &setup if block_given? end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/grammoire/rule.rb', line 3 def name @name end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
3 4 5 |
# File 'lib/grammoire/rule.rb', line 3 def weight @weight end |
Instance Method Details
#applies?(context) ⇒ Boolean
21 22 23 |
# File 'lib/grammoire/rule.rb', line 21 def applies?(context) context.instance_eval &@condition end |
#evaluate(context) ⇒ Object
29 30 31 |
# File 'lib/grammoire/rule.rb', line 29 def evaluate(context) context.instance_eval &@action end |
#pre_condition(&condition) ⇒ Object
17 18 19 |
# File 'lib/grammoire/rule.rb', line 17 def pre_condition(&condition) @condition = condition end |
#produce(&action) ⇒ Object
25 26 27 |
# File 'lib/grammoire/rule.rb', line 25 def produce(&action) @action = action end |
#weights(weight) ⇒ Object
13 14 15 |
# File 'lib/grammoire/rule.rb', line 13 def weights(weight) @weight = weight end |