bankocr 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +32 -0
- data/bankocr.gemspec +23 -0
- data/bin/bankocr +7 -0
- data/bin/input.in +48 -0
- data/lib/account_number.rb +31 -0
- data/lib/bankocr/version.rb +3 -0
- data/lib/bankocr.rb +14 -0
- data/lib/file_parser.rb +59 -0
- data/lib/report_generator.rb +22 -0
- data/lib/utils.rb +84 -0
- data/spec/bin/bankocr_spec.rb +24 -0
- data/spec/bin/input.in +48 -0
- data/spec/lib/account_number_spec.rb +44 -0
- data/spec/lib/file_parser_spec.rb +28 -0
- data/spec/lib/report_generator_spec.rb +38 -0
- data/spec/lib/user_story_1.in +48 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 51e9f6ed181fb6340334fb1d1aab02b63fef8ba1
|
4
|
+
data.tar.gz: 63b85e8d8dc37b40d8ff16bfde34cf6457276854
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 52eb966fadec59720b6d2474dbffc5be72a784d4cdc701fbe62c45f1df28bc8f7c7336002f2d710b993d309b77d8b7035e1345e79995995792d5cf0644f147b4
|
7
|
+
data.tar.gz: 29b79b21203e50fce61e8c297efac31ae5c87868b03f45138358539c4578a84f7bd2ddb4d356631be1ffb003acc1819bd0c60381cdac25991a78bbe6e10b8f2d
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.5)
|
5
|
+
rspec (3.0.0)
|
6
|
+
rspec-core (~> 3.0.0)
|
7
|
+
rspec-expectations (~> 3.0.0)
|
8
|
+
rspec-mocks (~> 3.0.0)
|
9
|
+
rspec-core (3.0.2)
|
10
|
+
rspec-support (~> 3.0.0)
|
11
|
+
rspec-expectations (3.0.2)
|
12
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
13
|
+
rspec-support (~> 3.0.0)
|
14
|
+
rspec-mocks (3.0.2)
|
15
|
+
rspec-support (~> 3.0.0)
|
16
|
+
rspec-support (3.0.2)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
rspec (~> 3.0.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Javier Cervantes
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# BankOCR Kata
|
2
|
+
|
3
|
+
This repository provides a solution for BankOCR kata.
|
4
|
+
|
5
|
+
[](https://travis-ci.org/solojavier/BankOCR)
|
6
|
+
|
7
|
+
## What is it about?
|
8
|
+
|
9
|
+
* Description of the problem can be found here: http://code.joejag.com/coding-dojo-bank-ocr/
|
10
|
+
* Current implementation covers the first 3 use cases.
|
11
|
+
|
12
|
+
## How to run?
|
13
|
+
|
14
|
+
Use the following commands:
|
15
|
+
|
16
|
+
```
|
17
|
+
gem install backocr
|
18
|
+
bankocr ./bin/input.in ./bin/output
|
19
|
+
```
|
20
|
+
|
21
|
+
* It will generate a file under /bin directory with results
|
22
|
+
* If you want to modify input edit file /bin/input.in
|
23
|
+
|
24
|
+
## Tests
|
25
|
+
|
26
|
+
To run test use the following commands:
|
27
|
+
|
28
|
+
```
|
29
|
+
gem install bundler
|
30
|
+
bundle install
|
31
|
+
bundle exec rspec spec
|
32
|
+
```
|
data/bankocr.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bankocr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "bankocr"
|
8
|
+
spec.version = BankOCR::VERSION
|
9
|
+
spec.authors = ["Javier Cervantes"]
|
10
|
+
spec.email = ["javier@hybridgroup.com"]
|
11
|
+
spec.summary = %q{Solution to BankOCR Kata}
|
12
|
+
spec.description = %q{Solution in ruby of BankOCR Kata: http://code.joejag.com/coding-dojo-bank-ocr/}
|
13
|
+
spec.homepage = "https://github.com/solojavier/bankOCR"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
end
|
data/bin/bankocr
ADDED
data/bin/input.in
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
_
|
2
|
+
| | | | | | | | |
|
3
|
+
| | | | | | | | |
|
4
|
+
|
5
|
+
_ _ _ _ _ _ _ _
|
6
|
+
| | | | | | | | |
|
7
|
+
| | | | | | | | |
|
8
|
+
|
9
|
+
_ _ _ _ _ _ _ _ _
|
10
|
+
_|| || ||_|| || || || || |
|
11
|
+
|_ |_||_||_||_||_||_||_||_|
|
12
|
+
|
13
|
+
_ _ _ _ _ _ _ _ _
|
14
|
+
_| _| _| _||_| _| _| _| _|
|
15
|
+
_| _| _| _| _| _| _| _| _|
|
16
|
+
|
17
|
+
_ _ _ _ _ _ _ _ _
|
18
|
+
|_||_||_||_||_||_||_||_||_|
|
19
|
+
|_||_||_||_||_||_||_||_||_|
|
20
|
+
|
21
|
+
_ _ _ _ _ _ _ _ _
|
22
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
23
|
+
_| _| _| _| _| _| _| _| _|
|
24
|
+
|
25
|
+
_ _ _ _ _ _ _ _ _
|
26
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
27
|
+
|_||_||_||_||_||_||_||_||_|
|
28
|
+
|
29
|
+
_ _ _ _ _ _ _ _ _
|
30
|
+
|_||_||_||_||_||_||_||_||_|
|
31
|
+
_| _| _| _| _| _| _| _| _|
|
32
|
+
|
33
|
+
_ _ _ _ _ _ _
|
34
|
+
|_||_|| || ||_ | | ||_
|
35
|
+
| _||_||_||_| | | | _|
|
36
|
+
|
37
|
+
_ _ _ _ _ _ _
|
38
|
+
| _| _||_||_ |_ ||_||_|
|
39
|
+
||_ _| | _||_| ||_| _|
|
40
|
+
|
41
|
+
_ _ _ _ _ _ _ _
|
42
|
+
| || || || || || || ||_ |
|
43
|
+
|_||_||_||_||_||_||_| _| |
|
44
|
+
|
45
|
+
_ _ _ _ _ _ _
|
46
|
+
|_||_|| ||_||_ | | | _
|
47
|
+
| _||_||_||_| | | | _|
|
48
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module BankOCR
|
2
|
+
class AccountNumber
|
3
|
+
|
4
|
+
attr_reader :error_message, :digits
|
5
|
+
|
6
|
+
def initialize(digits)
|
7
|
+
@digits = digits
|
8
|
+
@valid = false
|
9
|
+
|
10
|
+
validate!
|
11
|
+
end
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
@valid
|
15
|
+
end
|
16
|
+
|
17
|
+
def validate!
|
18
|
+
@error_message = 'ILL' if @digits.include?('?')
|
19
|
+
@error_message ||= 'ERR' if sum(@digits) % 11 != 0
|
20
|
+
|
21
|
+
@valid = true unless @error_message
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def sum(account_number)
|
27
|
+
(0..8).map { |i| account_number[i].to_i * (i + 2) }.reduce(:+)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/bankocr.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bankocr/version"
|
2
|
+
|
3
|
+
module BankOCR
|
4
|
+
autoload :FileParser, 'file_parser'
|
5
|
+
autoload :AccountNumber, 'account_number'
|
6
|
+
autoload :ReportGenerator, 'report_generator'
|
7
|
+
|
8
|
+
def self.process(input, output)
|
9
|
+
digit_strings = BankOCR::FileParser.new(input).entries
|
10
|
+
account_numbers = digit_strings.map { |d| BankOCR::AccountNumber.new(d) }
|
11
|
+
|
12
|
+
BankOCR::ReportGenerator.new(output, account_numbers).save!
|
13
|
+
end
|
14
|
+
end
|
data/lib/file_parser.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module BankOCR
|
2
|
+
class FileParser
|
3
|
+
|
4
|
+
def initialize(input_path)
|
5
|
+
@input_path = input_path
|
6
|
+
end
|
7
|
+
|
8
|
+
def entries
|
9
|
+
@entries || read_entries
|
10
|
+
end
|
11
|
+
|
12
|
+
def read_entries
|
13
|
+
@entries = []
|
14
|
+
file = File.open(@input_path)
|
15
|
+
@entries << parse_entry(file) until file.eof?
|
16
|
+
|
17
|
+
@entries
|
18
|
+
rescue
|
19
|
+
[]
|
20
|
+
ensure
|
21
|
+
file.close if file
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse_entry(file)
|
27
|
+
top = file.readline
|
28
|
+
middle = file.readline
|
29
|
+
bottom = file.readline
|
30
|
+
_blank = file.readline
|
31
|
+
|
32
|
+
entry_to_digits(top, middle, bottom)
|
33
|
+
end
|
34
|
+
|
35
|
+
def entry_to_digits(top, middle, bottom)
|
36
|
+
(0..8).map do |i|
|
37
|
+
low = (i * 3)
|
38
|
+
high = ((i + 1) * 3) - 1
|
39
|
+
shape = top[low..high] + middle[low..high] + bottom[low..high]
|
40
|
+
|
41
|
+
conversions[shape] || '?'
|
42
|
+
end.join
|
43
|
+
end
|
44
|
+
|
45
|
+
def conversions
|
46
|
+
{ ' _ | ||_|' => '0',
|
47
|
+
' | |' => '1',
|
48
|
+
' _ _||_ ' => '2',
|
49
|
+
' _ _| _|' => '3',
|
50
|
+
' |_| |' => '4',
|
51
|
+
' _ |_ _|' => '5',
|
52
|
+
' _ |_ |_|' => '6',
|
53
|
+
' _ | |' => '7',
|
54
|
+
' _ |_||_|' => '8',
|
55
|
+
' _ |_| _|' => '9' }
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module BankOCR
|
2
|
+
class ReportGenerator
|
3
|
+
|
4
|
+
def initialize(output_path, account_numbers)
|
5
|
+
@output_path = output_path
|
6
|
+
@account_numbers = account_numbers
|
7
|
+
end
|
8
|
+
|
9
|
+
def save!
|
10
|
+
file = File.open(@output_path, 'w+')
|
11
|
+
|
12
|
+
@account_numbers.each do |account|
|
13
|
+
file.write account.digits
|
14
|
+
file.write " #{account.error_message}" if !account.valid?
|
15
|
+
file.write "\n"
|
16
|
+
end
|
17
|
+
|
18
|
+
file.close
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
data/lib/utils.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Module for BankOCR Application
|
2
|
+
module BankOCR
|
3
|
+
# Utility functions to perform data conversions
|
4
|
+
module Utils
|
5
|
+
# Parses an OCR machine input file and returns an array of account numbers
|
6
|
+
def parse_file(input_path)
|
7
|
+
file = File.open(input_path)
|
8
|
+
numbers = []
|
9
|
+
|
10
|
+
numbers << next_entry_to_digits(file) until file.eof?
|
11
|
+
numbers
|
12
|
+
rescue
|
13
|
+
[]
|
14
|
+
ensure
|
15
|
+
file.close if file
|
16
|
+
end
|
17
|
+
|
18
|
+
# Receives a list of account numbers and returns validation information
|
19
|
+
def validate_accounts(account_numbers)
|
20
|
+
account_numbers.map do |number|
|
21
|
+
valid, message = validate(number.to_s)
|
22
|
+
|
23
|
+
{ account_number: number, valid: valid, message: message }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Creates a file report in ouput path with accounts received
|
28
|
+
def generate_report(output_path, accounts)
|
29
|
+
file = File.open(output_path, 'w+')
|
30
|
+
|
31
|
+
accounts.select { |a| a[:account_number] }.each do |acc|
|
32
|
+
file.write acc[:account_number]
|
33
|
+
file.write " #{acc[:message]}" if !acc[:valid] && acc[:message]
|
34
|
+
file.write "\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
file.close
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def next_entry_to_digits(file)
|
43
|
+
top = file.readline
|
44
|
+
middle = file.readline
|
45
|
+
bottom = file.readline
|
46
|
+
_blank = file.readline
|
47
|
+
|
48
|
+
(0..8).map do |i|
|
49
|
+
low = (i * 3)
|
50
|
+
high = ((i + 1) * 3) - 1
|
51
|
+
shape = top[low..high] + middle[low..high] + bottom[low..high]
|
52
|
+
|
53
|
+
conversions[shape] || '?'
|
54
|
+
end.join
|
55
|
+
end
|
56
|
+
|
57
|
+
def conversions
|
58
|
+
{ ' _ | ||_|' => '0',
|
59
|
+
' | |' => '1',
|
60
|
+
' _ _||_ ' => '2',
|
61
|
+
' _ _| _|' => '3',
|
62
|
+
' |_| |' => '4',
|
63
|
+
' _ |_ _|' => '5',
|
64
|
+
' _ |_ |_|' => '6',
|
65
|
+
' _ | |' => '7',
|
66
|
+
' _ |_||_|' => '8',
|
67
|
+
' _ |_| _|' => '9' }
|
68
|
+
end
|
69
|
+
|
70
|
+
def sum(account_number)
|
71
|
+
(0..8).map { |i| account_number[i].to_i * (i + 2) }.reduce(:+)
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate(number)
|
75
|
+
if number.include?('?')
|
76
|
+
[false, 'ILL']
|
77
|
+
elsif sum(number) % 11 != 0
|
78
|
+
[false, 'ERR']
|
79
|
+
else
|
80
|
+
[true, 'OK']
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'bankocr'
|
2
|
+
|
3
|
+
describe 'Application execution' do
|
4
|
+
|
5
|
+
let(:input) { File.dirname(__FILE__) + '/input.in' }
|
6
|
+
let(:output) { File.dirname(__FILE__) + '/report.out' }
|
7
|
+
|
8
|
+
let(:report) do
|
9
|
+
"711111111\n777777177\n200800000\n333393333\n888888888 ERR\n" \
|
10
|
+
"555555555 ERR\n666666666 ERR\n999999999 ERR\n490067715 ERR\n" \
|
11
|
+
"123456789\n000000051\n49086771? ILL\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
before do
|
15
|
+
File.delete(output) if File.exists?(output)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'parses file and creates report', integration: true do
|
19
|
+
BankOCR.process(input, output)
|
20
|
+
|
21
|
+
expect(File.open(output).read).to eq(report)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/bin/input.in
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
_
|
2
|
+
| | | | | | | | |
|
3
|
+
| | | | | | | | |
|
4
|
+
|
5
|
+
_ _ _ _ _ _ _ _
|
6
|
+
| | | | | | | | |
|
7
|
+
| | | | | | | | |
|
8
|
+
|
9
|
+
_ _ _ _ _ _ _ _ _
|
10
|
+
_|| || ||_|| || || || || |
|
11
|
+
|_ |_||_||_||_||_||_||_||_|
|
12
|
+
|
13
|
+
_ _ _ _ _ _ _ _ _
|
14
|
+
_| _| _| _||_| _| _| _| _|
|
15
|
+
_| _| _| _| _| _| _| _| _|
|
16
|
+
|
17
|
+
_ _ _ _ _ _ _ _ _
|
18
|
+
|_||_||_||_||_||_||_||_||_|
|
19
|
+
|_||_||_||_||_||_||_||_||_|
|
20
|
+
|
21
|
+
_ _ _ _ _ _ _ _ _
|
22
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
23
|
+
_| _| _| _| _| _| _| _| _|
|
24
|
+
|
25
|
+
_ _ _ _ _ _ _ _ _
|
26
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
27
|
+
|_||_||_||_||_||_||_||_||_|
|
28
|
+
|
29
|
+
_ _ _ _ _ _ _ _ _
|
30
|
+
|_||_||_||_||_||_||_||_||_|
|
31
|
+
_| _| _| _| _| _| _| _| _|
|
32
|
+
|
33
|
+
_ _ _ _ _ _ _
|
34
|
+
|_||_|| || ||_ | | ||_
|
35
|
+
| _||_||_||_| | | | _|
|
36
|
+
|
37
|
+
_ _ _ _ _ _ _
|
38
|
+
| _| _||_||_ |_ ||_||_|
|
39
|
+
||_ _| | _||_| ||_| _|
|
40
|
+
|
41
|
+
_ _ _ _ _ _ _ _
|
42
|
+
| || || || || || || ||_ |
|
43
|
+
|_||_||_||_||_||_||_| _| |
|
44
|
+
|
45
|
+
_ _ _ _ _ _ _
|
46
|
+
|_||_|| ||_||_ | | | _
|
47
|
+
| _||_||_||_| | | | _|
|
48
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'bankocr'
|
2
|
+
|
3
|
+
describe BankOCR::AccountNumber do
|
4
|
+
|
5
|
+
context 'when validating account numbers' do
|
6
|
+
|
7
|
+
let(:valid_numbers) { %w(711111111b 123456789 490867715) }
|
8
|
+
let(:invalid_numbers) { %w(888888888 490067715 012345678) }
|
9
|
+
let(:wrong_numbers) { %w(86110?356) }
|
10
|
+
|
11
|
+
let(:wrong_accounts) do
|
12
|
+
[ { account_number: '86110??36', valid: false, message: 'ILL' } ]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'validates valid account numbers' do
|
16
|
+
valid_numbers.each do |n|
|
17
|
+
account = described_class.new(n)
|
18
|
+
|
19
|
+
expect(account.valid?).to eq(true)
|
20
|
+
expect(account.error_message).to eq(nil)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'validates invalid account numbers' do
|
25
|
+
invalid_numbers.each do |n|
|
26
|
+
account = described_class.new(n)
|
27
|
+
|
28
|
+
expect(account.valid?).to eq(false)
|
29
|
+
expect(account.error_message).to eq('ERR')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'validates wrong account numbers' do
|
34
|
+
wrong_numbers.each do |n|
|
35
|
+
account = described_class.new(n)
|
36
|
+
|
37
|
+
expect(account.valid?).to eq(false)
|
38
|
+
expect(account.error_message).to eq('ILL')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bankocr'
|
2
|
+
|
3
|
+
describe BankOCR::FileParser do
|
4
|
+
|
5
|
+
let(:input_path) { File.dirname(__FILE__) + '/user_story_1.in' }
|
6
|
+
|
7
|
+
context 'when parsing a file' do
|
8
|
+
|
9
|
+
let(:account_numbers) do
|
10
|
+
%w(000000000 111111111 222222222 333333333 444444444 555555555 666666666
|
11
|
+
777777777 888888888 999999999 123456789 12345678?)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns an array with account numbers' do
|
15
|
+
parser = described_class.new(input_path)
|
16
|
+
|
17
|
+
expect(parser.entries).to eq(account_numbers)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns empty account_numbers if error reading file' do
|
21
|
+
parser = described_class.new('invalid_path')
|
22
|
+
|
23
|
+
expect(parser.entries).to eq([])
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'bankocr'
|
2
|
+
|
3
|
+
describe BankOCR::ReportGenerator do
|
4
|
+
|
5
|
+
let(:accounts) do
|
6
|
+
[
|
7
|
+
BankOCR::AccountNumber.new('457508000'),
|
8
|
+
BankOCR::AccountNumber.new('664371495'),
|
9
|
+
BankOCR::AccountNumber.new('86110??36')
|
10
|
+
]
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:expected_content) do
|
14
|
+
"457508000\n664371495 ERR\n86110??36 ILL\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:output_path) { File.dirname(__FILE__) + '/user_story_3.out' }
|
18
|
+
|
19
|
+
let(:generated_content) do
|
20
|
+
File.open(output_path).read
|
21
|
+
end
|
22
|
+
|
23
|
+
before do
|
24
|
+
File.delete(output_path) if File.exists?(output_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'creates empty file if accounts are not sent' do
|
28
|
+
described_class.new(output_path, []).save!
|
29
|
+
|
30
|
+
expect(generated_content).to eq('')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'creates expected content' do
|
34
|
+
described_class.new(output_path, accounts).save!
|
35
|
+
|
36
|
+
expect(generated_content).to eq(expected_content)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
_ _ _ _ _ _ _ _ _
|
2
|
+
| || || || || || || || || |
|
3
|
+
|_||_||_||_||_||_||_||_||_|
|
4
|
+
|
5
|
+
|
6
|
+
| | | | | | | | |
|
7
|
+
| | | | | | | | |
|
8
|
+
|
9
|
+
_ _ _ _ _ _ _ _ _
|
10
|
+
_| _| _| _| _| _| _| _| _|
|
11
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
12
|
+
|
13
|
+
_ _ _ _ _ _ _ _ _
|
14
|
+
_| _| _| _| _| _| _| _| _|
|
15
|
+
_| _| _| _| _| _| _| _| _|
|
16
|
+
|
17
|
+
|
18
|
+
|_||_||_||_||_||_||_||_||_|
|
19
|
+
| | | | | | | | |
|
20
|
+
|
21
|
+
_ _ _ _ _ _ _ _ _
|
22
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
23
|
+
_| _| _| _| _| _| _| _| _|
|
24
|
+
|
25
|
+
_ _ _ _ _ _ _ _ _
|
26
|
+
|_ |_ |_ |_ |_ |_ |_ |_ |_
|
27
|
+
|_||_||_||_||_||_||_||_||_|
|
28
|
+
|
29
|
+
_ _ _ _ _ _ _ _ _
|
30
|
+
| | | | | | | | |
|
31
|
+
| | | | | | | | |
|
32
|
+
|
33
|
+
_ _ _ _ _ _ _ _ _
|
34
|
+
|_||_||_||_||_||_||_||_||_|
|
35
|
+
|_||_||_||_||_||_||_||_||_|
|
36
|
+
|
37
|
+
_ _ _ _ _ _ _ _ _
|
38
|
+
|_||_||_||_||_||_||_||_||_|
|
39
|
+
_| _| _| _| _| _| _| _| _|
|
40
|
+
|
41
|
+
_ _ _ _ _ _ _
|
42
|
+
| _| _||_||_ |_ ||_||_|
|
43
|
+
||_ _| | _||_| ||_| _|
|
44
|
+
|
45
|
+
_ _ _ _ _ _ _
|
46
|
+
| _| _||_||_ |_ ||_|| |
|
47
|
+
||_ _| | _||_| ||_| _|
|
48
|
+
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bankocr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Cervantes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
description: 'Solution in ruby of BankOCR Kata: http://code.joejag.com/coding-dojo-bank-ocr/'
|
42
|
+
email:
|
43
|
+
- javier@hybridgroup.com
|
44
|
+
executables:
|
45
|
+
- bankocr
|
46
|
+
- input.in
|
47
|
+
extensions: []
|
48
|
+
extra_rdoc_files: []
|
49
|
+
files:
|
50
|
+
- ".gitignore"
|
51
|
+
- ".travis.yml"
|
52
|
+
- Gemfile
|
53
|
+
- Gemfile.lock
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- bankocr.gemspec
|
57
|
+
- bin/bankocr
|
58
|
+
- bin/input.in
|
59
|
+
- lib/account_number.rb
|
60
|
+
- lib/bankocr.rb
|
61
|
+
- lib/bankocr/version.rb
|
62
|
+
- lib/file_parser.rb
|
63
|
+
- lib/report_generator.rb
|
64
|
+
- lib/utils.rb
|
65
|
+
- spec/bin/bankocr_spec.rb
|
66
|
+
- spec/bin/input.in
|
67
|
+
- spec/lib/account_number_spec.rb
|
68
|
+
- spec/lib/file_parser_spec.rb
|
69
|
+
- spec/lib/report_generator_spec.rb
|
70
|
+
- spec/lib/user_story_1.in
|
71
|
+
homepage: https://github.com/solojavier/bankOCR
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 2.2.2
|
92
|
+
signing_key:
|
93
|
+
specification_version: 4
|
94
|
+
summary: Solution to BankOCR Kata
|
95
|
+
test_files:
|
96
|
+
- spec/bin/bankocr_spec.rb
|
97
|
+
- spec/bin/input.in
|
98
|
+
- spec/lib/account_number_spec.rb
|
99
|
+
- spec/lib/file_parser_spec.rb
|
100
|
+
- spec/lib/report_generator_spec.rb
|
101
|
+
- spec/lib/user_story_1.in
|
102
|
+
has_rdoc:
|