Class: DiceBag::Normalize
- Inherits:
-
Object
- Object
- DiceBag::Normalize
- Defined in:
- lib/dicebag/normalize.rb
Overview
Encapsulate the Normalization Process
This takes the parsed tree, AFTER it has been through the Transform class, and massages the data a bit more, to ease the iteration that happens in the Roll class. It will convert all values into the correct *Part classes.
Instance Attribute Summary collapse
-
#ast ⇒ Object
readonly
The Abstract Source Tree.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ast) ⇒ Normalize
constructor
A new instance of Normalize.
- #perform ⇒ Object
Constructor Details
#initialize(ast) ⇒ Normalize
Returns a new instance of Normalize.
17 18 19 20 21 22 23 24 |
# File 'lib/dicebag/normalize.rb', line 17 def initialize(ast) # ASTs that only have a :start section will be a single array by # itself, with the first element being `:start`, so we need to # wrap it once more. ast = [ast] unless ast.first.is_a? Array @ast = ast end |
Instance Attribute Details
#ast ⇒ Object (readonly)
The Abstract Source Tree
11 12 13 |
# File 'lib/dicebag/normalize.rb', line 11 def ast @ast end |
Class Method Details
.call(ast) ⇒ Object
13 14 15 |
# File 'lib/dicebag/normalize.rb', line 13 def self.call(ast) new(ast).perform end |
Instance Method Details
#perform ⇒ Object
26 27 28 |
# File 'lib/dicebag/normalize.rb', line 26 def perform ast.map { |part| normalize part } end |