Class: HeadMusic::Rudiment::RhythmicElement
- Includes:
- Comparable
- Defined in:
- lib/head_music/rudiment/rhythmic_element.rb
Overview
Abstract base class for rhythmic elements that have a rhythmic value. This includes notes (pitched), rests (silence), and unpitched notes (percussion).
Direct Known Subclasses
Constant Summary collapse
- LetterName =
HeadMusic::Rudiment::LetterName
- Alteration =
HeadMusic::Rudiment::Alteration
- Register =
HeadMusic::Rudiment::Register
- RhythmicValue =
HeadMusic::Rudiment::RhythmicValue
Instance Attribute Summary collapse
-
#rhythmic_value ⇒ Object
readonly
Returns the value of attribute rhythmic_value.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(rhythmic_value) ⇒ RhythmicElement
constructor
A new instance of RhythmicElement.
-
#name ⇒ Object
Abstract method - must be implemented by subclasses.
-
#sounded? ⇒ Boolean
Abstract method - must be implemented by subclasses.
- #to_s ⇒ Object
-
#with_rhythmic_value(new_rhythmic_value) ⇒ Object
Create a new instance with a different rhythmic value.
Constructor Details
#initialize(rhythmic_value) ⇒ RhythmicElement
Returns a new instance of RhythmicElement.
21 22 23 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 21 def initialize(rhythmic_value) @rhythmic_value = rhythmic_value end |
Instance Attribute Details
#rhythmic_value ⇒ Object (readonly)
Returns the value of attribute rhythmic_value.
14 15 16 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 14 def rhythmic_value @rhythmic_value end |
Instance Method Details
#<=>(other) ⇒ Object
35 36 37 38 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 35 def <=>(other) return nil unless other.is_a?(HeadMusic::Rudiment::RhythmicElement) rhythmic_value <=> other.rhythmic_value end |
#==(other) ⇒ Object
30 31 32 33 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 30 def ==(other) return false unless other.is_a?(self.class) rhythmic_value == other.rhythmic_value end |
#name ⇒ Object
Abstract method - must be implemented by subclasses
45 46 47 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 45 def name raise NotImplementedError, "Subclasses must implement the name method" end |
#sounded? ⇒ Boolean
Abstract method - must be implemented by subclasses
50 51 52 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 50 def sounded? raise NotImplementedError, "Subclasses must implement the sounded? method" end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 40 def to_s name end |
#with_rhythmic_value(new_rhythmic_value) ⇒ Object
Create a new instance with a different rhythmic value
26 27 28 |
# File 'lib/head_music/rudiment/rhythmic_element.rb', line 26 def with_rhythmic_value(new_rhythmic_value) self.class.get(new_rhythmic_value) end |