Class: Music::Transcription::Tempo
- Inherits:
-
Object
- Object
- Music::Transcription::Tempo
- Includes:
- Parseable
- Defined in:
- lib/music-transcription/model/tempo.rb,
lib/music-transcription/conversion/tempo_conversion.rb,
lib/music-transcription/parsing/convenience_methods.rb
Defined Under Namespace
Constant Summary collapse
- PARSER =
Parsing::TempoParser.new
- CONVERSION_METHOD =
:to_tempo
Constants included from Parseable
Parseable::DEFAULT_SPLIT_PATTERN
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #clone ⇒ Object
- #convert(tgt_class, bdur = nil) ⇒ Object
-
#initialize(value) ⇒ Tempo
constructor
A new instance of Tempo.
Methods included from Parseable
Constructor Details
#initialize(value) ⇒ Tempo
Returns a new instance of Tempo.
6 7 8 9 |
# File 'lib/music-transcription/model/tempo.rb', line 6 def initialize value raise NonPositiveError, "Given tempo value #{value} is not positive" if value <= 0 @value = value end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/music-transcription/model/tempo.rb', line 5 def value @value end |
Instance Method Details
#==(other) ⇒ Object
11 12 13 |
# File 'lib/music-transcription/model/tempo.rb', line 11 def ==(other) self.class == other.class && self.value == other.value end |
#clone ⇒ Object
15 16 17 |
# File 'lib/music-transcription/model/tempo.rb', line 15 def clone self.class.new(@value) end |
#convert(tgt_class, bdur = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/music-transcription/conversion/tempo_conversion.rb', line 5 def convert tgt_class, bdur = nil args = (is_a?(BPM) || tgt_class == BPM) ? [bdur] : [] return case tgt_class.new(1) when self.class then self.clone when Tempo::QNPM then to_qnpm(*args) when Tempo::NPM then to_npm(*args) when Tempo::NPS then to_nps(*args) when Tempo::BPM then to_bpm(*args) else raise TypeError, "Unexpected target tempo class #{tgt_class}" end end |