coda_standard 0.1.2 → 0.1.3

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: 642ed89a40b23ef43c468b8087c29f0af3e1bea3
4
- data.tar.gz: d3c4a4a533aad85c8fb64ccd4c414737f85c39d1
3
+ metadata.gz: 4736e6a722c4f15a13d9ca03d58d0aee055173a4
4
+ data.tar.gz: 326312b1f946d0946fa6fae52b8b2285f037cf96
5
5
  SHA512:
6
- metadata.gz: 409f68bb12632332bffe9a980f35bef829896e843c10a128dd03c7a5c3d0eb6f6f7d7adfadd895b60f301b391b20b2fb1a8aeec714d325d302ae4497a8d20ddd
7
- data.tar.gz: 64416cd18dbca8e0f696fc023ef3132e84cc831f9cac51b3a2628d200a4eed543f3b06ee7b51a5ea77a3fc5a9e946cd806c7f4ea9d4fec2e5289c980c33ca094
6
+ metadata.gz: c1eda00743d3e70d3ce79fa2781067bb81c20b3b236f84f1a0465f4dcad8a3665bed5e0bf08971c527a0c3f95382d766ad0c51a6867345d2bbe7ff962a164eed
7
+ data.tar.gz: f72454d377adacc424be90df42cd8107058138ecf46d15ed0254453c59034f35e1c9d47b00fe7b14c6d7fcc769688d73f39359efe97ba713a0f84f74f60ce5f9
data/README.md CHANGED
@@ -35,6 +35,9 @@ You can get different common data from the TransactionList (current_bic, old_bal
35
35
 
36
36
  Shows the transactions info in the terminal
37
37
 
38
+ The info you can get from each transaction is:
39
+ name, currency, bic, address, postcode, city, country, amount, account, entry_date, reference_number and transaction_number
40
+
38
41
  ## Contributing
39
42
 
40
43
  1. Fork it ( https://github.com/Bluesmile82/coda_standard/fork )
@@ -23,6 +23,8 @@ module CodaStandard
23
23
  bban_foreign_account: /(^.{34})/,
24
24
  iban_be_account: /(^.{31})/,
25
25
  iban_foreign_account: /(^.{34})/,
26
+ transaction_number: /^21.{60}(.{15})/,
27
+ clean_structured: /.{3}(.{12})/,
26
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)/
27
29
  }
28
30
  end
@@ -71,6 +73,10 @@ module CodaStandard
71
73
  extract(:address)
72
74
  end
73
75
 
76
+ def transaction_number
77
+ extract(:transaction_number)
78
+ end
79
+
74
80
  private
75
81
 
76
82
  def extract(field)
@@ -82,6 +88,8 @@ module CodaStandard
82
88
  result = clean_account(result)
83
89
  when :old_balance, :amount
84
90
  result = clean_zeros(result)
91
+ when :transaction_number
92
+ result = check_structured(result)
85
93
  end
86
94
  result
87
95
  end
@@ -93,7 +101,7 @@ module CodaStandard
93
101
 
94
102
  def clean_account(account)
95
103
  account_type = account.scan(@regexp[:sep_account])[0][0]
96
- sequence_number = account.scan(@regexp[:sep_account])[0][1]
104
+ # sequence_number = account.scan(@regexp[:sep_account])[0][1]
97
105
  raw_account = account.scan(@regexp[:sep_account])[0][2]
98
106
  case account_type
99
107
  when "0" then account_type = "bban_be_account"
@@ -112,5 +120,14 @@ module CodaStandard
112
120
  separator = ","
113
121
  amount_sign + amount_integral + separator + amount_decimals
114
122
  end
123
+
124
+ def check_structured(number)
125
+ if number[0] == "1"
126
+ structured = true
127
+ number.scan(@regexp[:clean_structured]).join
128
+ else
129
+ "not structured"
130
+ end
131
+ end
115
132
  end
116
133
  end
@@ -20,6 +20,7 @@ module CodaStandard
20
20
  @current_transaction.entry_date = line.entry_date
21
21
  @current_transaction.reference_number = line.reference_number
22
22
  @current_transaction.amount = line.amount
23
+ @current_transaction.transaction_number = line.transaction_number
23
24
  when line.line =~ /^22/
24
25
  @current_transaction.bic = line.bic
25
26
  when line.line =~ /^23/
@@ -51,7 +52,7 @@ module CodaStandard
51
52
  puts "Account: #{@transactions.current_account} Account type: #{@transactions.current_account_type} BIC: #{@transactions.current_bic}"
52
53
  puts "Old balance: #{@transactions.old_balance} \n\n"
53
54
  @transactions.each_with_index do |transaction, index|
54
- puts "-- Transaction n.#{index + 1} in date #{transaction.entry_date}-- \n\n"
55
+ puts "-- Transaction n.#{index + 1} - number #{transaction.transaction_number} - in date #{transaction.entry_date}-- \n\n"
55
56
  puts " RN: #{transaction.reference_number} Account: #{transaction.account} BIC:#{transaction.bic}"
56
57
  puts " Amount: #{transaction.amount} #{transaction.currency}"
57
58
  puts " Name: #{transaction.name}"
@@ -1,5 +1,5 @@
1
1
  module CodaStandard
2
2
  class Transaction
3
- attr_accessor :name, :currency, :bic, :address, :postcode, :city, :country, :amount, :account, :entry_date, :reference_number
3
+ attr_accessor :name, :currency, :bic, :address, :postcode, :city, :country, :amount, :account, :entry_date, :reference_number, :transaction_number
4
4
  end
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module CodaStandard
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/spec/line_spec.rb CHANGED
@@ -2,12 +2,13 @@ require_relative 'spec_helper'
2
2
 
3
3
  describe CodaStandard::Line do
4
4
  before :each do
5
- @line0 = CodaStandard::Line.new("0000031031520005 MMIF SA/EVOCURE GEBABEBB 00538839354 00000 2")
6
- @line1 = CodaStandard::Line.new("10016035918134040 EUR0BE 0000000057900000300315MMIF SA/EVOCURE 017")
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
7
  @line21 = CodaStandard::Line.new("21000100000001500000103 0000000000500000010415001500001101100000834941 31031501601 0")
8
+ @line21b = CodaStandard::Line.new("21000100000001500000103 0000000000500000010415001500001001100000834941 31031501601 0")
8
9
  @line22 = CodaStandard::Line.new("2200010000 GKCCBEBB 1 0")
9
- @line23 = CodaStandard::Line.new("2300010000BE96553242750005 EURCOUREL PASCAL 0 1")
10
- @line32 = CodaStandard::Line.new("3200010001CHAUSSEE DE MALINES 10 1970 WEZEMBEEK-OPPEM 0 0")
10
+ @line23 = CodaStandard::Line.new("2300010000BE53900754703405 EURLASTNM PERSON 0 1")
11
+ @line32 = CodaStandard::Line.new("32000200015 STREET 3654 CITY BELGIQUE 0 0")
11
12
  end
12
13
 
13
14
  describe "current_bic" do
@@ -18,7 +19,7 @@ describe CodaStandard::Line do
18
19
 
19
20
  describe "current_account" do
20
21
  it "extracts the current_account" do
21
- expect(@line1.current_account).to eq({account_number:"035918134040", account_type:"bban_be_account"})
22
+ expect(@line1.current_account).to eq({account_number:"539007547034", account_type:"bban_be_account"})
22
23
  end
23
24
  end
24
25
 
@@ -60,19 +61,32 @@ describe CodaStandard::Line do
60
61
 
61
62
  describe "name" do
62
63
  it "extracts the name" do
63
- expect(@line23.name).to eq("COUREL PASCAL")
64
+ expect(@line23.name).to eq("LASTNM PERSON")
64
65
  end
65
66
  end
66
67
 
67
68
  describe "account" do
68
69
  it "extracts the account" do
69
- expect(@line23.account).to eq("BE96553242750005")
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
70
84
  end
71
85
  end
72
86
 
73
87
  describe "address" do
74
88
  it "extracts the address" do
75
- expect(@line32.address).to eq({:address=>"CHAUSSEE DE MALINES 10", :postcode=>"1970", :city=>"WEZEMBEEK-OPPEM", :country=>nil})
89
+ expect(@line32.address).to eq({:address=>"5 STREET", :postcode=>"3654", :city=>"CITY", :country=>" BELGIQUE"})
76
90
  end
77
91
  end
78
92
 
data/spec/parser_spec.rb CHANGED
@@ -63,7 +63,7 @@ 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(@file_name)}.to output("**--Transactions--**\n\nAccount: 539007547034 Account type: bban_be_account BIC: GEBABEBB\nOld balance: 57900,000 \n\n-- Transaction n.1 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 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
66
+ expect{@parser.show(@file_name)}.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
  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.2
4
+ version: 0.1.3
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-09 00:00:00.000000000 Z
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler