class Pokeberu::Converter

Constants

HELP_COL_WIDTH
H_BORDER
TABLE
V_BORDER

Public Instance Methods

help() click to toggle source
# File lib/pokeberu/converter.rb, line 33
def help
  tr = []
  TABLE.each.with_index(1) do |row, i|
    tr << draw_full_border
    tr << draw_char_cols(row)
    tr << draw_num_cols(i)
  end
  tr << draw_full_border
  tr.map(&method(:format_row)).join("\n")
end
to_chars(input) click to toggle source
# File lib/pokeberu/converter.rb, line 19
def to_chars(input)
  to_c = -> ((row, col)) { TABLE[row][col] }

  input
    .each_char
    .map(&:to_i)
    .map(&:pred)
    .each_slice(2)
    .map(&to_c)
    .join
    .katakana
    .zen_to_han
end

Private Instance Methods

draw_char_cols(row) click to toggle source
# File lib/pokeberu/converter.rb, line 46
def draw_char_cols(row)
  row.map(&method(:format_char)).join(V_BORDER)
end
draw_full_border() click to toggle source
# File lib/pokeberu/converter.rb, line 66
def draw_full_border
  col_count = TABLE[0].size
  H_BORDER * (HELP_COL_WIDTH * col_count + col_count - 1)
end
draw_num_cols(i) click to toggle source
# File lib/pokeberu/converter.rb, line 54
def draw_num_cols(i)
  i = 0 if i > 9
  from = i * 10
  to = from + 9
  nums = (from..to).map(&method(:format_num))
  nums.rotate(1).join(V_BORDER)
end
format_char(c) click to toggle source
# File lib/pokeberu/converter.rb, line 50
def format_char(c)
  c.katakana.center(HELP_COL_WIDTH - 1)
end
format_num(n) click to toggle source
# File lib/pokeberu/converter.rb, line 62
def format_num(n)
  n.to_s.rjust(2, '0').center(HELP_COL_WIDTH)
end
format_row(text) click to toggle source
# File lib/pokeberu/converter.rb, line 71
def format_row(text)
  [V_BORDER, text, V_BORDER].join
end