Class: 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
-
#+(variation) ⇒ Value
Adds a variation to the Value, returning a new one with the sum of variations.
-
#initialize(value, variation = nil) ⇒ Value
constructor
Initializes with the value passed in, and an optional variation.
-
#to_f(pattern) ⇒ Float?
Converts the value to float.
-
#to_i(pattern) ⇒ Integer?
Converts the value to integer.
-
#to_s ⇒ Object
String representation for this value, either a number or the name of the variable.
Constructor Details
#initialize(value, variation = nil) ⇒ Value
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
#+(variation) ⇒ Value
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 |
#to_f(pattern) ⇒ Float?
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 |
#to_i(pattern) ⇒ Integer?
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 |
#to_s ⇒ Object
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 |