coda_standard 0.1.3 → 0.1.4
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/README.md +26 -25
- data/lib/coda_standard/line.rb +34 -34
- data/lib/coda_standard/parser.rb +34 -32
- data/lib/coda_standard/version.rb +1 -1
- data/lib/coda_standard.rb +1 -0
- data/spec/parser_spec.rb +7 -6
- 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: c747a72bd151e0741c2f0652934829fbc1414563
|
4
|
+
data.tar.gz: 8ff61da7a6ff285449b50983284063aecebc14f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dbd5e47ecc16eae6426567c7dd1ce4e28d21f893b6dd5c9ba65c43ec1308b89516f9c5cc27ae6554a60fc32c268d0f4a6a7506d2230dc12794f7aa3342909c3
|
7
|
+
data.tar.gz: 18c23f3a27786da2289c6e888a4b0ff93605089ba45181bfa71349c29546b1241475a00ceb45eda2d7bc9e38c1037dd7f35d7e3314be8bb9c8206b5295d26c1d
|
data/README.md
CHANGED
@@ -1,42 +1,41 @@
|
|
1
|
-
# coda_standard
|
1
|
+
# coda_standard
|
2
2
|
|
3
|
-
This gem parses the Coded statement of account (CODA) bank standard.
|
4
|
-
## Installation
|
3
|
+
This gem parses the [Coded statement of account](https://www.febelfin.be/sites/default/files/files/Standard-CODA-22-EN.pdf) (CODA) bank standard used by some banks and follows version 2.2 of this standard.
|
5
4
|
|
6
|
-
|
5
|
+
> This bank standard specifies the lay-out for the electronic files, by banks to customers, of the account transactions and the information concerning the enclosures in connection with the movement.
|
7
6
|
|
8
|
-
|
9
|
-
gem 'coda_standard'
|
10
|
-
```
|
11
|
-
|
12
|
-
And then execute:
|
7
|
+
The coda_standard gem requires Ruby version ~> 2.0.
|
13
8
|
|
14
|
-
|
15
|
-
|
16
|
-
Or install it yourself as:
|
9
|
+
## Install
|
17
10
|
|
18
11
|
$ gem install coda_standard
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
$ CodaStandard::Parser.new.parse(filename)
|
13
|
+
or add the following line to Gemfile:
|
23
14
|
|
24
|
-
|
15
|
+
```
|
16
|
+
gem 'coda_standard'
|
17
|
+
```
|
25
18
|
|
26
|
-
|
19
|
+
and run `bundle install` from your shell.
|
27
20
|
|
28
|
-
|
21
|
+
## Usage
|
29
22
|
|
30
|
-
|
23
|
+
```ruby
|
24
|
+
# a new TransactionList object:
|
25
|
+
CodaStandard::Parser.new(filename).parse
|
31
26
|
|
32
|
-
|
27
|
+
# or an array of transactions:
|
28
|
+
CodaStandard::Parser.new(filename).parse.transactions
|
33
29
|
|
34
|
-
|
30
|
+
# or maybe the BIC:
|
31
|
+
CodaStandard::Parser.new(filename).parse.current_bic => "GEBABEBB"
|
32
|
+
# also available are: old_balance, current_account, current_account_type
|
35
33
|
|
36
|
-
|
34
|
+
# or print a more readable represenation of the file
|
35
|
+
CodaStandard::Parser.new(filename).show
|
36
|
+
```
|
37
37
|
|
38
|
-
The
|
39
|
-
name, currency, bic, address, postcode, city, country, amount, account, entry_date, reference_number and transaction_number
|
38
|
+
The available getters for each transaction are: `name`, `currency`, `bic`, `address`, `postcode`, `city`, `country`, `amount`, `account`, `entry_date`, `reference_number` and `transaction_number`.
|
40
39
|
|
41
40
|
## Contributing
|
42
41
|
|
@@ -46,4 +45,6 @@ The info you can get from each transaction is:
|
|
46
45
|
4. Push to the branch (`git push origin my-new-feature`)
|
47
46
|
5. Create a new Pull Request
|
48
47
|
|
49
|
-
|
48
|
+
## License
|
49
|
+
|
50
|
+
coda_standard is Copyright © 2015 Alvaro Leal. It is free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE) file.
|
data/lib/coda_standard/line.rb
CHANGED
@@ -2,31 +2,33 @@ module CodaStandard
|
|
2
2
|
class Line
|
3
3
|
attr_reader :line
|
4
4
|
|
5
|
+
FIELDS = {
|
6
|
+
current_bic: /^0.{59}(.{11})/,
|
7
|
+
current_account: /^1(.{41})/,
|
8
|
+
name: /^23.{45}(.{35})/,
|
9
|
+
currency: /^23.{42}(.{3})/,
|
10
|
+
entry_date: /^21.{113}(\d{6})/,
|
11
|
+
reference_number: /^21.{8}(.{21})/,
|
12
|
+
address: /^32.{8}(.{105})/,
|
13
|
+
account: /^23\d{8}(\w+)\D/,
|
14
|
+
bic: /^22.{96}(.{11})/,
|
15
|
+
amount: /^21\d+\s+(\d{16})/,
|
16
|
+
old_balance: /^1.{41}(\d)(\d{15})/,
|
17
|
+
sep_address: /(^.+)(\d{4})\s(\S+)(\s\S+)?$/,
|
18
|
+
sep_account: /(^.)(.{3})(.+)/,
|
19
|
+
bban_be_account: /(^.{12})/,
|
20
|
+
bban_foreign_account: /(^.{34})/,
|
21
|
+
iban_be_account: /(^.{31})/,
|
22
|
+
iban_foreign_account: /(^.{34})/,
|
23
|
+
transaction_number: /^21.{60}(.{15})/,
|
24
|
+
clean_structured: /.{3}(.{12})/,
|
25
|
+
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)/
|
26
|
+
}
|
27
|
+
|
28
|
+
CLEAN_ZEROS_REGEX = /0*([^0]\d+)(\d{3})/
|
29
|
+
|
5
30
|
def initialize(line)
|
6
31
|
@line = line
|
7
|
-
@regexp = {
|
8
|
-
current_bic: /^0.{59}(.{11})/,
|
9
|
-
current_account: /^1(.{41})/,
|
10
|
-
name: /^23.{45}(.{35})/,
|
11
|
-
currency: /^23.{42}(.{3})/,
|
12
|
-
entry_date: /^21.{113}(\d{6})/,
|
13
|
-
reference_number: /^21.{8}(.{21})/,
|
14
|
-
address: /^32.{8}(.{105})/,
|
15
|
-
account: /^23\d{8}(\w+)\D/,
|
16
|
-
bic: /^22.{96}(.{11})/,
|
17
|
-
amount: /^21\d+\s+(\d{16})/,
|
18
|
-
old_balance: /^1.{41}(\d)(\d{15})/,
|
19
|
-
clean_zeros: /0*([^0]\d+)(\d{3})/,
|
20
|
-
sep_address: /(^.+)(\d{4})\s(\S+)(\s\S+)?$/,
|
21
|
-
sep_account: /(^.)(.{3})(.+)/,
|
22
|
-
bban_be_account: /(^.{12})/,
|
23
|
-
bban_foreign_account: /(^.{34})/,
|
24
|
-
iban_be_account: /(^.{31})/,
|
25
|
-
iban_foreign_account: /(^.{34})/,
|
26
|
-
transaction_number: /^21.{60}(.{15})/,
|
27
|
-
clean_structured: /.{3}(.{12})/,
|
28
|
-
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)/
|
29
|
-
}
|
30
32
|
end
|
31
33
|
|
32
34
|
def current_bic
|
@@ -80,7 +82,7 @@ module CodaStandard
|
|
80
82
|
private
|
81
83
|
|
82
84
|
def extract(field)
|
83
|
-
result = @line.scan(
|
85
|
+
result = @line.scan(FIELDS[field]).join.strip
|
84
86
|
case field
|
85
87
|
when :address
|
86
88
|
result = separate_address(result)
|
@@ -95,39 +97,37 @@ module CodaStandard
|
|
95
97
|
end
|
96
98
|
|
97
99
|
def separate_address(address)
|
98
|
-
address_fields = address.scan(
|
100
|
+
address_fields = address.scan(FIELDS[:sep_address])[0]
|
99
101
|
{address: address_fields[0].strip, postcode: address_fields[1], city: address_fields[2], country: address_fields[3]}
|
100
102
|
end
|
101
103
|
|
102
104
|
def clean_account(account)
|
103
|
-
account_type = account.scan(
|
104
|
-
|
105
|
-
raw_account = account.scan(@regexp[:sep_account])[0][2]
|
105
|
+
account_type = account.scan(FIELDS[:sep_account])[0][0]
|
106
|
+
raw_account = account.scan(FIELDS[:sep_account])[0][2]
|
106
107
|
case account_type
|
107
108
|
when "0" then account_type = "bban_be_account"
|
108
109
|
when "1" then account_type = "bban_foreign_account"
|
109
110
|
when "2" then account_type = "iban_be_account"
|
110
111
|
when "3" then account_type = "iban_foreign_account"
|
111
112
|
end
|
112
|
-
account_number = raw_account.scan(
|
113
|
+
account_number = raw_account.scan(FIELDS[account_type.to_sym]).join
|
113
114
|
{account_type: account_type, account_number: account_number}
|
114
115
|
end
|
115
116
|
|
116
117
|
def clean_zeros(amount)
|
117
118
|
amount[0] == "0" ? amount_sign = "" : amount_sign = "-"
|
118
|
-
amount_integral = amount.scan(
|
119
|
-
amount_decimals = amount.scan(
|
119
|
+
amount_integral = amount.scan(CLEAN_ZEROS_REGEX)[0][0]
|
120
|
+
amount_decimals = amount.scan(CLEAN_ZEROS_REGEX)[0][1]
|
120
121
|
separator = ","
|
121
122
|
amount_sign + amount_integral + separator + amount_decimals
|
122
123
|
end
|
123
124
|
|
124
125
|
def check_structured(number)
|
125
126
|
if number[0] == "1"
|
126
|
-
|
127
|
-
number.scan(@regexp[:clean_structured]).join
|
127
|
+
number.scan(FIELDS[:clean_structured]).join
|
128
128
|
else
|
129
129
|
"not structured"
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
133
|
-
end
|
133
|
+
end
|
data/lib/coda_standard/parser.rb
CHANGED
@@ -1,53 +1,55 @@
|
|
1
1
|
module CodaStandard
|
2
2
|
class Parser
|
3
3
|
attr_reader :transactions, :old_balance, :current_bic, :current_account, :current_transaction
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
def initialize(filename)
|
6
|
+
@filename = filename
|
7
|
+
@transactions = TransactionList.new
|
6
8
|
@current_transaction = Transaction.new
|
7
9
|
end
|
8
10
|
|
9
|
-
def parse
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
11
|
+
def parse
|
12
|
+
File.open(@filename).each do |row|
|
13
|
+
line = Line.new(row)
|
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/
|
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)
|
32
34
|
end
|
33
35
|
end
|
34
36
|
@transactions
|
35
37
|
end
|
36
38
|
|
37
39
|
def set_address(address)
|
38
|
-
@current_transaction.address
|
40
|
+
@current_transaction.address = address[:address]
|
39
41
|
@current_transaction.postcode = address[:postcode]
|
40
|
-
@current_transaction.city
|
41
|
-
@current_transaction.country
|
42
|
+
@current_transaction.city = address[:city]
|
43
|
+
@current_transaction.country = address[:country]
|
42
44
|
end
|
43
45
|
|
44
46
|
def set_account(account)
|
45
|
-
@transactions.current_account
|
47
|
+
@transactions.current_account = account[:account_number]
|
46
48
|
@transactions.current_account_type = account[:account_type]
|
47
49
|
end
|
48
50
|
|
49
|
-
def show
|
50
|
-
parse
|
51
|
+
def show
|
52
|
+
parse
|
51
53
|
puts "**--Transactions--**\n\n"
|
52
54
|
puts "Account: #{@transactions.current_account} Account type: #{@transactions.current_account_type} BIC: #{@transactions.current_bic}"
|
53
55
|
puts "Old balance: #{@transactions.old_balance} \n\n"
|
@@ -60,4 +62,4 @@ module CodaStandard
|
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
63
|
-
end
|
65
|
+
end
|
data/lib/coda_standard.rb
CHANGED
data/spec/parser_spec.rb
CHANGED
@@ -3,9 +3,8 @@ require_relative 'spec_helper'
|
|
3
3
|
describe CodaStandard::Parser do
|
4
4
|
|
5
5
|
before :each do
|
6
|
-
|
7
|
-
@
|
8
|
-
@parser = CodaStandard::Parser.new
|
6
|
+
filename = 'spec/coda.cod'
|
7
|
+
@parser = CodaStandard::Parser.new(filename)
|
9
8
|
end
|
10
9
|
|
11
10
|
describe "initialize" do
|
@@ -16,10 +15,11 @@ describe CodaStandard::Parser do
|
|
16
15
|
|
17
16
|
describe "parse" do
|
18
17
|
before :each do
|
19
|
-
@parser.parse
|
18
|
+
@parser.parse
|
20
19
|
end
|
20
|
+
|
21
21
|
it "returns a Transactions object" do
|
22
|
-
expect(@parser.parse
|
22
|
+
expect(@parser.parse).to be_a(CodaStandard::TransactionList)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -63,7 +63,8 @@ describe CodaStandard::Parser do
|
|
63
63
|
|
64
64
|
describe "show" do
|
65
65
|
it "shows the info from the transactions" do
|
66
|
-
expect{@parser.show
|
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
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
69
70
|
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
|
+
version: 0.1.4
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|