Class: MusicalScore::Notes
- Inherits:
-
ElementBase
- Object
- ElementBase
- MusicalScore::Notes
- Includes:
- Contracts, Enumerable
- Defined in:
- lib/musical_score/notes.rb
Instance Attribute Summary collapse
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #divide_to_notes_and_rests ⇒ Object
- #each ⇒ Object
-
#initialize(notes) ⇒ Notes
constructor
A new instance of Notes.
- #set_location(location, number) ⇒ Object
Methods inherited from ElementBase
create_by_hash, create_by_xml, #export_xml
Constructor Details
#initialize(notes) ⇒ Notes
Returns a new instance of Notes.
10 11 12 |
# File 'lib/musical_score/notes.rb', line 10 def initialize(notes) @notes = notes end |
Instance Attribute Details
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
7 8 9 |
# File 'lib/musical_score/notes.rb', line 7 def duration @duration end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
7 8 9 |
# File 'lib/musical_score/notes.rb', line 7 def notes @notes end |
Instance Method Details
#[](index) ⇒ Object
18 19 20 |
# File 'lib/musical_score/notes.rb', line 18 def [](index) return @notes[index] end |
#divide_to_notes_and_rests ⇒ Object
13 14 15 16 |
# File 'lib/musical_score/notes.rb', line 13 def divide_to_notes_and_rests divided_array = @notes.partition { |note| note.rest } return { note: divided_array[1], rest: divided_array[0] } end |
#each ⇒ Object
22 23 24 25 26 |
# File 'lib/musical_score/notes.rb', line 22 def each @notes.each do |note| yield note end end |
#set_location(location, number) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/musical_score/notes.rb', line 28 def set_location(location, number) current_location = MusicalScore::Location.new(number, location) @notes.each do |note| note.location = current_location current_location = MusicalScore::Location.new(number, current_location.location + note.actual_duration) end @duration = current_location.location - location end |