Class: HeadMusic::DiatonicInterval::Parser
- Inherits:
-
Object
- Object
- HeadMusic::DiatonicInterval::Parser
- Defined in:
- lib/head_music/diatonic_interval.rb
Overview
Interprets a string or symbol
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Instance Method Summary collapse
- #degree_name ⇒ Object
- #expand(identifier) ⇒ Object
- #higher_letter ⇒ Object
-
#initialize(identifier) ⇒ Parser
constructor
A new instance of Parser.
- #quality_for(abbreviation) ⇒ Object
- #quality_name ⇒ Object
- #steps ⇒ Object
- #words ⇒ Object
Constructor Details
#initialize(identifier) ⇒ Parser
Returns a new instance of Parser.
50 51 52 |
# File 'lib/head_music/diatonic_interval.rb', line 50 def initialize(identifier) @identifier = (identifier) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
48 49 50 |
# File 'lib/head_music/diatonic_interval.rb', line 48 def identifier @identifier end |
Instance Method Details
#degree_name ⇒ Object
62 63 64 |
# File 'lib/head_music/diatonic_interval.rb', line 62 def degree_name words.last end |
#expand(identifier) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/head_music/diatonic_interval.rb', line 74 def (identifier) if /[A-Z]\d{1,2}/i.match?(identifier) number = NUMBER_NAMES[identifier.gsub(/[A-Z]/i, "").to_i - 1] return [quality_for(identifier[0]), number].join("_").to_sym end identifier end |
#higher_letter ⇒ Object
70 71 72 |
# File 'lib/head_music/diatonic_interval.rb', line 70 def higher_letter HeadMusic::Pitch.middle_c.letter_name.steps_up(steps) end |
#quality_for(abbreviation) ⇒ Object
82 83 84 85 86 |
# File 'lib/head_music/diatonic_interval.rb', line 82 def quality_for(abbreviation) QUALITY_ABBREVIATIONS[abbreviation.to_sym] || QUALITY_ABBREVIATIONS[abbreviation.upcase.to_sym] || QUALITY_ABBREVIATIONS[abbreviation.downcase.to_sym] end |
#quality_name ⇒ Object
58 59 60 |
# File 'lib/head_music/diatonic_interval.rb', line 58 def quality_name words[0..-2].join(" ").to_sym end |
#steps ⇒ Object
66 67 68 |
# File 'lib/head_music/diatonic_interval.rb', line 66 def steps NUMBER_NAMES.index(degree_name) end |
#words ⇒ Object
54 55 56 |
# File 'lib/head_music/diatonic_interval.rb', line 54 def words identifier.to_s.split(/[_ ]+/) end |