Skip to content

Instantly share code, notes, and snippets.

@nathanows
Created October 20, 2015 15:06
Show Gist options
  • Save nathanows/51236ceaf31e4ea63894 to your computer and use it in GitHub Desktop.
Save nathanows/51236ceaf31e4ea63894 to your computer and use it in GitHub Desktop.
Braille Letters
require 'pry'
class FileReader
def self.input_filename
ARGV[0]
end
def read
filename = FileReader.input_filename
File.read(filename)
end
end
class NightWriter
attr_reader :reader, :string
def initialize
@reader = FileReader.new
@string = reader.read
end
ALPHABET_TO_BRAILLE = {
"a" => ["0.", "..", ".."],
"b" => ["0.", "0.", ".."],
"c" => ["00", "..", ".."],
"d" => ["00", ".0", ".."],
"e" => ["0.", ".0", ".."],
"f" => ["00", "0.", ".."],
"g" => ["00", "00", ".."],
"h" => ["0.", "00", ".."],
"i" => [".0", "0.", ".."],
"j" => [".0", "00", ".."],
"k" => ["0.", "..", "0."],
"l" => ["0.", "0.", "0."],
"m" => ["00", "..", "0."],
"n" => ["00", ".0", "0."],
"o" => ["0.", ".0", "0."],
"p" => ["00", "0.", "0."],
"q" => ["00", "00", "0."],
"r" => ["0.", "00", "0."],
"s" => [".0", "0.", "0."],
"t" => [".0", "00", "0."],
"u" => ["0.", "..", "00"],
"v" => ["0.", "0.", "00"],
"w" => [".0", "00", ".0"],
"x" => ["00", "..", "00"],
"y" => ["00", ".0", "00"],
"z" => ["0.", ".0", "00"]
}
BRAILLE_TO_ALPHABET = ALPHABET_TO_BRAILLE.invert
end
require './braille_letters'
require 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
class NightWriterTest < Minitest::Test
def setup
@file = File.new("tempfile.txt", "w")
@file.print("TEST TEST TEST")
@file.close
end
def teardown
File.delete("tempfile.txt")
end
def test_it_can_read_file
FileReader.stub(:input_filename, -> { @file }) do
night = NightWriter.new
assert_equal "TEST TEST TEST", night.string
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment