Skip to content

Instantly share code, notes, and snippets.

@esebastian
Created January 11, 2016 21:12
Show Gist options
  • Save esebastian/0c614efacf8f9d3b77f5 to your computer and use it in GitHub Desktop.
Save esebastian/0c614efacf8f9d3b77f5 to your computer and use it in GitHub Desktop.
WIP - Katayuno - Bank OCR
class OCR
OCR_MAP = {
" _ | ||_|" => 0,
" | |" => 1,
" _ _||_ " => 2,
" _ _| _|" => 3,
" |_| |" => 4,
" _ |_ _|" => 5,
" _ |_ |_|" => 6,
" _ | |" => 7,
" _ |_||_|" => 8,
" _ |_| _|" => 9
}
def self.do number_representation
OCR_MAP[number_representation]
end
end
require_relative '../ocr'
describe "OCR" do
it "recognizes a 0" do
zero = " _ " +
"| |" +
"|_|"
# " _ | ||_|"
number = OCR.do(zero)
expect(number).to be(0)
end
it "recognizes a 1" do
one = " " +
" |" +
" |"
# " | |"
number = OCR.do(one)
expect(number).to be(1)
end
it "recognizes a 2" do
two = " _ " +
" _|" +
"|_ "
# " _ _||_ "
number = OCR.do(two)
expect(number).to be(2)
end
it "recognizes a 3" do
three = " _ " +
" _|" +
" _|"
# " _ _| _|"
number = OCR.do(three)
expect(number).to be(3)
end
it "recognizes a 4" do
four = " " +
"|_|" +
" |"
# " |_| |"
number = OCR.do(four)
expect(number).to be(4)
end
it "recognizes a 5" do
five = " _ " +
"|_ " +
" _|"
# " _ |_ _|"
number = OCR.do(five)
expect(number).to be(5)
end
it "recognizes a 6" do
six = " _ " +
"|_ " +
"|_|"
# " _ |_ |_|"
number = OCR.do(six)
expect(number).to be(6)
end
it "recognizes a 7" do
seven = " _ " +
" |" +
" |"
# " _ | |"
number = OCR.do(seven)
expect(number).to be(7)
end
it "recognizes a 8" do
eight = " _ " +
"|_|" +
"|_|"
# " _ |_||_|"
number = OCR.do(eight)
expect(number).to be(8)
end
it "recognizes a 9" do
nine = " _ " +
"|_|" +
" _|"
# " _ |_| _|"
number = OCR.do(nine)
expect(number).to be(9)
end
end
# _ _ _ _ _ _ _
# | _| _||_||_ |_ ||_||_|
# ||_ _| | _||_| ||_| _|
#
class Parser
def self.parse entry
""
end
end
require_relative '../parser'
describe "Parser" do
it "extracts individual digits from account number string" do
account_number = " _ _ _ _ _ _ _ " +
" | _| _||_||_ |_ ||_||_|" +
" ||_ _| | _||_| ||_| _|"
parsed_account = Parser.parse(account_number)
number_of_digits = parsed_account.size
expect(number_of_digits).to be(9)
end
end
# _ _ _ _ _ _ _
# | _| _||_||_ |_ ||_||_|
# ||_ _| | _||_| ||_| _|
#
.
├── ocr.rb
├── parser.rb
└── spec
├── ocr_spec.rb
├── parser_spec.rb
└── spec_helper.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment