Class: Usine::Evaluator
- Inherits:
-
Object
- Object
- Usine::Evaluator
- Defined in:
- lib/usine/evaluator.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#scoped_sequences ⇒ Object
readonly
Returns the value of attribute scoped_sequences.
-
#sequences ⇒ Object
readonly
Returns the value of attribute sequences.
Instance Method Summary collapse
- #generate(attribute) ⇒ Object
-
#initialize(sequences = {}) ⇒ Evaluator
constructor
A new instance of Evaluator.
- #method_missing(method_symbol, *args, &block) ⇒ Object
- #sequence(name, initial_value = 1, &block) ⇒ Object
Constructor Details
#initialize(sequences = {}) ⇒ Evaluator
Returns a new instance of Evaluator.
7 8 9 10 11 |
# File 'lib/usine/evaluator.rb', line 7 def initialize(sequences = {}) @sequences = sequences @scoped_sequences = [] @attributes = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/usine/evaluator.rb', line 13 def method_missing(method_symbol, *args, &block) if block @attributes[method_symbol] = block.call else @attributes[method_symbol] = generate(method_symbol) end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/usine/evaluator.rb', line 3 def attributes @attributes end |
#scoped_sequences ⇒ Object (readonly)
Returns the value of attribute scoped_sequences.
5 6 7 |
# File 'lib/usine/evaluator.rb', line 5 def scoped_sequences @scoped_sequences end |
#sequences ⇒ Object (readonly)
Returns the value of attribute sequences.
4 5 6 |
# File 'lib/usine/evaluator.rb', line 4 def sequences @sequences end |
Instance Method Details
#generate(attribute) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/usine/evaluator.rb', line 21 def generate(attribute) if sequence = scoped_sequences.detect { |x| x.attribute == attribute } sequence.next elsif sequence = sequences.detect { |x| x.attribute == attribute } sequence.next else raise(UsineError::SequenceNotFound, "Couldn’t find a sequence named : `#{attribute}`") end end |