Class: Clef::Notation::Beam

Inherits:
Object
  • Object
show all
Defined in:
lib/clef/notation/beam.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notes) ⇒ Beam

Returns a new instance of Beam.

Parameters:

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/clef/notation/beam.rb', line 9

def initialize(notes)
  raise ArgumentError, "beam requires at least two notes" if notes.length < 2

  @notes = notes
end

Instance Attribute Details

#notesObject (readonly)

Returns the value of attribute notes.



6
7
8
# File 'lib/clef/notation/beam.rb', line 6

def notes
  @notes
end

Instance Method Details

#levelInteger

Returns:

  • (Integer)


16
17
18
19
20
21
22
# File 'lib/clef/notation/beam.rb', line 16

def level
  shortest = notes.map { |note| note.duration.base_value }.min
  return 1 if shortest >= Rational(1, 8)
  return 2 if shortest >= Rational(1, 16)

  3
end