Class: HeadMusic::Rudiment::Quality
- Defined in:
- lib/head_music/rudiment/quality.rb
Overview
A quality is a categorization of an interval.
Constant Summary collapse
- SHORTHAND =
{ perfect: "P", major: "M", minor: "m", diminished: "d", augmented: "A", doubly_diminished: "dd", doubly_augmented: "AA" }.freeze
- NAMES =
SHORTHAND.keys
- PERFECT_INTERVAL_MODIFICATION =
{ -2 => :doubly_diminished, -1 => :diminished, 0 => :perfect, 1 => :augmented, 2 => :doubly_augmented }.freeze
- MAJOR_INTERVAL_MODIFICATION =
{ -2 => :diminished, -1 => :minor, 0 => :major, 1 => :augmented, 2 => :doubly_augmented }.freeze
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #article ⇒ Object
-
#initialize(name) ⇒ Quality
constructor
A new instance of Quality.
- #shorthand ⇒ Object
Constructor Details
#initialize(name) ⇒ Quality
52 53 54 |
# File 'lib/head_music/rudiment/quality.rb', line 52 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
48 49 50 |
# File 'lib/head_music/rudiment/quality.rb', line 48 def name @name end |
Class Method Details
.from(starting_quality, delta) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/head_music/rudiment/quality.rb', line 39 def self.from(starting_quality, delta) case starting_quality when :perfect PERFECT_INTERVAL_MODIFICATION[delta].to_s.gsub(/_+/, " ") when :major MAJOR_INTERVAL_MODIFICATION[delta].to_s.gsub(/_+/, " ") end end |
.get(identifier) ⇒ Object
33 34 35 36 37 |
# File 'lib/head_music/rudiment/quality.rb', line 33 def self.get(identifier) @qualities ||= {} identifier = identifier.to_s.to_sym @qualities[identifier] ||= new(identifier) if NAMES.include?(identifier) end |
Instance Method Details
#==(other) ⇒ Object
56 57 58 |
# File 'lib/head_music/rudiment/quality.rb', line 56 def ==(other) to_s == other.to_s end |
#article ⇒ Object
64 65 66 |
# File 'lib/head_music/rudiment/quality.rb', line 64 def article %w[a e i o u h].include?(name.to_s.first) ? "an" : "a" end |
#shorthand ⇒ Object
60 61 62 |
# File 'lib/head_music/rudiment/quality.rb', line 60 def shorthand SHORTHAND[name] end |