Class: Hammelin::NotesRange
- Inherits:
-
Object
- Object
- Hammelin::NotesRange
- Includes:
- Enumerable
- Defined in:
- lib/hammelin/notes_range.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
Returns the value of attribute notes.
Class Method Summary collapse
Instance Method Summary collapse
- #decrease_octave(times = 1) ⇒ Object
-
#downto(value) ⇒ Object
(also: #upto)
downto and upto are just some sintactic sugar for expanding the range to a new value.
- #each ⇒ Object
- #increase_octave(times = 1) ⇒ Object
-
#initialize(array) ⇒ NotesRange
constructor
A new instance of NotesRange.
- #music_string ⇒ Object
- #play ⇒ Object
- #reverse ⇒ Object
Constructor Details
#initialize(array) ⇒ NotesRange
Returns a new instance of NotesRange.
9 10 11 |
# File 'lib/hammelin/notes_range.rb', line 9 def initialize(array) @notes = array end |
Instance Attribute Details
#notes ⇒ Object
Returns the value of attribute notes.
7 8 9 |
# File 'lib/hammelin/notes_range.rb', line 7 def notes @notes end |
Class Method Details
.from_array(array) ⇒ Object
17 18 19 |
# File 'lib/hammelin/notes_range.rb', line 17 def self.from_array(array) NotesRange.new(array) end |
.from_range(from, to) ⇒ Object
13 14 15 |
# File 'lib/hammelin/notes_range.rb', line 13 def self.from_range(from,to) NotesRange.new(transverse_notes(from,to)) end |
Instance Method Details
#decrease_octave(times = 1) ⇒ Object
53 54 55 56 57 |
# File 'lib/hammelin/notes_range.rb', line 53 def decrease_octave(times=1) notes = @notes.map {|note| note.decrease_octave(times)} NotesRange.new(notes) end |
#downto(value) ⇒ Object Also known as: upto
downto and upto are just some sintactic sugar for expanding the range to a new value. It will create a new NotesRange object with the last Note and then will figure out how to get to the newest one.
41 42 43 |
# File 'lib/hammelin/notes_range.rb', line 41 def downto(value) NotesRange.from_range(last,value) end |
#each ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/hammelin/notes_range.rb', line 21 def each if block_given? @notes.each {|note| yield note} else to_enum(:each) end end |
#increase_octave(times = 1) ⇒ Object
47 48 49 50 51 |
# File 'lib/hammelin/notes_range.rb', line 47 def increase_octave(times=1) notes = @notes.map {|note| note.increase_octave(times)} NotesRange.new(notes) end |
#music_string ⇒ Object
59 60 61 |
# File 'lib/hammelin/notes_range.rb', line 59 def music_string @notes.map{|i| i.music_string }.join(" ") end |
#play ⇒ Object
33 34 35 36 |
# File 'lib/hammelin/notes_range.rb', line 33 def play Hammelin.play_string music_string self end |
#reverse ⇒ Object
29 30 31 |
# File 'lib/hammelin/notes_range.rb', line 29 def reverse @notes.reverse end |