coda_standard 0.1.4 → 0.1.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: c747a72bd151e0741c2f0652934829fbc1414563
4
- data.tar.gz: 8ff61da7a6ff285449b50983284063aecebc14f5
3
+ metadata.gz: 4a1ce079c0bc3adf0c772294905d02bba9e645f3
4
+ data.tar.gz: a9a8f8c3516b715c26e52a8187569f08cefeb735
5
5
  SHA512:
6
- metadata.gz: 0dbd5e47ecc16eae6426567c7dd1ce4e28d21f893b6dd5c9ba65c43ec1308b89516f9c5cc27ae6554a60fc32c268d0f4a6a7506d2230dc12794f7aa3342909c3
7
- data.tar.gz: 18c23f3a27786da2289c6e888a4b0ff93605089ba45181bfa71349c29546b1241475a00ceb45eda2d7bc9e38c1037dd7f35d7e3314be8bb9c8206b5295d26c1d
6
+ metadata.gz: 05f544cf123702072bd15eb11742ea7e7c3a859b5e10aef9ce0df714ec0f3529ba165bcaadd88cebdc9076449edd87a6435115f1d81e335fa0e1ee7b1522cd25
7
+ data.tar.gz: 3206307f035f57558bcaa0b781d131b6bf07570ade4ab1762323249a70a0539caaf8db5acd50aaf90f3be8f8d35eb466ade9d1c97e66d28c3ed253161c80de56
@@ -9,28 +9,28 @@ module CodaStandard
9
9
  end
10
10
 
11
11
  def parse
12
- File.open(@filename).each do |row|
13
- line = Line.new(row)
12
+ File.open(@filename).each do |line|
13
+ record = Record.new(line)
14
14
  case
15
- when line.line =~ /^0/
16
- @transactions.current_bic = line.current_bic
17
- when line.line =~ /^1/
18
- set_account(line.current_account)
19
- @transactions.old_balance = line.old_balance
20
- when line.line =~ /^21/
15
+ when record.header?
16
+ @transactions.current_bic = record.current_bic
17
+ when record.data_old_balance?
18
+ set_account(record.current_account)
19
+ @transactions.old_balance = record.old_balance
20
+ when record.data_movement1?
21
21
  @current_transaction = @transactions.create
22
- @current_transaction.entry_date = line.entry_date
23
- @current_transaction.reference_number = line.reference_number
24
- @current_transaction.amount = line.amount
25
- @current_transaction.transaction_number = line.transaction_number
26
- when line.line =~ /^22/
27
- @current_transaction.bic = line.bic
28
- when line.line =~ /^23/
29
- @current_transaction.currency = line.currency
30
- @current_transaction.name = line.name
31
- @current_transaction.account = line.account
32
- when line.line =~ /^32/
33
- set_address(line.address)
22
+ @current_transaction.entry_date = record.entry_date
23
+ @current_transaction.reference_number = record.reference_number
24
+ @current_transaction.amount = record.amount
25
+ @current_transaction.transaction_number = record.transaction_number
26
+ when record.data_movement2?
27
+ @current_transaction.bic = record.bic
28
+ when record.data_movement3?
29
+ @current_transaction.currency = record.currency
30
+ @current_transaction.name = record.name
31
+ @current_transaction.account = record.account
32
+ when record.data_information2?
33
+ set_address(record.address)
34
34
  end
35
35
  end
36
36
  @transactions
@@ -55,7 +55,7 @@ module CodaStandard
55
55
  puts "Old balance: #{@transactions.old_balance} \n\n"
56
56
  @transactions.each_with_index do |transaction, index|
57
57
  puts "-- Transaction n.#{index + 1} - number #{transaction.transaction_number} - in date #{transaction.entry_date}-- \n\n"
58
- puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC:#{transaction.bic}"
58
+ puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC: #{transaction.bic}"
59
59
  puts " Amount: #{transaction.amount} #{transaction.currency}"
60
60
  puts " Name: #{transaction.name}"
61
61
  puts " Address: #{transaction.address} #{transaction.postcode} #{transaction.city} #{transaction.country} \n\n"
@@ -1,7 +1,5 @@
1
1
  module CodaStandard
2
- class Line
3
- attr_reader :line
4
-
2
+ class Record
5
3
  FIELDS = {
6
4
  current_bic: /^0.{59}(.{11})/,
7
5
  current_account: /^1(.{41})/,
@@ -31,6 +29,30 @@ module CodaStandard
31
29
  @line = line
32
30
  end
33
31
 
32
+ def header?
33
+ @line.start_with? "0"
34
+ end
35
+
36
+ def data_old_balance?
37
+ @line.start_with? "1"
38
+ end
39
+
40
+ def data_movement1?
41
+ @line.start_with? "21"
42
+ end
43
+
44
+ def data_movement2?
45
+ @line.start_with? "22"
46
+ end
47
+
48
+ def data_movement3?
49
+ @line.start_with? "23"
50
+ end
51
+
52
+ def data_information2?
53
+ @line.start_with? "32"
54
+ end
55
+
34
56
  def current_bic
35
57
  extract(:current_bic)
36
58
  end
@@ -1,3 +1,3 @@
1
1
  module CodaStandard
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
data/lib/coda_standard.rb CHANGED
@@ -2,7 +2,7 @@ require "coda_standard/version"
2
2
  require "coda_standard/parser"
3
3
  require "coda_standard/transaction"
4
4
  require "coda_standard/transaction_list"
5
- require "coda_standard/line"
5
+ require "coda_standard/record"
6
6
 
7
7
  module CodaStandard
8
8
  end
data/spec/parser_spec.rb CHANGED
@@ -1,69 +1,66 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
3
  describe CodaStandard::Parser do
4
-
5
- before :each do
6
- filename = 'spec/coda.cod'
7
- @parser = CodaStandard::Parser.new(filename)
8
- end
4
+ let(:filename) { 'spec/coda.cod' }
5
+ let(:parser) { CodaStandard::Parser.new(filename) }
9
6
 
10
7
  describe "initialize" do
11
8
  it "initializes some class variables" do
12
- expect(@parser.transactions).to be_a(CodaStandard::TransactionList)
9
+ expect(parser.transactions).to be_a(CodaStandard::TransactionList)
13
10
  end
14
11
  end
15
12
 
16
13
  describe "parse" do
17
14
  before :each do
18
- @parser.parse
15
+ parser.parse
19
16
  end
20
17
 
21
18
  it "returns a Transactions object" do
22
- expect(@parser.parse).to be_a(CodaStandard::TransactionList)
19
+ expect(parser.parse).to be_a(CodaStandard::TransactionList)
23
20
  end
24
21
  end
25
22
 
26
23
  describe "set_address" do
27
24
  before :each do
28
25
  address = {:address=>"5 RUE DU CENTCINQUANTENAIRE", :postcode=>"6750", :city=>"MUSSY-LA-VILLE", :country=>" BELGIQUE"}
29
- @parser.set_address(address)
26
+ parser.set_address(address)
30
27
  end
31
28
 
32
29
  it "sets the address field to the current transaction" do
33
- expect(@parser.current_transaction.address).to eq("5 RUE DU CENTCINQUANTENAIRE")
30
+ expect(parser.current_transaction.address).to eq("5 RUE DU CENTCINQUANTENAIRE")
34
31
  end
35
32
 
36
33
  it "sets the postcode field to the current transaction" do
37
- expect(@parser.current_transaction.postcode).to eq("6750")
34
+ expect(parser.current_transaction.postcode).to eq("6750")
38
35
  end
39
36
 
40
37
  it "sets the city field to the current transaction" do
41
- expect(@parser.current_transaction.city).to eq("MUSSY-LA-VILLE")
38
+ expect(parser.current_transaction.city).to eq("MUSSY-LA-VILLE")
42
39
  end
43
40
 
44
41
  it "sets the country field to the current transaction" do
45
- expect(@parser.current_transaction.country).to eq(" BELGIQUE")
42
+ expect(parser.current_transaction.country).to eq(" BELGIQUE")
46
43
  end
47
44
  end
48
45
 
49
46
  describe "set_account" do
50
47
  before :each do
51
48
  account = {account_number:"035918134040", account_type:"bban_be_account"}
52
- @parser.set_account(account)
49
+ parser.set_account(account)
53
50
  end
54
51
 
55
52
  it "sets the current_account field to the TransactionList" do
56
- expect(@parser.transactions.current_account).to eq("035918134040")
53
+ expect(parser.transactions.current_account).to eq("035918134040")
57
54
  end
58
55
 
59
56
  it "sets the account_type field to the TransactionList" do
60
- expect(@parser.transactions.current_account_type).to eq("bban_be_account")
57
+ expect(parser.transactions.current_account_type).to eq("bban_be_account")
61
58
  end
62
59
  end
63
60
 
64
61
  describe "show" do
65
62
  it "shows the info from the transactions" do
66
- expect{@parser.show}.to output("**--Transactions--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900,000 \n\n-- Transaction n.1 - number 100000834941 - in date 310315-- \n\n RN: 0001500000103 Account: BE53900754703405 BIC:GKCCBEBB\n Amount: 500,000 EUR\n Name: LASTNM PERSON\n Address: CHAUSSEE DE BIERE 10 1978 SOMECITY \n\n-- Transaction n.2 - number 100000835749 - in date 310315-- \n\n RN: 0001500000104 Account: LU539007547034898400 BIC:BILLLULL\n Amount: 200,000 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
63
+ expect{parser.show}.to output("**--Transactions--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900,000 \n\n-- Transaction n.1 - number 100000834941 - in date 310315-- \n\n RN: 0001500000103 Account: BE53900754703405 BIC: GKCCBEBB\n Amount: 500,000 EUR\n Name: LASTNM PERSON\n Address: CHAUSSEE DE BIERE 10 1978 SOMECITY \n\n-- Transaction n.2 - number 100000835749 - in date 310315-- \n\n RN: 0001500000104 Account: LU539007547034898400 BIC: BILLLULL\n Amount: 200,000 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
67
64
  end
68
65
  end
69
66
 
@@ -0,0 +1,152 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe CodaStandard::Record do
4
+
5
+ let(:header_record) { CodaStandard::Record.new("0000031031520005 MMIF SA/BANK GEBABEBB 00538839354 00000 2")}
6
+ let(:old_balance_data_record) { CodaStandard::Record.new("10016539007547034 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017")}
7
+ let(:data_movement1_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500000010415001500001101100000834941 31031501601 0")}
8
+ let(:data_movement1b_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500000010415001500001001100000834941 31031501601 0")}
9
+ let(:data_movement2_record) { CodaStandard::Record.new("2200010000 GKCCBEBB 1 0")}
10
+ let(:data_movement3_record) { CodaStandard::Record.new("2300010000BE53900754703405 EURLASTNM PERSON 0 1")}
11
+ let(:data_information2_record) { CodaStandard::Record.new("32000200015 STREET 3654 CITY BELGIQUE 0 0")}
12
+
13
+ describe "data_header" do
14
+ it "returns true if the line starts with a zero" do
15
+ expect(header_record.header?).to be true
16
+ end
17
+
18
+ it "returns false if the line does not start with a zero" do
19
+ expect(old_balance_data_record.header?).to be false
20
+ end
21
+ end
22
+
23
+ describe "data_old_balance" do
24
+ it "returns true if the line starts with a one" do
25
+ expect(old_balance_data_record.data_old_balance?).to be true
26
+ end
27
+
28
+ it "returns false if the line does not start with a one" do
29
+ expect(header_record.data_old_balance?).to be false
30
+ end
31
+ end
32
+
33
+ describe "data_movement1" do
34
+ it "returns true if the line starts with a 21" do
35
+ expect(data_movement1_record.data_movement1?).to be true
36
+ end
37
+
38
+ it "returns false if the line does not start with 21" do
39
+ expect(header_record.data_movement1?).to be false
40
+ end
41
+ end
42
+
43
+ describe "data_movement2" do
44
+ it "returns true if the line starts with a 22" do
45
+ expect(data_movement2_record.data_movement2?).to be true
46
+ end
47
+
48
+ it "returns false if the line does not start with 22" do
49
+ expect(header_record.data_movement2?).to be false
50
+ end
51
+ end
52
+
53
+ describe "data_movement3" do
54
+ it "returns true if the line starts with a 23" do
55
+ expect(data_movement3_record.data_movement3?).to be true
56
+ end
57
+
58
+ it "returns false if the line does not start with 23" do
59
+ expect(header_record.data_movement3?).to be false
60
+ end
61
+ end
62
+
63
+ describe "data_information2" do
64
+ it "returns true if the line starts with a 32" do
65
+ expect(data_information2_record.data_information2?).to be true
66
+ end
67
+
68
+ it "returns false if the line does not start with 32" do
69
+ expect(header_record.data_information2?).to be false
70
+ end
71
+ end
72
+
73
+ describe "current_bic" do
74
+ it "extracts the current_bic" do
75
+ expect(header_record.current_bic).to eq("GEBABEBB")
76
+ end
77
+ end
78
+
79
+ describe "current_account" do
80
+ it "extracts the current_account" do
81
+ expect(old_balance_data_record.current_account).to eq({account_number:"539007547034", account_type:"bban_be_account"})
82
+ end
83
+ end
84
+
85
+ describe "old_balance" do
86
+ it "extracts the old_balance" do
87
+ expect(old_balance_data_record.old_balance).to eq("57900,000")
88
+ end
89
+ end
90
+
91
+ describe "entry_date" do
92
+ it "extracts the entry_date" do
93
+ expect(data_movement1_record.entry_date).to eq("310315")
94
+ end
95
+ end
96
+
97
+ describe "reference_number" do
98
+ it "extracts the reference_number" do
99
+ expect(data_movement1_record.reference_number).to eq("0001500000103")
100
+ end
101
+ end
102
+
103
+ describe "amount" do
104
+ it "extracts the amount" do
105
+ expect(data_movement1_record.amount).to eq("500,000")
106
+ end
107
+ end
108
+
109
+ describe "bic" do
110
+ it "extracts the bic" do
111
+ expect(data_movement2_record.bic).to eq("GKCCBEBB")
112
+ end
113
+ end
114
+
115
+ describe "currency" do
116
+ it "extracts the currency" do
117
+ expect(data_movement3_record.currency).to eq("EUR")
118
+ end
119
+ end
120
+
121
+ describe "name" do
122
+ it "extracts the name" do
123
+ expect(data_movement3_record.name).to eq("LASTNM PERSON")
124
+ end
125
+ end
126
+
127
+ describe "account" do
128
+ it "extracts the account" do
129
+ expect(data_movement3_record.account).to eq("BE53900754703405")
130
+ end
131
+ end
132
+
133
+ describe "transaction_number" do
134
+ context "structured_number" do
135
+ it "extracts the number" do
136
+ expect(data_movement1_record.transaction_number).to eq("100000834941")
137
+ end
138
+ end
139
+ context "non-structured_number" do
140
+ it "returns not structured" do
141
+ expect(data_movement1b_record.transaction_number).to eq("not structured")
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "address" do
147
+ it "extracts the address" do
148
+ expect(data_information2_record.address).to eq({:address=>"5 STREET", :postcode=>"3654", :city=>"CITY", :country=>" BELGIQUE"})
149
+ end
150
+ end
151
+
152
+ end
@@ -1,20 +1,18 @@
1
1
  require_relative 'spec_helper'
2
2
 
3
3
  describe CodaStandard::TransactionList do
4
- before :each do
5
- @transaction_list = CodaStandard::TransactionList.new
6
- end
4
+ let(:transaction_list) { CodaStandard::TransactionList.new }
7
5
 
8
6
  describe "initialize some values" do
9
7
  it "has an transactions array" do
10
- expect(@transaction_list.transactions).to eq([])
8
+ expect(transaction_list.transactions).to eq([])
11
9
  end
12
10
  end
13
11
 
14
12
  describe "create" do
15
13
  it "creates a new transaction and puts it into the array" do
16
- @transaction_list.create
17
- expect(@transaction_list.create).to eq @transaction_list.transactions.last
14
+ transaction_list.create
15
+ expect(transaction_list.create).to eq transaction_list.transactions.last
18
16
  end
19
17
  end
20
- end
18
+ 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.4
4
+ version: 0.1.5
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-04-14 00:00:00.000000000 Z
11
+ date: 2015-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,14 +66,14 @@ files:
66
66
  - Rakefile
67
67
  - coda_standard.gemspec
68
68
  - lib/coda_standard.rb
69
- - lib/coda_standard/line.rb
70
69
  - lib/coda_standard/parser.rb
70
+ - lib/coda_standard/record.rb
71
71
  - lib/coda_standard/transaction.rb
72
72
  - lib/coda_standard/transaction_list.rb
73
73
  - lib/coda_standard/version.rb
74
74
  - spec/coda.cod
75
- - spec/line_spec.rb
76
75
  - spec/parser_spec.rb
76
+ - spec/record_spec.rb
77
77
  - spec/spec_helper.rb
78
78
  - spec/transaction_list_spec.rb
79
79
  homepage: https://github.com/Bluesmile82/coda_standard
@@ -102,7 +102,7 @@ specification_version: 4
102
102
  summary: CODA bank standard file parser
103
103
  test_files:
104
104
  - spec/coda.cod
105
- - spec/line_spec.rb
106
105
  - spec/parser_spec.rb
106
+ - spec/record_spec.rb
107
107
  - spec/spec_helper.rb
108
108
  - spec/transaction_list_spec.rb
data/spec/line_spec.rb DELETED
@@ -1,93 +0,0 @@
1
- require_relative 'spec_helper'
2
-
3
- describe CodaStandard::Line do
4
- before :each do
5
- @line0 = CodaStandard::Line.new("0000031031520005 MMIF SA/BANK GEBABEBB 00538839354 00000 2")
6
- @line1 = CodaStandard::Line.new("10016539007547034 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017")
7
- @line21 = CodaStandard::Line.new("21000100000001500000103 0000000000500000010415001500001101100000834941 31031501601 0")
8
- @line21b = CodaStandard::Line.new("21000100000001500000103 0000000000500000010415001500001001100000834941 31031501601 0")
9
- @line22 = CodaStandard::Line.new("2200010000 GKCCBEBB 1 0")
10
- @line23 = CodaStandard::Line.new("2300010000BE53900754703405 EURLASTNM PERSON 0 1")
11
- @line32 = CodaStandard::Line.new("32000200015 STREET 3654 CITY BELGIQUE 0 0")
12
- end
13
-
14
- describe "current_bic" do
15
- it "extracts the current_bic" do
16
- expect(@line0.current_bic).to eq("GEBABEBB")
17
- end
18
- end
19
-
20
- describe "current_account" do
21
- it "extracts the current_account" do
22
- expect(@line1.current_account).to eq({account_number:"539007547034", account_type:"bban_be_account"})
23
- end
24
- end
25
-
26
- describe "old_balance" do
27
- it "extracts the old_balance" do
28
- expect(@line1.old_balance).to eq("57900,000")
29
- end
30
- end
31
-
32
- describe "entry_date" do
33
- it "extracts the entry_date" do
34
- expect(@line21.entry_date).to eq("310315")
35
- end
36
- end
37
-
38
- describe "reference_number" do
39
- it "extracts the reference_number" do
40
- expect(@line21.reference_number).to eq("0001500000103")
41
- end
42
- end
43
-
44
- describe "amount" do
45
- it "extracts the amount" do
46
- expect(@line21.amount).to eq("500,000")
47
- end
48
- end
49
-
50
- describe "bic" do
51
- it "extracts the bic" do
52
- expect(@line22.bic).to eq("GKCCBEBB")
53
- end
54
- end
55
-
56
- describe "currency" do
57
- it "extracts the currency" do
58
- expect(@line23.currency).to eq("EUR")
59
- end
60
- end
61
-
62
- describe "name" do
63
- it "extracts the name" do
64
- expect(@line23.name).to eq("LASTNM PERSON")
65
- end
66
- end
67
-
68
- describe "account" do
69
- it "extracts the account" do
70
- expect(@line23.account).to eq("BE53900754703405")
71
- end
72
- end
73
-
74
- describe "transaction_number" do
75
- context "structured_number" do
76
- it "extracts the number" do
77
- expect(@line21.transaction_number).to eq("100000834941")
78
- end
79
- end
80
- context "non-structured_number" do
81
- it "returns not structured" do
82
- expect(@line21b.transaction_number).to eq("not structured")
83
- end
84
- end
85
- end
86
-
87
- describe "address" do
88
- it "extracts the address" do
89
- expect(@line32.address).to eq({:address=>"5 STREET", :postcode=>"3654", :city=>"CITY", :country=>" BELGIQUE"})
90
- end
91
- end
92
-
93
- end