Sha256: 13ae32198b6188decc6ef47b6a8a669ab2d839967654380e2825e74e8bf7b561

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

#!/usr/bin/env ruby
# vim: set filetype=ruby:
$: << File.expand_path("../../lib/", __FILE__)

require 'yaml'
require 'readline'
require 'bindot2braillegraph'

FONT_TABLE = YAML.load(
  open(File.expand_path('../../fontdata/misaki.yml', __FILE__)).read +
  open(File.expand_path('../../fontdata/kanji.yml', __FILE__)).read)

def convert_text(input)
  input.split(//).reject { |c|
    FONT_TABLE[c].nil?
  }
  .map { |c|
    bindot = FONT_TABLE[c].split("\n")
    {
      width: bindot[0].size,
      height: bindot.size,
      bindot: bindot.join
    }
  }
  .map { |data|
    BinDot2BrailleGraph.convert(data[:width], data[:height], data[:bindot])
  }
  .each { |c|
    print c[0].join
  }
  .tap { puts }
  .each { |c|
    print c[1].join
  }
  .tap { puts }
end

def interactive
  begin
    while input = Readline.readline('YAPPY> ')
      case input
      when 'quit', 'exit'
        break
      else
        convert_text(input)
      end
    end
  rescue Interrupt
    puts "^C"
    retry
  end
end

if File.pipe?(STDIN) || File.select([STDIN], [], [], 0) != nil then
  STDIN.each_line do |line|
    convert_text(line)
  end
else
  interactive
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bindot2braillegraph-0.0.4 exe/text2braillegraph