Class: Stretto::Value
- Inherits:
-
Object
- Object
- Stretto::Value
- Defined in:
- lib/stretto/music_elements/modifiers/value.rb
Overview
This class acts as a placeholder for values contained by musical elements.
It is needed in order to retrieve values held by a variable until evaluation, looking for them in the pattern the element belongs, or one of the predefined variables.
Defined Under Namespace
Classes: NumericValue, VariableValue
Instance Method Summary (collapse)
-
- (Value) +(variation)
Adds a variation to the Value, returning a new one with the sum of variations.
-
- (Value) initialize(value, variation = nil)
constructor
Initializes with the value passed in, and an optional variation.
-
- (Float?) to_f(pattern)
Converts the value to float.
-
- (Integer?) to_i(pattern)
Converts the value to integer.
-
- (Object) to_s
String representation for this value, either a number or the name of the variable.
Constructor Details
- (Value) initialize(value, variation = nil)
Initializes with the value passed in, and an optional variation.
and have it evaluated until requested
129 130 131 132 |
# File 'lib/stretto/music_elements/modifiers/value.rb', line 129 def initialize(value, variation = nil) @value = value @variation = variation end |
Instance Method Details
- (Value) +(variation)
Adds a variation to the Value, returning a new one with the sum of variations
159 160 161 162 |
# File 'lib/stretto/music_elements/modifiers/value.rb', line 159 def +(variation) new_variation = [@variation, variation].compact.sum self.class.new(@value, new_variation) end |
- (Float?) to_f(pattern)
Converts the value to float
148 149 150 151 152 153 154 |
# File 'lib/stretto/music_elements/modifiers/value.rb', line 148 def to_f(pattern) if @value result = @value.to_f(pattern) result += @variation if @variation result end end |
- (Integer?) to_i(pattern)
Converts the value to integer
137 138 139 140 141 142 143 |
# File 'lib/stretto/music_elements/modifiers/value.rb', line 137 def to_i(pattern) if @value result = @value.to_i(pattern) result += @variation if @variation result end end |
- (Object) to_s
String representation for this value, either a number or the name of the variable.
165 166 167 168 169 |
# File 'lib/stretto/music_elements/modifiers/value.rb', line 165 def to_s output = @value.to_s output += "+#{@variation}" if @variation output end |