lib/head_music/interval.rb in head_music-0.14.8 vs lib/head_music/interval.rb in head_music-0.16.0

- old
+ new

@@ -5,17 +5,14 @@ NAMES = %w{perfect_unison minor_second major_second minor_third major_third perfect_fourth tritone perfect_fifth minor_sixth major_sixth minor_seventh major_seventh perfect_octave} attr_reader :semitones - def self.get(semitones) + def self.get(identifier) @intervals ||= {} - @intervals[semitones.to_i] ||= new(semitones.to_i) - end - - def self.named(name) - name = name.to_s - get(NAMES.index(name)) if NAMES.include?(name) + candidate = identifier.to_s.downcase.gsub(/\W+/, '_') + semitones = NAMES.index(candidate) || identifier.to_i + @intervals[semitones] ||= new(semitones.to_i) end def initialize(semitones) @semitones = semitones end