Permalink
Browse files

Broke account out to it's own file

  • Loading branch information...
1 parent aaa9b76 commit 344fcf308d5633e79c56a445a66646c5156c17ab @guyroyse committed Feb 25, 2012
Showing with 74 additions and 70 deletions.
  1. +27 −0 lib/account.rb
  2. +46 −43 lib/digit.rb
  3. +1 −27 lib/ocr.rb
View
@@ -0,0 +1,27 @@
+require 'digit'
+
+ACCOUNT_NUMBER_LENGTH = 9
+LINE_LENGTH = DIGIT_WIDTH * ACCOUNT_NUMBER_LENGTH + 1
+
+class Account
+ def initialize text
+ @text = text
+ end
+ def number
+ (0...ACCOUNT_NUMBER_LENGTH).reduce '' do |account_number, digit_position|
+ digit_text = extract_digit_text digit_position
+ account_number << Digit.new(digit_text).value
+ end
+ end
+ def extract_digit_text digit_position
+ (0...DIGIT_HEIGHT).reduce '' do |digit, line|
+ offset = calculate_offset line, digit_position
+ digit << @text[offset, DIGIT_WIDTH]
+ end
+ end
+ def calculate_offset line, digit_position
+ line_offset = line * LINE_LENGTH
+ digit_offset = digit_position * DIGIT_WIDTH
+ offset = line_offset + digit_offset
+ end
+end
View
@@ -1,57 +1,60 @@
-class Digit
+DIGIT_WIDTH = 3
+DIGIT_HEIGHT = 3
+
+ZERO = ' _ ' +
+ '| |' +
+ '|_|'
- ZERO = ' _ ' +
- '| |' +
- '|_|'
+ONE = ' ' +
+ ' |' +
+ ' |'
- ONE = ' ' +
- ' |' +
- ' |'
+TWO = ' _ ' +
+ ' _|' +
+ '|_ '
- TWO = ' _ ' +
- ' _|' +
- '|_ '
+THREE = ' _ ' +
+ ' _|' +
+ ' _|'
- THREE = ' _ ' +
- ' _|' +
- ' _|'
+FOUR = ' ' +
+ '|_|' +
+ ' |'
- FOUR = ' ' +
- '|_|' +
- ' |'
+FIVE = ' _ ' +
+ '|_ ' +
+ ' _|'
- FIVE = ' _ ' +
- '|_ ' +
- ' _|'
+SIX = ' _ ' +
+ '|_ ' +
+ '|_|'
- SIX = ' _ ' +
- '|_ ' +
- '|_|'
+SEVEN = ' _ ' +
+ ' |' +
+ ' |'
- SEVEN = ' _ ' +
- ' |' +
- ' |'
+EIGHT = ' _ ' +
+ '|_|' +
+ '|_|'
- EIGHT = ' _ ' +
- '|_|' +
- '|_|'
+NINE = ' _ ' +
+ '|_|' +
+ ' _|'
- NINE = ' _ ' +
- '|_|' +
- ' _|'
+DIGITS = {
+ ZERO => '0',
+ ONE => '1',
+ TWO => '2',
+ THREE => '3',
+ FOUR => '4',
+ FIVE => '5',
+ SIX => '6',
+ SEVEN => '7',
+ EIGHT => '8',
+ NINE => '9'
+}
- DIGITS = {
- ZERO => '0',
- ONE => '1',
- TWO => '2',
- THREE => '3',
- FOUR => '4',
- FIVE => '5',
- SIX => '6',
- SEVEN => '7',
- EIGHT => '8',
- NINE => '9'
- }
+class Digit
attr_reader :value
View
@@ -1,9 +1,5 @@
-require 'digit'
+require 'account'
-DIGIT_WIDTH = 3
-DIGIT_HEIGHT = 3
-ACCOUNT_NUMBER_LENGTH = 9
-LINE_LENGTH = DIGIT_WIDTH * ACCOUNT_NUMBER_LENGTH + 1
ACCOUNT_LENGTH = LINE_LENGTH * 4
class Ocr
@@ -33,25 +29,3 @@ def extract_account_text acct_position
end
end
-class Account
- def initialize text
- @text = text
- end
- def number
- (0...ACCOUNT_NUMBER_LENGTH).reduce '' do |account_number, digit_position|
- digit_text = extract_digit_text digit_position
- account_number << Digit.new(digit_text).value
- end
- end
- def extract_digit_text digit_position
- (0...DIGIT_HEIGHT).reduce '' do |digit, line|
- offset = calculate_offset line, digit_position
- digit << @text[offset, DIGIT_WIDTH]
- end
- end
- def calculate_offset line, digit_position
- line_offset = line * LINE_LENGTH
- digit_offset = digit_position * DIGIT_WIDTH
- offset = line_offset + digit_offset
- end
-end

0 comments on commit 344fcf3

Please sign in to comment.