Class: Coltrane::ChordQuality
- Inherits:
-
IntervalSequence
- Object
- IntervalSequence
- Coltrane::ChordQuality
- Defined in:
- lib/coltrane/chord_quality.rb
Overview
It describe the quality of a chord, like maj7 or dim.
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute name.
Attributes inherited from IntervalSequence
Instance Method Summary collapse
- #get_name ⇒ Object
-
#initialize(name: nil, notes: nil) ⇒ ChordQuality
constructor
A new instance of ChordQuality.
- #suspension_type ⇒ Object
Methods inherited from IntervalSequence
#&, #[], #all, #distances, #full_names, #has?, #interval_names, #intervals_semitones, #inversion, #inversions, #names, #next_inversion, #notes_for, #previous_inversion, #shift, #zero_it
Constructor Details
#initialize(name: nil, notes: nil) ⇒ ChordQuality
Returns a new instance of ChordQuality.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/coltrane/chord_quality.rb', line 97 def initialize(name: nil, notes: nil) if !name.nil? @name = name super(intervals: NAMES[name]) elsif !notes.nil? super(notes: notes) @name = get_name else raise WrongKeywordsError, '[name:] || [notes:]' end end |
Instance Attribute Details
#name ⇒ Object (readonly) Also known as: to_s
Returns the value of attribute name.
6 7 8 |
# File 'lib/coltrane/chord_quality.rb', line 6 def name @name end |
Instance Method Details
#get_name ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/coltrane/chord_quality.rb', line 75 def get_name if result = find_chord([*retrieve_chord_intervals].compact) return result elsif result = find_chord([*retrieve_chord_intervals(sus2_sequence)].compact) return result elsif result = find_chord([*retrieve_chord_intervals(sus4_sequence)].compact) return result else binding.pry raise ChordNotFoundError end end |
#suspension_type ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/coltrane/chord_quality.rb', line 89 def suspension_type if has_major_second? 'sus2' else has_fourth? 'sus4' end end |