class BankOCR::FileParser
Reads a file from OCR and converts to digits
Public Class Methods
new(input_path)
click to toggle source
# File lib/file_parser.rb, line 4 def initialize(input_path) @input_path = input_path end
Public Instance Methods
entries()
click to toggle source
# File lib/file_parser.rb, line 8 def entries @digits || read_entries end
read_entries()
click to toggle source
# File lib/file_parser.rb, line 12 def read_entries @digits = [] file = File.open(@input_path) @digits << parse_entry(file) until file.eof? @digits.map { |d| BankOCR::AccountNumber.new(d) } rescue p 'Error reading input file, please validate' [] ensure file.close if file end
Private Instance Methods
build_digit(top, middle, bottom)
click to toggle source
# File lib/file_parser.rb, line 36 def build_digit(top, middle, bottom) (0..8).map do |i| low = (i * 3) high = ((i + 1) * 3) - 1 shape = top[low..high] + middle[low..high] + bottom[low..high] BankOCR::Digit.new(shape) end end
parse_entry(file)
click to toggle source
# File lib/file_parser.rb, line 27 def parse_entry(file) top = file.readline middle = file.readline bottom = file.readline _blank = file.readline build_digit(top, middle, bottom) end