class Coltrane::Renderers::TextRenderer::RepresentationGuitarChordDrawer

Public Instance Methods

alt(str) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 71
def alt(str)
  Paint[str, '#2DD380']
end
base_color(str) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 63
def base_color(str)
  Paint[str, '#6A4AC2']
end
border(x, y) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 39
def border(x, y)
  edge = [guitar.tuning.size * 2 - 2, chord_height + 1]
  x_on_start  = x == 0
  y_on_start  = y == 0
  x_on_edge   = x == edge[0]
  y_on_edge   = y == edge[1]
  x_on_middle = (0...edge[0]).cover?(x)
  y_on_middle = (0...edge[1]).cover?(y)

  if    x_on_start  && y_on_start  then '┍'
  elsif x_on_middle && y_on_start  then x.odd? ? '━' : '┯'
  elsif x_on_edge   && y_on_start  then '┑'
  elsif x_on_start  && y_on_middle then '┝'
  elsif x_on_middle && y_on_middle then x.odd? ? '━' : '┿'
  elsif x_on_edge   && y_on_middle then '┥'
  elsif x_on_start  && y_on_edge   then '┕'
  elsif x_on_middle && y_on_edge   then x.odd? ? '━' : '┷'
  elsif x_on_edge   && y_on_edge   then '┙'
  else ' '
  end
  # puts edge.inspect
  # "#{x},#{y} "
end
chord_height() click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 9
def chord_height
  chord.max_fret_span
end
guitar() click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 13
def guitar
  chord.guitar
end
highlight(str) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 67
def highlight(str)
  Paint[str, '#E67831']
end
render() click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 17
def render
  render_top(chord) +
    (chord.lowest_fret..chord.lowest_fret + chord_height)
    .each_with_index.reduce('') do |memo1, (f, y)|
        memo1 +
          '   ' +
          (chord.guitar.strings.size * 2).times.map { |x| base_color border(x, y) }.join('') +
          "\n" +
          chord.guitar.strings.reduce(base_color(f.to_s.ljust(2, ' '))) do |memo2, s|
            memo2 +
              ' ' +
            render_note(chord.guitar_notes.select do |n|
              n.string == s && n.fret == f
            end.any?)
          end +
          " \n"
    end + '   ' +
    (chord.guitar.strings.size * 2).times.map do |x|
      base_color border(x, chord_height + 1)
    end.join('')
end
render_note(found) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 89
def render_note(found)
  found ? highlight('•') : base_color('│')
end
render_top(chord) click to toggle source
# File lib/coltrane/renderers/text_renderer/representation_guitar_chord_drawer.rb, line 75
def render_top(chord)
  chord.guitar.strings.reduce('   ') do |memo, s|
    memo +
      if chord.guitar_notes.select do |n|
        n.string == s && n.fret == 0 end.any?
        highlight '• '
      elsif chord.guitar_notes.select { |n| n.string == s && n.fret.nil? }.any?
        alt 'x '
      else
        '  '
      end
  end + "\n"
end