Class: HeadMusic::Rudiment::RhythmicElement

Inherits:
Base
  • Object
show all
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

Note, Rest, UnpitchedNote

Constant Summary collapse

LetterName =
HeadMusic::Rudiment::LetterName
Alteration =
HeadMusic::Rudiment::Alteration
Register =
HeadMusic::Rudiment::Register
RhythmicValue =
HeadMusic::Rudiment::RhythmicValue

Instance Attribute Summary collapse

Instance Method Summary collapse

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_valueObject (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

#nameObject

Abstract method - must be implemented by subclasses

Raises:

  • (NotImplementedError)


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

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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_sObject



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