coda_standard 0.1.9 → 0.2.0

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: dda9c638d689bcea9637bbac5a47a1a2158b6e89
4
- data.tar.gz: ca9292bdbab414c7bb4592a1a4cbf2d25f104064
3
+ metadata.gz: f1dbb0e0db4bc5c06941b94ca4a7a36f8cee8291
4
+ data.tar.gz: ecea24627d4a271c938863c81cf0abc5d2414268
5
5
  SHA512:
6
- metadata.gz: 193f1a011ec3fd8aedea410340d7de00e34f04c07a2f9479d63c783b2cd1b9a8b0ce82efe0fbf8569d94946db53b35f339519c98b6aba375b23deec62ecde12c
7
- data.tar.gz: ac36c1f4530a2e2c125e8c7914be1d07f3b09b13cddf1e2759d12a36499ce86db6bc277e5cf709c7e8306466677d03fd2edf847cb8a202e7274ce8a58a40fa0c
6
+ metadata.gz: 9a72a672dd4b470872a43158a3d08ab5321d9e6afe896c2527e3b7c0354ab6c34593ebe907f2f254dfa93b236f55f8b7f6227bc6b34c15d78a30261f7cc3a1ac
7
+ data.tar.gz: b9be352b5843db3068d858408ccbd160125808506fd6c0553ad21496fbc1e25831bc088128aff48d6b5047a9f5d906360999fe411222c3e81d00e9293e373b67
data/.gitignore CHANGED
@@ -14,6 +14,8 @@
14
14
  *.a
15
15
  mkmf.log
16
16
 
17
+ inv.cod
18
+
17
19
  *.gem
18
20
  *.rbc
19
21
  /.config
data/README.md CHANGED
@@ -37,6 +37,12 @@ CodaStandard::Parser.new(filename).parse.first.transactions[0].amount
37
37
  # or print a more readable representation of the file
38
38
  CodaStandard::Parser.new(filename).show
39
39
 
40
+ # or check if the file is valid (the validation is not yet implemented for every field)
41
+ CodaStandard::Parser.new(filename).valid? => true
42
+
43
+ # by default the parse and show methods have validation but you can skip it if you dare
44
+ CodaStandard::Parser.new(filename).parse(skip_validation: true)
45
+
40
46
  # you can also find a transaction inside a transaction list object by the structured communication number
41
47
  CodaStandard::Parser.new(filename).parse.first.find_by_structured_communication('100000001234')
42
48
  ```
@@ -9,7 +9,16 @@ module CodaStandard
9
9
  @current_transaction = Transaction.new
10
10
  end
11
11
 
12
- def parse
12
+ def valid?
13
+ File.open(@filename).each do |line|
14
+ record = Record.new(line)
15
+ return false unless record.valid?
16
+ end
17
+ true
18
+ end
19
+
20
+ def parse(skip_validation: skip_validation = false)
21
+ return [] if !skip_validation && !valid?
13
22
  File.open(@filename).each do |line|
14
23
  record = Record.new(line)
15
24
  case
@@ -71,8 +80,9 @@ module CodaStandard
71
80
  @current_transaction.account = record.account
72
81
  end
73
82
 
74
- def show
75
- parse
83
+ def show(skip_validation: skip_validation = false)
84
+ puts "The file is invalid" if !skip_validation && !valid?
85
+ parse(skip_validation: skip_validation)
76
86
  @transactions.each_with_index do |transaction, index|
77
87
  puts "**--Transaction List #{ index + 1 }--**\n\n"
78
88
  puts "Account: #{transaction.current_account} Account type: #{transaction.current_account_type} BIC: #{transaction.current_bic}"
@@ -103,10 +103,28 @@ module CodaStandard
103
103
  extract(:structured_communication)
104
104
  end
105
105
 
106
+ def valid?
107
+ if data_old_balance?
108
+ return false if !field_valid?(:current_account)
109
+ end
110
+ true
111
+ end
112
+
113
+ def field_valid?(field)
114
+ if field == :current_account
115
+ return raw_extract(:current_account).scan(CLEAN_FIELDS[:sep_account]).flatten.size == 3
116
+ end
117
+ true
118
+ end
119
+
106
120
  private
107
121
 
122
+ def raw_extract(field)
123
+ @line.scan(FIELDS[field]).join.strip
124
+ end
125
+
108
126
  def extract(field)
109
- result = @line.scan(FIELDS[field]).join.strip
127
+ result = raw_extract(field)
110
128
  case field
111
129
  when :address
112
130
  separate_address(result)
@@ -126,6 +144,7 @@ module CodaStandard
126
144
  { address: address_fields[0].strip, postcode: address_fields[1], city: address_fields[2], country: address_fields[3] }
127
145
  end
128
146
 
147
+
129
148
  def clean_account(account)
130
149
  account_type = account.scan(CLEAN_FIELDS[:sep_account])[0][0]
131
150
  raw_account = account.scan(CLEAN_FIELDS[:sep_account])[0][2]
@@ -1,3 +1,3 @@
1
1
  module CodaStandard
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/invalid.cod ADDED
@@ -0,0 +1,18 @@
1
+ 0000031031520005 MMIF SA/BANK GEBABEBB 00538839354 00000 2
2
+ 10016539007547034 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017
3
+ 21000100000001500000103 0000000000500860010415001500001101100000834941 31031501601 0
4
+ 2200010000 GKCCBEBB 1 0
5
+ 2300010000BE53900754703405 EURLASTNM PERSON 0 1
6
+ 31000100010001500000103 001500001001LASTNM PERSON 1 0
7
+ 3200010001CHAUSSEE DE BIERE 10 1978 SOMECITY 0 0
8
+ 21000200000001500000104 0000000000200000010415001500001102100000835749 31031501601 0
9
+ 2200020000 BILLLULL 1 0
10
+ 2300020000LU539007547034898400 EURM.JOHN DOE 0 1
11
+ 31000200010001500000104 001500001001M.JOHN DOE 1 0
12
+ 32000200015 STREET 3654 CITY BELGIQUE 0 0
13
+ 8016035918134040 EUR0BE 0000000058900000310315 0
14
+ 9 000027000000000000000000000001000000
15
+
16
+
17
+
18
+ 100/0000/00135
data/spec/parser_spec.rb CHANGED
@@ -3,6 +3,8 @@ require_relative 'spec_helper'
3
3
  describe CodaStandard::Parser do
4
4
  let(:filename) { 'spec/coda.cod' }
5
5
  let(:parser) { CodaStandard::Parser.new(filename) }
6
+ let(:filename_invalid) { 'spec/invalid.cod' }
7
+ let(:parser_invalid) { CodaStandard::Parser.new(filename_invalid) }
6
8
 
7
9
  describe "initialize" do
8
10
  it "initializes some class variables" do
@@ -15,6 +17,18 @@ describe CodaStandard::Parser do
15
17
  parser.parse
16
18
  end
17
19
 
20
+ context "skip_validation is false or not specified" do
21
+ it "returns an empty array if the file is invalid" do
22
+ expect(parser_invalid.parse).to eq []
23
+ end
24
+ end
25
+
26
+ context "skip_validation is true" do
27
+ it "raises an exception when invalid" do
28
+ expect{ parser_invalid.parse(skip_validation: true) }.to raise_error
29
+ end
30
+ end
31
+
18
32
  it "returns an array of TransactionLists" do
19
33
  expect(parser.parse).to be_a(Array)
20
34
  parser.parse.each{ |tl| expect(tl).to be_a(CodaStandard::TransactionList) }
@@ -61,9 +75,29 @@ describe CodaStandard::Parser do
61
75
  end
62
76
 
63
77
  describe "show" do
78
+ context "skip_validation is false or not specified" do
79
+ it "returns a message if the file is invalid" do
80
+ expect{ parser_invalid.show }.to output("The file is invalid\n").to_stdout
81
+ end
82
+ end
83
+ context "skip_validation is true" do
84
+ it "raises an exception when invalid" do
85
+ expect{ parser_invalid.show(skip_validation: true) }.to raise_error
86
+ end
87
+ end
88
+
64
89
  it "shows the info from the transactions" do
65
90
  expect{ parser.show }.to output("**--Transaction List 1--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900.000 \n\n-- Transaction n.1 - number 100000834941 - in date 2015-03-31-- \n\n RN: 0001500000103 Account: BE53900754703405 BIC: GKCCBEBB\n Amount: 500,86 EUR\n Name: LASTNM PERSON\n Address: CHAUSSEE DE BIERE 10 1978 SOMECITY \n\n-- Transaction n.2 - number 100000835749 - in date 2015-03-31-- \n\n RN: 0001500000104 Account: LU539007547034898400 BIC: BILLLULL\n Amount: 200,00 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
66
91
  end
67
92
  end
68
93
 
94
+ describe "valid?" do
95
+ it "returns true if the file is valid" do
96
+ expect(parser.valid?).to be true
97
+ end
98
+
99
+ it "returns false if the file is invalid" do
100
+ expect(parser_invalid.valid?).to be false
101
+ end
102
+ end
69
103
  end
data/spec/record_spec.rb CHANGED
@@ -4,6 +4,7 @@ describe CodaStandard::Record do
4
4
 
5
5
  let(:header_record) { CodaStandard::Record.new("0000031031520005 MMIF SA/BANK GEBABEBB 00538839354 00000 2")}
6
6
  let(:old_balance_data_record) { CodaStandard::Record.new("10016539007547034 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017")}
7
+ let(:old_balance_data_record_invalid) { CodaStandard::Record.new("100/0000/00135")}
7
8
  let(:data_movement1_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500860010415001500001101100000834941 31031501601 0")}
8
9
  let(:data_movement1b_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500860010415001500001001100000834941 31031501601 0")}
9
10
  let(:data_movement2_record) { CodaStandard::Record.new("2200010000 GKCCBEBB 1 0")}
@@ -136,6 +137,7 @@ describe CodaStandard::Record do
136
137
  expect(data_movement1_record.structured_communication).to eq("100000834941")
137
138
  end
138
139
  end
140
+
139
141
  context "non-structured_number" do
140
142
  it "returns not structured" do
141
143
  expect(data_movement1b_record.structured_communication).to eq("not structured")
@@ -149,4 +151,13 @@ describe CodaStandard::Record do
149
151
  end
150
152
  end
151
153
 
154
+ describe "valid?" do
155
+ it "returns true if the record is valid" do
156
+ expect(old_balance_data_record.valid?).to be true
157
+ end
158
+
159
+ it "returns false if the record is invalid" do
160
+ expect(old_balance_data_record_invalid.valid?).to be false
161
+ end
162
+ end
152
163
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coda_standard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alvaro Leal
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,6 +72,7 @@ files:
72
72
  - lib/coda_standard/transaction_list.rb
73
73
  - lib/coda_standard/version.rb
74
74
  - spec/coda.cod
75
+ - spec/invalid.cod
75
76
  - spec/parser_spec.rb
76
77
  - spec/record_spec.rb
77
78
  - spec/spec_helper.rb
@@ -102,6 +103,7 @@ specification_version: 4
102
103
  summary: CODA bank standard file parser
103
104
  test_files:
104
105
  - spec/coda.cod
106
+ - spec/invalid.cod
105
107
  - spec/parser_spec.rb
106
108
  - spec/record_spec.rb
107
109
  - spec/spec_helper.rb