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.
52 53 54 |
# File 'lib/head_music/diatonic_interval.rb', line 52 def initialize(identifier) @identifier = (identifier) end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
50 51 52 |
# File 'lib/head_music/diatonic_interval.rb', line 50 def identifier @identifier end |
Instance Method Details
#degree_name ⇒ Object
64 65 66 |
# File 'lib/head_music/diatonic_interval.rb', line 64 def degree_name words.last end |
#expand(identifier) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/head_music/diatonic_interval.rb', line 76 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
72 73 74 |
# File 'lib/head_music/diatonic_interval.rb', line 72 def higher_letter HeadMusic::Pitch.middle_c.letter_name.steps_up(steps) end |
#quality_for(abbreviation) ⇒ Object
84 85 86 87 88 |
# File 'lib/head_music/diatonic_interval.rb', line 84 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
60 61 62 |
# File 'lib/head_music/diatonic_interval.rb', line 60 def quality_name words[0..-2].join(" ").to_sym end |
#steps ⇒ Object
68 69 70 |
# File 'lib/head_music/diatonic_interval.rb', line 68 def steps NUMBER_NAMES.index(degree_name) end |
#words ⇒ Object
56 57 58 |
# File 'lib/head_music/diatonic_interval.rb', line 56 def words identifier.to_s.split(/[_ ]+/) end |