Sha256: 1cff9aae6cb7959d66f4415148b3563b65b1c82dc1bdef56b1ebd1c65a7200d0

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

class Uke
  class Fretboard
    STYLES = {
      small: { open: " ⚪", finger: " ●" },
      large: { open: " ○", finger: "⬤ " },
    }

    def initialize(chord, style = nil)
      @chord  = chord
      @style = style.to_sym
      raise ArgumentError, 'Unknown style' unless STYLES[@style]
      @config = chord_to_config(@chord)
    end

    def lines
      (TEMPLATE % @config).split($/)
    end

    private

    def chord_to_config(chord)
      config = DEFAULT_CONFIG.dup
      chord.each_with_index{ |n, i|
        if n == 0
          config[i] = STYLES[@style][:open]
        else
          config[n*4+i] = STYLES[@style][:finger]
        end
      }
      config
    end

    DEFAULT_CONFIG = [
      "  ", "  ", "  ", "  ",
      " │", " │", " │", " │",
      " │", " │", " │", " │",
      " │", " │", " │", " │",
      " │", " │", " │", " │",
      " │", " │", " │", " │",
    ]

    TEMPLATE = <<TEMPLATE

\t%s %s %s %s
\t ╒══╤══╤══╕
\t%s %s %s %s
\t ├──┼──┼──┤
\t%s %s %s %s
\t ├──┼──┼──┤
\t%s %s %s %s
\t ├──┼──┼──┤
\t%s %s %s %s
\t └──┴──┴──┘

TEMPLATE
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
uke-1.0.0 lib/uke/fretboard.rb