bankocr 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c718e8a72b9c3926e904bd07c21637270d96ccc
4
- data.tar.gz: 78622c054b4183e0f6b022aedd5cdf492dd2b8e3
3
+ metadata.gz: 26e0d3a1fb2759af164b58e10b12692ba0d7b178
4
+ data.tar.gz: 85168f078496ca138a3b6392112a91de7192bd74
5
5
  SHA512:
6
- metadata.gz: 0fd91b34998b1be1886fff104925b24ebcbe871848ad35f069da570d6f075def69336f6b96f412983f7d236b03c0f54fd9d00ae82778db30aa04fd9ce061fb4c
7
- data.tar.gz: 77f43c26adb1c807c338d56ba8b38779e6bcb54a9657100394b9ab86ce373c093bf662bac25604f5e3bbfa6f41ff409264d6132515d45ba2006b6627f7bcb06e
6
+ metadata.gz: 5aa4456636276c3ddc3472c9e7818058cba091956b3ac9837a621e6b49100588fa76a6722d77d98ebeb13e05abac67462b860c5f7f23384d937501edbe529783
7
+ data.tar.gz: f1256f6172a86841528e25f2b197cf85794843e750725e30877141c372ad3e20625d3840c30587c5bad39c1ab97f64650b2006363a560863ab9587a728ac022f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bankocr (0.0.4)
4
+ bankocr (0.0.5)
5
5
  thor (~> 0.19)
6
6
 
7
7
  GEM
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)
@@ -7,11 +7,11 @@ module BankOCR
7
7
  end
8
8
 
9
9
  def valid?
10
- @valid ||= sum(@digits) % 11 == 0
10
+ @valid ||= sum(to_s) % 11 == 0
11
11
  end
12
12
 
13
13
  def to_s
14
- @digits
14
+ @digits.map(&:value).join
15
15
  end
16
16
 
17
17
  private
@@ -1,3 +1,3 @@
1
1
  module BankOCR
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
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
- @entries || read_entries
9
+ @digits || read_entries
10
10
  end
11
11
 
12
12
  def read_entries
13
- @entries = []
13
+ @digits = []
14
14
  file = File.open(@input_path)
15
- @entries << parse_entry(file) until file.eof?
15
+ @digits << parse_entry(file) until file.eof?
16
16
 
17
- @entries.map{|e| BankOCR::AccountNumber.new(e) }
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
- entry_to_digits(top, middle, bottom)
33
+ build_digit(top, middle, bottom)
34
34
  end
35
35
 
36
- def entry_to_digits(top, middle, bottom)
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
- conversions[shape] || '?'
43
- end.join
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
@@ -25,6 +25,5 @@ module BankOCR
25
25
  ' ERR'
26
26
  end
27
27
  end
28
-
29
28
  end
30
29
  end
@@ -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
- BankOCR::AccountNumber.new('457508000'),
8
- BankOCR::AccountNumber.new('664371495'),
9
- BankOCR::AccountNumber.new('86110??36')
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
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