class BinDot2BrailleGraph

Constants

LEFT_SHIFT_TABLE
VERSION

Public Class Methods

convert(width, height, binary) click to toggle source
# File lib/bindot2braillegraph.rb, line 26
def self.convert(width, height, binary)
  if width % 2 != 0 || height % 4 != 0
    nil
  else
    table = []
    vertical_char_num = height / 4
    horizontal_char_num = width / 2
    (0..(vertical_char_num - 1)).each do |v_pos|
      row = []
      (0..(horizontal_char_num - 1)).each do |h_pos|
        braille_binary =
          binary.slice((v_pos * 4    ) * width + h_pos * 2, 2) +
          binary.slice((v_pos * 4 + 1) * width + h_pos * 2, 2) +
          binary.slice((v_pos * 4 + 2) * width + h_pos * 2, 2) +
          binary.slice((v_pos * 4 + 3) * width + h_pos * 2, 2)
        row << @@num_to_braille_graph[braille_binary.to_i(2)]
      end
      table << row
    end
    table
  end
end