coda_standard 0.1.6 → 0.1.7
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 +4 -4
- data/lib/coda_standard/parser.rb +36 -20
- data/lib/coda_standard/record.rb +26 -21
- data/lib/coda_standard/transaction.rb +9 -0
- data/lib/coda_standard/transaction_list.rb +1 -2
- data/lib/coda_standard/version.rb +1 -1
- data/spec/coda.cod +1 -1
- data/spec/parser_spec.rb +3 -3
- data/spec/record_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f877398d2d3037548b41b1c90f4c12409f06c9c
|
4
|
+
data.tar.gz: affb5ec7da939cdbcee9263ab276f664f5e616d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b220227c53fa1c9030dbea09ac0cd39f2cd4403ebce8dd4b4ef1461e6c791877eb382fd7d823a00c0608d164b03ff50abac42ac579524284647e02a6af3c01be
|
7
|
+
data.tar.gz: a9d455e18abc1dae905ef75d6244f3e389e65883f0e0990aa73b5916ccd40fb09f59ff13e3306d4481a15c776d5208854f0fcf1fa646c49a640267cc1c336dec
|
data/lib/coda_standard/parser.rb
CHANGED
@@ -12,25 +12,20 @@ module CodaStandard
|
|
12
12
|
File.open(@filename).each do |line|
|
13
13
|
record = Record.new(line)
|
14
14
|
case
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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)
|
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
|
+
create_transaction
|
22
|
+
extract_data_movement1(record)
|
23
|
+
when record.data_movement2?
|
24
|
+
extract_data_movement2(record)
|
25
|
+
when record.data_movement3?
|
26
|
+
extract_data_movement3(record)
|
27
|
+
when record.data_information2?
|
28
|
+
set_address(record.address)
|
34
29
|
end
|
35
30
|
end
|
36
31
|
@transactions
|
@@ -48,6 +43,27 @@ module CodaStandard
|
|
48
43
|
@transactions.current_account_type = account[:account_type]
|
49
44
|
end
|
50
45
|
|
46
|
+
def create_transaction
|
47
|
+
@current_transaction = @transactions.create
|
48
|
+
end
|
49
|
+
|
50
|
+
def extract_data_movement1(record)
|
51
|
+
@current_transaction.entry_date = record.entry_date
|
52
|
+
@current_transaction.reference_number = record.reference_number
|
53
|
+
@current_transaction.amount = record.amount
|
54
|
+
@current_transaction.structured_communication = record.structured_communication
|
55
|
+
end
|
56
|
+
|
57
|
+
def extract_data_movement2(record)
|
58
|
+
@current_transaction.bic = record.bic
|
59
|
+
end
|
60
|
+
|
61
|
+
def extract_data_movement3(record)
|
62
|
+
@current_transaction.currency = record.currency
|
63
|
+
@current_transaction.name = record.name
|
64
|
+
@current_transaction.account = record.account
|
65
|
+
end
|
66
|
+
|
51
67
|
def show
|
52
68
|
parse
|
53
69
|
puts "**--Transactions--**\n\n"
|
@@ -56,7 +72,7 @@ module CodaStandard
|
|
56
72
|
@transactions.each_with_index do |transaction, index|
|
57
73
|
puts "-- Transaction n.#{index + 1} - number #{transaction.structured_communication} - in date #{transaction.entry_date}-- \n\n"
|
58
74
|
puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC: #{transaction.bic}"
|
59
|
-
puts " Amount: #{transaction.
|
75
|
+
puts " Amount: #{transaction.amount_money}"
|
60
76
|
puts " Name: #{transaction.name}"
|
61
77
|
puts " Address: #{transaction.address} #{transaction.postcode} #{transaction.city} #{transaction.country} \n\n"
|
62
78
|
end
|
data/lib/coda_standard/record.rb
CHANGED
@@ -12,19 +12,21 @@ module CodaStandard
|
|
12
12
|
bic: /^22.{96}(.{11})/,
|
13
13
|
amount: /^21.{29}(\d{16})/,
|
14
14
|
old_balance: /^1.{41}(\d)(\d{15})/,
|
15
|
+
structured_communication: /^21.{60}(.{15})/,
|
16
|
+
currencies: /(^.+)(AED|AFN|ALL|AMD|ANG|AOA|ARS|AUD|AWG|AZN|BAM|BBD|BDT|BGN|BHD|BIF|BMD|BND|BOB|BOV|BRL|BSD|BTN|BWP|BYR|BZD|CAD|CDF|CHE|CHF|CHW|CLF|CLP|CNY|COP|COU|CRC|CUC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HRK|HTG|HUF|IDR|ILS|INR|IQD|IRR|ISK|JMD|JOD|JPY|KES|KGS|KHR|KMF|KPW|KRW|KWD|KYD|KZT|LAK|LBP|LKR|LRD|LSL|LTL|LVL|LYD|MAD|MDL|MGA|MKD|MMK|MNT|MOP|MRO|MUR|MVR|MWK|MXN|MXV|MYR|MZN|NAD|NGN|NIO|NOK|NPR|NZD|OMR|PAB|PEN|PGK|PHP|PKR|PLN|PYG|QAR|RON|RSD|RUB|RWF|SAR|SBD|SCR|SDG|SEK|SGD|SHP|SLL|SOS|SRD|SSP|STD|SVC|SYP|SZL|THB|TJS|TMT|TND|TOP|TRY|TTD|TWD|TZS|UAH|UGX|USD|USN|USS|UYI|UYU|UZS|VEF|VND|VUV|WST|XAF|XAG|XAU|XBA|XBB|XBC|XBD|XCD|XDR|XFU|XOF|XPD|XPF|XPT|XSU|XTS|XUA|XXX|YER|ZAR|ZMW|ZWL)/
|
17
|
+
}
|
18
|
+
|
19
|
+
CLEAN_FIELDS = {
|
20
|
+
clean_zeros: /0*([^0]\d+)(\d{3})/,
|
15
21
|
sep_address: /(^.+)(\d{4})\s(\S+)(\s\S+)?$/,
|
16
22
|
sep_account: /(^.)(.{3})(.+)/,
|
23
|
+
clean_structured: /.{3}(.{12})/,
|
17
24
|
bban_be_account: /(^.{12})/,
|
18
25
|
bban_foreign_account: /(^.{34})/,
|
19
26
|
iban_be_account: /(^.{31})/,
|
20
|
-
iban_foreign_account: /(^.{34})
|
21
|
-
structured_communication: /^21.{60}(.{15})/,
|
22
|
-
clean_structured: /.{3}(.{12})/,
|
23
|
-
currencies: /(^.+)(AED|AFN|ALL|AMD|ANG|AOA|ARS|AUD|AWG|AZN|BAM|BBD|BDT|BGN|BHD|BIF|BMD|BND|BOB|BOV|BRL|BSD|BTN|BWP|BYR|BZD|CAD|CDF|CHE|CHF|CHW|CLF|CLP|CNY|COP|COU|CRC|CUC|CUP|CVE|CZK|DJF|DKK|DOP|DZD|EGP|ERN|ETB|EUR|FJD|FKP|GBP|GEL|GHS|GIP|GMD|GNF|GTQ|GYD|HKD|HNL|HRK|HTG|HUF|IDR|ILS|INR|IQD|IRR|ISK|JMD|JOD|JPY|KES|KGS|KHR|KMF|KPW|KRW|KWD|KYD|KZT|LAK|LBP|LKR|LRD|LSL|LTL|LVL|LYD|MAD|MDL|MGA|MKD|MMK|MNT|MOP|MRO|MUR|MVR|MWK|MXN|MXV|MYR|MZN|NAD|NGN|NIO|NOK|NPR|NZD|OMR|PAB|PEN|PGK|PHP|PKR|PLN|PYG|QAR|RON|RSD|RUB|RWF|SAR|SBD|SCR|SDG|SEK|SGD|SHP|SLL|SOS|SRD|SSP|STD|SVC|SYP|SZL|THB|TJS|TMT|TND|TOP|TRY|TTD|TWD|TZS|UAH|UGX|USD|USN|USS|UYI|UYU|UZS|VEF|VND|VUV|WST|XAF|XAG|XAU|XBA|XBB|XBC|XBD|XCD|XDR|XFU|XOF|XPD|XPF|XPT|XSU|XTS|XUA|XXX|YER|ZAR|ZMW|ZWL)/
|
27
|
+
iban_foreign_account: /(^.{34})/
|
24
28
|
}
|
25
29
|
|
26
|
-
CLEAN_ZEROS_REGEX = /0*([^0]\d+)(\d{3})/
|
27
|
-
|
28
30
|
def initialize(line)
|
29
31
|
@line = line
|
30
32
|
end
|
@@ -107,46 +109,49 @@ module CodaStandard
|
|
107
109
|
result = @line.scan(FIELDS[field]).join.strip
|
108
110
|
case field
|
109
111
|
when :address
|
110
|
-
|
112
|
+
separate_address(result)
|
111
113
|
when :current_account
|
112
|
-
|
114
|
+
clean_account(result)
|
113
115
|
when :old_balance, :amount
|
114
|
-
|
116
|
+
clean_zeros(result)
|
115
117
|
when :structured_communication
|
116
|
-
|
118
|
+
check_structured(result)
|
119
|
+
else
|
120
|
+
result
|
117
121
|
end
|
118
|
-
result
|
119
122
|
end
|
120
123
|
|
121
124
|
def separate_address(address)
|
122
|
-
address_fields = address.scan(
|
123
|
-
{address: address_fields[0].strip, postcode: address_fields[1], city: address_fields[2], country: address_fields[3]}
|
125
|
+
address_fields = address.scan(CLEAN_FIELDS[:sep_address])[0]
|
126
|
+
{ address: address_fields[0].strip, postcode: address_fields[1], city: address_fields[2], country: address_fields[3] }
|
124
127
|
end
|
125
128
|
|
126
129
|
def clean_account(account)
|
127
|
-
account_type = account.scan(
|
128
|
-
raw_account = account.scan(
|
130
|
+
account_type = account.scan(CLEAN_FIELDS[:sep_account])[0][0]
|
131
|
+
raw_account = account.scan(CLEAN_FIELDS[:sep_account])[0][2]
|
129
132
|
case account_type
|
130
133
|
when "0" then account_type = "bban_be_account"
|
131
134
|
when "1" then account_type = "bban_foreign_account"
|
132
135
|
when "2" then account_type = "iban_be_account"
|
133
136
|
when "3" then account_type = "iban_foreign_account"
|
137
|
+
else
|
138
|
+
raise "unsupported account_type: '#{account_type}'"
|
134
139
|
end
|
135
|
-
account_number = raw_account.scan(
|
136
|
-
{account_type: account_type, account_number: account_number}
|
140
|
+
account_number = raw_account.scan(CLEAN_FIELDS[account_type.to_sym]).join
|
141
|
+
{ account_type: account_type, account_number: account_number }
|
137
142
|
end
|
138
143
|
|
139
144
|
def clean_zeros(amount)
|
140
145
|
amount[0] == "0" ? amount_sign = "" : amount_sign = "-"
|
141
|
-
amount_integral = amount.scan(
|
142
|
-
amount_decimals = amount.scan(
|
143
|
-
separator = "
|
146
|
+
amount_integral = amount.scan(CLEAN_FIELDS[:clean_zeros])[0][0]
|
147
|
+
amount_decimals = amount.scan(CLEAN_FIELDS[:clean_zeros])[0][1]
|
148
|
+
separator = "."
|
144
149
|
amount_sign + amount_integral + separator + amount_decimals
|
145
150
|
end
|
146
151
|
|
147
152
|
def check_structured(number)
|
148
153
|
if number[0] == "1"
|
149
|
-
number.scan(
|
154
|
+
number.scan(CLEAN_FIELDS[:clean_structured]).join
|
150
155
|
else
|
151
156
|
"not structured"
|
152
157
|
end
|
@@ -1,8 +1,17 @@
|
|
1
1
|
module CodaStandard
|
2
2
|
class Transaction
|
3
3
|
attr_accessor :name, :currency, :bic, :address, :postcode, :city, :country, :amount, :account, :entry_date, :reference_number, :structured_communication
|
4
|
+
|
4
5
|
def match_structured_communication(structured_communication)
|
5
6
|
@structured_communication == structured_communication
|
6
7
|
end
|
8
|
+
|
9
|
+
def amount_cents
|
10
|
+
(@amount.to_f * 100).to_i
|
11
|
+
end
|
12
|
+
|
13
|
+
def amount_money
|
14
|
+
"#{ amount_cents.to_s.insert(-3, ',') } #{ @currency }"
|
15
|
+
end
|
7
16
|
end
|
8
17
|
end
|
@@ -16,9 +16,8 @@ module CodaStandard
|
|
16
16
|
@transactions.each_with_index(&blk)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
20
19
|
def find_by_structured_communication(structured_communication)
|
21
|
-
@transactions.select{|t| t.match_structured_communication(structured_communication)}
|
20
|
+
@transactions.select{ |t| t.match_structured_communication(structured_communication) }
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
data/spec/coda.cod
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
0000031031520005 MMIF SA/BANK GEBABEBB 00538839354 00000 2
|
2
2
|
10016539007547034 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017
|
3
|
-
21000100000001500000103
|
3
|
+
21000100000001500000103 0000000000500860010415001500001101100000834941 31031501601 0
|
4
4
|
2200010000 GKCCBEBB 1 0
|
5
5
|
2300010000BE53900754703405 EURLASTNM PERSON 0 1
|
6
6
|
31000100010001500000103 001500001001LASTNM PERSON 1 0
|
data/spec/parser_spec.rb
CHANGED
@@ -22,7 +22,7 @@ describe CodaStandard::Parser do
|
|
22
22
|
|
23
23
|
describe "set_address" do
|
24
24
|
before :each do
|
25
|
-
address = {:
|
25
|
+
address = { address: "5 RUE DU CENTCINQUANTENAIRE", postcode: "6750", city: "MUSSY-LA-VILLE", country: " BELGIQUE" }
|
26
26
|
parser.set_address(address)
|
27
27
|
end
|
28
28
|
|
@@ -45,7 +45,7 @@ describe CodaStandard::Parser do
|
|
45
45
|
|
46
46
|
describe "set_account" do
|
47
47
|
before :each do
|
48
|
-
account = {account_number:"035918134040", account_type:"bban_be_account"}
|
48
|
+
account = {account_number: "035918134040", account_type: "bban_be_account"}
|
49
49
|
parser.set_account(account)
|
50
50
|
end
|
51
51
|
|
@@ -60,7 +60,7 @@ describe CodaStandard::Parser do
|
|
60
60
|
|
61
61
|
describe "show" do
|
62
62
|
it "shows the info from the transactions" do
|
63
|
-
expect{parser.show}.to output("**--Transactions--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900
|
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,86 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,00 EUR\n Name: M.JOHN DOE\n Address: 5 STREET 3654 CITY BELGIQUE \n\n").to_stdout
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
data/spec/record_spec.rb
CHANGED
@@ -4,8 +4,8 @@ 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(:data_movement1_record) { CodaStandard::Record.new("21000100000001500000103
|
8
|
-
let(:data_movement1b_record) { CodaStandard::Record.new("21000100000001500000103
|
7
|
+
let(:data_movement1_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500860010415001500001101100000834941 31031501601 0")}
|
8
|
+
let(:data_movement1b_record) { CodaStandard::Record.new("21000100000001500000103 0000000000500860010415001500001001100000834941 31031501601 0")}
|
9
9
|
let(:data_movement2_record) { CodaStandard::Record.new("2200010000 GKCCBEBB 1 0")}
|
10
10
|
let(:data_movement3_record) { CodaStandard::Record.new("2300010000BE53900754703405 EURLASTNM PERSON 0 1")}
|
11
11
|
let(:data_information2_record) { CodaStandard::Record.new("32000200015 STREET 3654 CITY BELGIQUE 0 0")}
|
@@ -84,7 +84,7 @@ describe CodaStandard::Record do
|
|
84
84
|
|
85
85
|
describe "old_balance" do
|
86
86
|
it "extracts the old_balance" do
|
87
|
-
expect(old_balance_data_record.old_balance).to eq("57900
|
87
|
+
expect(old_balance_data_record.old_balance).to eq("57900.000")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -102,7 +102,7 @@ describe CodaStandard::Record do
|
|
102
102
|
|
103
103
|
describe "amount" do
|
104
104
|
it "extracts the amount" do
|
105
|
-
expect(data_movement1_record.amount).to eq("500
|
105
|
+
expect(data_movement1_record.amount).to eq("500.860")
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
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
|
+
version: 0.1.7
|
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-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|