Class: MusicalScore::Notes

Inherits:
ElementBase show all
Includes:
Contracts, Enumerable
Defined in:
lib/musical_score/notes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#durationObject (readonly)

Returns the value of attribute duration.



7
8
9
# File 'lib/musical_score/notes.rb', line 7

def duration
  @duration
end

#notesObject (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_restsObject



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

#eachObject



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