class HeadMusic::DiatonicInterval::Parser

Interprets a string or symbol

Attributes

identifier[R]

Public Class Methods

new(identifier) click to toggle source
# File lib/head_music/diatonic_interval.rb, line 52
def initialize(identifier)
  @identifier = expand(identifier)
end

Public Instance Methods

degree_name() click to toggle source
# File lib/head_music/diatonic_interval.rb, line 64
def degree_name
  words.last
end
expand(identifier) click to toggle source
# File lib/head_music/diatonic_interval.rb, line 76
def expand(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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/head_music/diatonic_interval.rb, line 60
def quality_name
  words[0..-2].join(' ').to_sym
end
steps() click to toggle source
# File lib/head_music/diatonic_interval.rb, line 68
def steps
  NUMBER_NAMES.index(degree_name)
end
words() click to toggle source
# File lib/head_music/diatonic_interval.rb, line 56
def words
  identifier.to_s.split(/[_ ]+/)
end