Class: Clef::Core::Chord

Inherits:
Object
  • Object
show all
Defined in:
lib/clef/core/chord.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitches, duration) ⇒ Chord

Returns a new instance of Chord.

Parameters:

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
# File 'lib/clef/core/chord.rb', line 10

def initialize(pitches, duration)
  validate_pitches!(pitches)
  raise ArgumentError, "duration must be a Clef::Core::Duration" unless duration.is_a?(Duration)

  @pitches = Array(pitches).freeze
  @duration = duration
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/clef/core/chord.rb', line 6

def duration
  @duration
end

#pitchesObject (readonly)

Returns the value of attribute pitches.



6
7
8
# File 'lib/clef/core/chord.rb', line 6

def pitches
  @pitches
end

Instance Method Details

#lengthRational

Returns:

  • (Rational)


19
20
21
# File 'lib/clef/core/chord.rb', line 19

def length
  duration.length
end

#sorted_pitchesArray<Pitch>

Returns:



24
25
26
# File 'lib/clef/core/chord.rb', line 24

def sorted_pitches
  pitches.sort
end