Sha256: 087f81117ced6b1d0d7547509aada4524026784011aec0b7f86df1b9d84e1eca

Contents?: true

Size: 849 Bytes

Versions: 2

Compression:

Stored size: 849 Bytes

Contents

module Jamming
  class Dictionary
    DICTIONARY = {
      "A"  => %w(x02220),
      "Am" => %w(x02210),
      "B"  => %w(x24442),
      "Bm" => %w(x24432),
      "C"  => %w(x32010),
      "Cm" => %w(x35543),
      "D"  => %w(xx0232),
      "Dm" => %w(xx0231),
      "E"  => %w(022100),      
      "Em" => %w(022000),
      "F"  => %w(133211),
      "Fm" => %w(133111),
      "G"  => %w(320022 320002),
      "Gm" => %w(355333)      
    }

    def self.name_for(frets)
      frets = normalize_frets(frets)
      DICTIONARY.each do |key, different_fingerings|
        return key if different_fingerings.include?(frets)
      end
      nil
    end
    
    private
      def self.normalize_frets(frets)
        join_with = frets.any? { |f| f && f >= 10 } ? "-" : ""
        frets.map { |f| f.nil? ? "x" : f.to_s }.join(join_with)
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jamming-0.2.1 lib/jamming/dictionary.rb
jamming-0.2.0 lib/jamming/dictionary.rb