Class: Coltrane::NoteSet
- Inherits:
-
Object
- Object
- Coltrane::NoteSet
- Extended by:
- Forwardable
- Defined in:
- lib/coltrane/note_set.rb
Overview
It describes a set of notes
Instance Attribute Summary collapse
-
#notes ⇒ Object
(also: #all)
readonly
Returns the value of attribute notes.
Class Method Summary collapse
Instance Method Summary collapse
- #&(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #degree(note) ⇒ Object
-
#initialize(arg) ⇒ NoteSet
constructor
A new instance of NoteSet.
- #integers ⇒ Object
- #interval_sequence ⇒ Object
- #names ⇒ Object
- #pretty_names ⇒ Object
Constructor Details
#initialize(arg) ⇒ NoteSet
Returns a new instance of NoteSet.
20 21 22 23 24 25 26 27 |
# File 'lib/coltrane/note_set.rb', line 20 def initialize(arg) @notes = case arg when NoteSet then arg.notes when Array then arg.map { |n| n.is_a?(Note) ? n : Note[n] }.uniq else raise InvalidNotesError, arg end end |
Instance Attribute Details
#notes ⇒ Object (readonly) Also known as: all
Returns the value of attribute notes.
11 12 13 |
# File 'lib/coltrane/note_set.rb', line 11 def notes @notes end |
Class Method Details
.[](*notes) ⇒ Object
16 17 18 |
# File 'lib/coltrane/note_set.rb', line 16 def self.[](*notes) new(notes) end |
Instance Method Details
#&(other) ⇒ Object
29 30 31 |
# File 'lib/coltrane/note_set.rb', line 29 def &(other) NoteSet[*(notes & other.notes)] end |
#+(other) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/coltrane/note_set.rb', line 37 def +(other) case other when Note then NoteSet[*(notes + [other])] when NoteSet then NoteSet[*notes, *other.notes] when Interval then NoteSet[*notes.map { |n| n + other }] end end |
#-(other) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/coltrane/note_set.rb', line 45 def -(other) case other when NoteSet then NoteSet[*(notes - other.notes)] when Interval then NoteSet[*notes.map { |n| n - other }] end end |
#degree(note) ⇒ Object
33 34 35 |
# File 'lib/coltrane/note_set.rb', line 33 def degree(note) index(note) + 1 end |
#integers ⇒ Object
60 61 62 |
# File 'lib/coltrane/note_set.rb', line 60 def integers map(&:integer) end |
#interval_sequence ⇒ Object
64 65 66 |
# File 'lib/coltrane/note_set.rb', line 64 def interval_sequence IntervalSequence.new(notes: self) end |
#names ⇒ Object
56 57 58 |
# File 'lib/coltrane/note_set.rb', line 56 def names map(&:name) end |
#pretty_names ⇒ Object
52 53 54 |
# File 'lib/coltrane/note_set.rb', line 52 def pretty_names map(&:pretty_name) end |