Class: BinDot2BrailleGraph

Inherits:
Object
  • Object
show all
Defined in:
lib/bindot2braillegraph.rb,
lib/bindot2braillegraph/version.rb

Constant Summary collapse

LEFT_SHIFT_TABLE =
{
  0b00000001 => 7,
  0b00000010 => 4,
  0b00000100 => 1,
  0b00001000 => 3,
  0b00010000 => 0,
  0b00100000 => -3,
  0b01000000 => -5,
  0b10000000 => -7
}
VERSION =
"0.0.4"
@@num_to_braille_graph =
{}

Class Method Summary collapse

Class Method Details

.convert(width, height, binary) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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