bankocr 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/bankocr +1 -2
- data/lib/account_number.rb +2 -2
- data/lib/bankocr/version.rb +1 -1
- data/lib/bankocr.rb +1 -0
- data/lib/digit.rb +43 -0
- data/lib/file_parser.rb +8 -21
- data/lib/report_generator.rb +0 -1
- data/spec/lib/account_number_spec.rb +9 -11
- data/spec/lib/report_generator_spec.rb +3 -3
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26e0d3a1fb2759af164b58e10b12692ba0d7b178
|
4
|
+
data.tar.gz: 85168f078496ca138a3b6392112a91de7192bd74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5aa4456636276c3ddc3472c9e7818058cba091956b3ac9837a621e6b49100588fa76a6722d77d98ebeb13e05abac67462b860c5f7f23384d937501edbe529783
|
7
|
+
data.tar.gz: f1256f6172a86841528e25f2b197cf85794843e750725e30877141c372ad3e20625d3840c30587c5bad39c1ab97f64650b2006363a560863ab9587a728ac022f
|
data/Gemfile.lock
CHANGED
data/bin/bankocr
CHANGED
@@ -5,8 +5,7 @@ require 'bankocr'
|
|
5
5
|
|
6
6
|
module BankOCR
|
7
7
|
class ProcessCommand < Thor
|
8
|
-
desc 'process input_path output_path',
|
9
|
-
'Generates a report for account numbers read from input'
|
8
|
+
desc 'process input_path output_path', 'Create report for account numbers'
|
10
9
|
|
11
10
|
def process(input, output)
|
12
11
|
BankOCR.process(input, output)
|
data/lib/account_number.rb
CHANGED
data/lib/bankocr/version.rb
CHANGED
data/lib/bankocr.rb
CHANGED
@@ -6,6 +6,7 @@ module BankOCR
|
|
6
6
|
autoload :FileParser, 'file_parser'
|
7
7
|
autoload :AccountNumber, 'account_number'
|
8
8
|
autoload :ReportGenerator, 'report_generator'
|
9
|
+
autoload :Digit, 'digit'
|
9
10
|
|
10
11
|
def self.process(input, output)
|
11
12
|
account_numbers = BankOCR::FileParser.new(input).entries
|
data/lib/digit.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module BankOCR
|
2
|
+
class Digit
|
3
|
+
attr_reader :value, :shape
|
4
|
+
|
5
|
+
def initialize(shape)
|
6
|
+
@shape = shape
|
7
|
+
@value = CONVERSIONS[shape] || '?'
|
8
|
+
end
|
9
|
+
|
10
|
+
CONVERSIONS = {
|
11
|
+
' _ ' /
|
12
|
+
'| |' /
|
13
|
+
'|_|' => '0',
|
14
|
+
' ' /
|
15
|
+
' |' /
|
16
|
+
' |' => '1',
|
17
|
+
' _ ' /
|
18
|
+
' _|' /
|
19
|
+
'|_ ' => '2',
|
20
|
+
' _ ' /
|
21
|
+
' _|' /
|
22
|
+
' _|' => '3',
|
23
|
+
' ' /
|
24
|
+
'|_|' /
|
25
|
+
' |' => '4',
|
26
|
+
' _ ' /
|
27
|
+
'|_ ' /
|
28
|
+
' _|' => '5',
|
29
|
+
' _ ' /
|
30
|
+
'|_ ' /
|
31
|
+
'|_|' => '6',
|
32
|
+
' _ ' /
|
33
|
+
' |' /
|
34
|
+
' |' => '7',
|
35
|
+
' _ ' /
|
36
|
+
'|_|' /
|
37
|
+
'|_|' => '8',
|
38
|
+
' _ ' /
|
39
|
+
'|_|' /
|
40
|
+
' _|' => '9'
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
data/lib/file_parser.rb
CHANGED
@@ -6,15 +6,15 @@ module BankOCR
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def entries
|
9
|
-
@
|
9
|
+
@digits || read_entries
|
10
10
|
end
|
11
11
|
|
12
12
|
def read_entries
|
13
|
-
@
|
13
|
+
@digits = []
|
14
14
|
file = File.open(@input_path)
|
15
|
-
@
|
15
|
+
@digits << parse_entry(file) until file.eof?
|
16
16
|
|
17
|
-
@
|
17
|
+
@digits.map { |d| BankOCR::AccountNumber.new(d) }
|
18
18
|
rescue
|
19
19
|
p 'Error reading input file, please validate'
|
20
20
|
[]
|
@@ -30,30 +30,17 @@ module BankOCR
|
|
30
30
|
bottom = file.readline
|
31
31
|
_blank = file.readline
|
32
32
|
|
33
|
-
|
33
|
+
build_digit(top, middle, bottom)
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def build_digit(top, middle, bottom)
|
37
37
|
(0..8).map do |i|
|
38
38
|
low = (i * 3)
|
39
39
|
high = ((i + 1) * 3) - 1
|
40
40
|
shape = top[low..high] + middle[low..high] + bottom[low..high]
|
41
41
|
|
42
|
-
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def conversions
|
47
|
-
{ ' _ | ||_|' => '0',
|
48
|
-
' | |' => '1',
|
49
|
-
' _ _||_ ' => '2',
|
50
|
-
' _ _| _|' => '3',
|
51
|
-
' |_| |' => '4',
|
52
|
-
' _ |_ _|' => '5',
|
53
|
-
' _ |_ |_|' => '6',
|
54
|
-
' _ | |' => '7',
|
55
|
-
' _ |_||_|' => '8',
|
56
|
-
' _ |_| _|' => '9' }
|
42
|
+
BankOCR::Digit.new(shape)
|
43
|
+
end
|
57
44
|
end
|
58
45
|
end
|
59
46
|
end
|
data/lib/report_generator.rb
CHANGED
@@ -2,15 +2,21 @@ require 'bankocr'
|
|
2
2
|
|
3
3
|
describe BankOCR::AccountNumber do
|
4
4
|
|
5
|
+
def digits(string)
|
6
|
+
string.split('').map do |c|
|
7
|
+
shape = BankOCR::Digit::CONVERSIONS.keys[c.to_i]
|
8
|
+
BankOCR::Digit.new(shape)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
5
12
|
context 'when validating account numbers' do
|
6
13
|
|
7
14
|
let(:valid_numbers) { %w(711111111b 123456789 490867715) }
|
8
15
|
let(:invalid_numbers) { %w(888888888 490067715 012345678) }
|
9
|
-
let(:wrong_numbers) { %w(86110?356) }
|
10
16
|
|
11
17
|
it 'validates valid account numbers' do
|
12
18
|
valid_numbers.each do |n|
|
13
|
-
account = described_class.new(n)
|
19
|
+
account = described_class.new(digits(n))
|
14
20
|
|
15
21
|
expect(account.valid?).to eq(true)
|
16
22
|
end
|
@@ -18,15 +24,7 @@ describe BankOCR::AccountNumber do
|
|
18
24
|
|
19
25
|
it 'validates invalid account numbers' do
|
20
26
|
invalid_numbers.each do |n|
|
21
|
-
account = described_class.new(n)
|
22
|
-
|
23
|
-
expect(account.valid?).to eq(false)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'validates wrong account numbers' do
|
28
|
-
wrong_numbers.each do |n|
|
29
|
-
account = described_class.new(n)
|
27
|
+
account = described_class.new(digits(n))
|
30
28
|
|
31
29
|
expect(account.valid?).to eq(false)
|
32
30
|
end
|
@@ -4,9 +4,9 @@ describe BankOCR::ReportGenerator do
|
|
4
4
|
|
5
5
|
let(:accounts) do
|
6
6
|
[
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
double('account', :to_s => '457508000', :valid? => true),
|
8
|
+
double('account', :to_s => '664371495', :valid? => false),
|
9
|
+
double('account', :to_s => '86110??36', :valid? => false)
|
10
10
|
]
|
11
11
|
end
|
12
12
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bankocr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Javier Cervantes
|
@@ -72,6 +72,7 @@ files:
|
|
72
72
|
- lib/account_number.rb
|
73
73
|
- lib/bankocr.rb
|
74
74
|
- lib/bankocr/version.rb
|
75
|
+
- lib/digit.rb
|
75
76
|
- lib/file_parser.rb
|
76
77
|
- lib/report_generator.rb
|
77
78
|
- spec/bin/bankocr_spec.rb
|