cmxl 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +136 -0
  6. data/Rakefile +7 -0
  7. data/cmxl.gemspec +24 -0
  8. data/lib/cmxl.rb +20 -0
  9. data/lib/cmxl/field.rb +78 -0
  10. data/lib/cmxl/fields/account_balance.rb +45 -0
  11. data/lib/cmxl/fields/account_identification.rb +12 -0
  12. data/lib/cmxl/fields/available_balance.rb +8 -0
  13. data/lib/cmxl/fields/closing_balance.rb +8 -0
  14. data/lib/cmxl/fields/reference.rb +21 -0
  15. data/lib/cmxl/fields/statement_details.rb +54 -0
  16. data/lib/cmxl/fields/statement_line.rb +47 -0
  17. data/lib/cmxl/fields/statement_number.rb +8 -0
  18. data/lib/cmxl/statement.rb +84 -0
  19. data/lib/cmxl/transaction.rb +91 -0
  20. data/lib/cmxl/version.rb +3 -0
  21. data/spec/fields/account_balance_spec.rb +41 -0
  22. data/spec/fields/account_identification_spec.rb +24 -0
  23. data/spec/fields/available_balance_spec.rb +16 -0
  24. data/spec/fields/closing_balance_spec.rb +15 -0
  25. data/spec/fields/reference_spec.rb +12 -0
  26. data/spec/fields/statement_details_spec.rb +40 -0
  27. data/spec/fields/statement_number_spec.rb +10 -0
  28. data/spec/fields/statment_line_spec.rb +19 -0
  29. data/spec/fields/unknown_spec.rb +9 -0
  30. data/spec/fixtures/lines/account_balance_credit.txt +1 -0
  31. data/spec/fixtures/lines/account_balance_debit.txt +1 -0
  32. data/spec/fixtures/lines/account_identification_iban.txt +1 -0
  33. data/spec/fixtures/lines/account_identification_legacy.txt +1 -0
  34. data/spec/fixtures/lines/available_balance.txt +1 -0
  35. data/spec/fixtures/lines/closing_balance.txt +1 -0
  36. data/spec/fixtures/lines/reference.txt +1 -0
  37. data/spec/fixtures/lines/statement_details.txt +1 -0
  38. data/spec/fixtures/lines/statement_line.txt +1 -0
  39. data/spec/fixtures/lines/statement_number.txt +1 -0
  40. data/spec/fixtures/mt940.txt +75 -0
  41. data/spec/mt940_parsing_spec.rb +44 -0
  42. data/spec/spec_helper.rb +30 -0
  43. data/spec/support/fixtures.rb +7 -0
  44. data/spec/transaction_spec.rb +28 -0
  45. metadata +155 -0
@@ -0,0 +1 @@
1
+ :60F:D140829EUR000000000147,64
@@ -0,0 +1 @@
1
+ :25:PL25106000760000888888888888
@@ -0,0 +1 @@
1
+ :25:70011110/4005287001EUR
@@ -0,0 +1 @@
1
+ :64:D140901EUR000000000003,66
@@ -0,0 +1 @@
1
+ :62F:C140901EUR000000000137,00
@@ -0,0 +1 @@
1
+ :20:D140902049
@@ -0,0 +1 @@
1
+ :86:171?00SEPA LASTSCHRIFT KUNDE?10281?20EREF+TRX-0A4A47C3-F846-4729?21-8A1B-5DF620F?22MREF+CAC97D2144174318AC18D9?23BF815BD4FB?24CRED+DE98ZZZ09999999999?25SVWZ+FOO TRX-0A4A47C3-F84?266-4729-8A1B-5DF620F?30HYVEDEMMXXX?31HUkkbbbsssskcccccccccccccccx?32Peter Pan?34171
@@ -0,0 +1 @@
1
+ :61:1409010902DR000000000001,62NTRF0000549855700010//025498557/000001
@@ -0,0 +1 @@
1
+ :28C:00035/001
@@ -0,0 +1,75 @@
1
+ :20:131110
2
+ :25:45050050/76198810
3
+ :28:27/01
4
+ :60F:C131016DEM84349,74
5
+ :61:131017D6800,NCHK16703074
6
+ :86:999PN5477SCHECK-NR. 0000016703074
7
+ :61:131017D620,3NSTON
8
+ :86:999PN0911DAUERAUFTR.NR. 14
9
+ :61:131017C18500,NCLRN
10
+ :86:999PN2406SCHECK
11
+ :61:131015D14220,NBOEN
12
+ :86:999PN0920WECHSEL
13
+ :61:131017D1507,NTRFN
14
+ :86:999PN0920SCHNELLUEB
15
+ :61:131024C4200,NMSCN
16
+ :86:999PN2506AUSSENH. NR. 1
17
+ :61:131017D19900,NTRFN
18
+ :86:999PN0907UEBERTRAG
19
+ :61:131017D400,NTRFN
20
+ :86:999PN0891BTX
21
+ :61:131018C3656,74NMSCN
22
+ :86:999PN0850EINZAHLG.N
23
+ :61:131019C23040,NMSCN
24
+ :86:999PN0812LT.ANLAGE
25
+ :61:131027D5862,14NCHKN
26
+ :86:999PN5329AUSLSCHECK
27
+ :62F:C131017DEM84437,04
28
+
29
+ -
30
+
31
+ :20:1234567
32
+ :21:9876543210
33
+ :25:10020030/1234567
34
+ :28C:5/1
35
+ :60F:C021101EUR2187,95
36
+ :61:0211011102DR800,NSTONONREF//55555
37
+ :86:008?00DAUERAUFTRAG?100599?20Miete November?3010020030?31234567?32MUELLER?34339
38
+ :61:0211021102CR3000,NTRFNONREF//55555
39
+ :86:051?00UEBERWEISUNG?100599?20Gehalt Oktob
40
+ er
41
+ ?21Firma
42
+ Mustermann
43
+ GmbH?3050060400?31084756
44
+ 4700?32MUELLER?34339
45
+ :62F:C021131EUR4387,95
46
+
47
+ -
48
+
49
+ :20:TELEWIZORY S.A.
50
+ :25:BPHKPLPK/320000546101
51
+ :28C:00084/001
52
+ :60F:C031002PLN40000,00
53
+ :61:0310201020C20000,00FMSCNONREF//8327000090031789
54
+ Card transaction
55
+ :86: 020?00Wyplata-(dysp/przel)?2008106000760000777777777777?2115617?
56
+ 22INFO INFO INFO INFO INFO INFO 1 END?23INFO INFO INFO INFO INFO
57
+ INFO 2 END?24ZAPLATA ZA FABRYKATY DO TUB?25 - 200 S ZTUK, TRANZY
58
+ STORY-?26300 SZT GR544 I OPORNIKI-5?2700 SZT GTX847 FAKTURA 333/
59
+ 2?28003.?3010600076?310000777777777777?32HUTA SZKLA TOPIC UL
60
+ PRZEMY?33SLOWA 67 32-669 WROCLAW?38PL081060007600007777777
61
+ 77777
62
+ :61:0310201020D10000,00FTRFREF 25611247//8327000090031790
63
+ Transfer
64
+ :86: 020?00Wyplata-(dysp/przel)?2008106000760000777777777777?2115617?
65
+ 22INFO INFO INFO INFO INFO INFO 1 END?23INFO INFO INFO INFO INFO
66
+ INFO 2 END?24ZAPLATA ZA FABRYKATY DO TUB?25 - 200 S ZTUK, TRANZY
67
+ STORY-?26300 SZT GR544 I OPORNIKI-5?2700 SZT GTX847 FAKTURA 333/
68
+ 2?28003.?3010600076?310000777777777777?38PL081060007600007777777
69
+ 77777
70
+ :61:0310201020C40,00FTRFNONREF//8327000090031791
71
+ Interest credit
72
+ :86: 844?00Uznanie kwotą odsetek?20Odsetki od lokaty nr 101000?21022086
73
+ :62F:C020325PLN50040,00
74
+
75
+ -
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'parsing a statement' do
4
+ context 'first example' do
5
+ subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[0] }
6
+ it { expect(subject.reference).to eql('131110') }
7
+ it { expect(subject.opening_balance.amount_in_cents).to eql(8434974) }
8
+ it { expect(subject.closing_balance.amount_in_cents).to eql(8443704) }
9
+ it { expect(subject.generation_date).to eql(Date.new(2013, 11, 10)) }
10
+ it { expect(subject.transactions.count).to eql(11) }
11
+ end
12
+
13
+ context 'second example' do
14
+ subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[1] }
15
+ it { expect(subject.reference).to eql('1234567') }
16
+ it { expect(subject.opening_balance.amount_in_cents).to eql(218795) }
17
+ it { expect(subject.closing_balance.amount_in_cents).to eql(438795) }
18
+ it { expect(subject.generation_date).to eql('123456') }
19
+ it { expect(subject.reference).to eql("1234567") }
20
+ it { expect(subject.transactions.count).to eql(2) }
21
+ it { expect(subject.transactions.first.description).to eql('DAUERAUFTRAG') }
22
+ it { expect(subject.transactions.first.information).to eql('Miete November') }
23
+ it { expect(subject.transactions.first.name).to eql('MUELLER') }
24
+ it { expect(subject.transactions.first.bic).to eql('10020030') }
25
+ it { expect(subject.transactions.first.iban).to eql('234567') }
26
+ end
27
+
28
+ context 'third example' do
29
+ subject { Cmxl.parse(mt940_file(), :encoding => 'ISO-8859-1', :universal_newline => true)[2] }
30
+ it { expect(subject.reference).to eql('TELEWIZORY S.A.') }
31
+ it { expect(subject.opening_balance.amount_in_cents).to eql(4000000) }
32
+ it { expect(subject.closing_balance.amount_in_cents).to eql(5004000) }
33
+ it { expect(subject.reference).to eql("TELEWIZORY S.A.") }
34
+ it { expect(subject.transactions.count).to eql(3) }
35
+ it { expect(subject.transactions.first.description).to eql('Wyplata-(dysp/przel)') }
36
+ it { expect(subject.transactions.first.information).to eql('0810600076000077777777777715617INFO INFO INFO INFO INFO INFO 1 ENDINFO INFO INFO INFO INFOINFO 2 ENDZAPLATA ZA FABRYKATY DO TUB - 200 S ZTUK, TRANZYSTORY-300 SZT GR544 I OPORNIKI-500 SZT GTX847 FAKTURA 333/2003.') }
37
+ it { expect(subject.transactions.first.name).to eql('HUTA SZKLA TOPIC ULPRZEMYSLOWA 67 32-669 WROCLAW') }
38
+ it { expect(subject.transactions.first.bic).to eql('10600076') }
39
+ it { expect(subject.transactions.first.iban).to eql('PL08106000760000777777777777') }
40
+ it { expect(subject.transactions.first.sepa).to eql({}) }
41
+ end
42
+
43
+
44
+ end
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'cmxl'
5
+
6
+ puts File.join(File.dirname(__FILE__), "support/**/*.rb").to_s
7
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+
13
+ if config.files_to_run.one?
14
+ config.default_formatter = 'doc'
15
+ end
16
+
17
+ config.profile_examples = 3
18
+
19
+ config.order = :random
20
+ Kernel.srand config.seed
21
+
22
+ config.expect_with :rspec do |expectations|
23
+ expectations.syntax = :expect
24
+ end
25
+
26
+ config.mock_with :rspec do |mocks|
27
+ mocks.syntax = :expect
28
+ mocks.verify_partial_doubles = true
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ def fixture_line(name)
2
+ File.read(File.join(File.dirname(__FILE__), '../fixtures/lines', "#{name}.txt"))
3
+ end
4
+
5
+ def mt940_file(name='mt940')
6
+ File.read(File.join(File.dirname(__FILE__), '../fixtures', "#{name}.txt"))
7
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cmxl::Transaction do
4
+
5
+ context 'with details' do
6
+ subject { Cmxl::Transaction.new( fixture_line(:statement_line), fixture_line(:statement_details) ) }
7
+ it { expect(subject).to be_debit }
8
+ it { expect(subject).to_not be_credit }
9
+ it { expect(subject.funds_code).to eql('D') }
10
+ it { expect(subject.date).to eql(Date.new(2014,9,1))}
11
+ it { expect(subject.entry_date).to eql(Date.new(2014,9,2))}
12
+ it { expect(subject.amount).to eql(-1.62)}
13
+ it { expect(subject.statement_line.amount).to eql(-1.62)}
14
+ it { expect(subject.amount_in_cents).to eql(-162)}
15
+ it { expect(subject.to_h).to eql({"date"=>Date.new(2014,9,1), "entry_date"=>Date.new(2014,9,2), "funds_code"=>"D", "currency_letter"=>"R", "amount"=>-1.62, "swift_code"=>"NTRF", "reference"=>"0000549855700010", "bank_reference"=>"025498557/000001", "amount_in_cents"=>-162, "sign"=>-1, "debit"=>true, "credit"=>false, "bic"=>"HYVEDEMMXXX", "iban"=>"HUkkbbbsssskcccccccccccccccx", "name"=>"Peter Pan", "sepa"=>{"EREF"=>"TRX-0A4A47C3-F846-4729-8A1B-5DF620F", "MREF"=>"CAC97D2144174318AC18D9BF815BD4FB", "CRED"=>"DE98ZZZ09999999999", "SVWZ"=>"FOO TRX-0A4A47C3-F846-4729-8A1B-5DF620F"}, "information"=>"EREF+TRX-0A4A47C3-F846-4729-8A1B-5DF620FMREF+CAC97D2144174318AC18D9BF815BD4FBCRED+DE98ZZZ09999999999SVWZ+FOO TRX-0A4A47C3-F846-4729-8A1B-5DF620F", "description"=>"SEPA LASTSCHRIFT KUNDE", "sub_fields"=>{"00"=>"SEPA LASTSCHRIFT KUNDE", "10"=>"281", "20"=>"EREF+TRX-0A4A47C3-F846-4729", "21"=>"-8A1B-5DF620F", "22"=>"MREF+CAC97D2144174318AC18D9", "23"=>"BF815BD4FB", "24"=>"CRED+DE98ZZZ09999999999", "25"=>"SVWZ+FOO TRX-0A4A47C3-F84", "26"=>"6-4729-8A1B-5DF620F", "30"=>"HYVEDEMMXXX", "31"=>"HUkkbbbsssskcccccccccccccccx", "32"=>"Peter Pan", "34"=>"171"}, "transaction_code"=>"171", "details"=>"?00SEPA LASTSCHRIFT KUNDE?10281?20EREF+TRX-0A4A47C3-F846-4729?21-8A1B-5DF620F?22MREF+CAC97D2144174318AC18D9?23BF815BD4FB?24CRED+DE98ZZZ09999999999?25SVWZ+FOO TRX-0A4A47C3-F84?266-4729-8A1B-5DF620F?30HYVEDEMMXXX?31HUkkbbbsssskcccccccccccccccx?32Peter Pan?34171"}) }
16
+ end
17
+
18
+ context 'without details' do
19
+ subject { Cmxl::Transaction.new( fixture_line(:statement_line) ) }
20
+ it { expect(subject).to be_debit }
21
+ it { expect(subject).to_not be_credit }
22
+ it { expect(subject.date).to eql(Date.new(2014,9,1))}
23
+ it { expect(subject.entry_date).to eql(Date.new(2014,9,2))}
24
+ it { expect(subject.amount).to eql(-1.62)}
25
+ it { expect(subject.amount_in_cents).to eql(-162)}
26
+ it { expect(subject.to_h).to eql({"date"=>Date.new(2014,9,1), "entry_date"=>Date.new(2014,9,2), "funds_code"=>"D", "currency_letter"=>"R", "amount"=>-1.62, "swift_code"=>"NTRF", "reference"=>"0000549855700010", "bank_reference"=>"025498557/000001", "amount_in_cents"=>-162, "sign"=>-1, "debit"=>true, "credit"=>false}) }
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmxl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bumann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Cmxl provides an extensible and customizable parser for the MT940 bank
56
+ statement format.
57
+ email:
58
+ - michael@railslove.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - cmxl.gemspec
69
+ - lib/cmxl.rb
70
+ - lib/cmxl/field.rb
71
+ - lib/cmxl/fields/account_balance.rb
72
+ - lib/cmxl/fields/account_identification.rb
73
+ - lib/cmxl/fields/available_balance.rb
74
+ - lib/cmxl/fields/closing_balance.rb
75
+ - lib/cmxl/fields/reference.rb
76
+ - lib/cmxl/fields/statement_details.rb
77
+ - lib/cmxl/fields/statement_line.rb
78
+ - lib/cmxl/fields/statement_number.rb
79
+ - lib/cmxl/statement.rb
80
+ - lib/cmxl/transaction.rb
81
+ - lib/cmxl/version.rb
82
+ - spec/fields/account_balance_spec.rb
83
+ - spec/fields/account_identification_spec.rb
84
+ - spec/fields/available_balance_spec.rb
85
+ - spec/fields/closing_balance_spec.rb
86
+ - spec/fields/reference_spec.rb
87
+ - spec/fields/statement_details_spec.rb
88
+ - spec/fields/statement_number_spec.rb
89
+ - spec/fields/statment_line_spec.rb
90
+ - spec/fields/unknown_spec.rb
91
+ - spec/fixtures/lines/account_balance_credit.txt
92
+ - spec/fixtures/lines/account_balance_debit.txt
93
+ - spec/fixtures/lines/account_identification_iban.txt
94
+ - spec/fixtures/lines/account_identification_legacy.txt
95
+ - spec/fixtures/lines/available_balance.txt
96
+ - spec/fixtures/lines/closing_balance.txt
97
+ - spec/fixtures/lines/reference.txt
98
+ - spec/fixtures/lines/statement_details.txt
99
+ - spec/fixtures/lines/statement_line.txt
100
+ - spec/fixtures/lines/statement_number.txt
101
+ - spec/fixtures/mt940.txt
102
+ - spec/mt940_parsing_spec.rb
103
+ - spec/spec_helper.rb
104
+ - spec/support/fixtures.rb
105
+ - spec/transaction_spec.rb
106
+ homepage: http://railslove.com
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Cmxl is your friendly MT940 bank statement parser
130
+ test_files:
131
+ - spec/fields/account_balance_spec.rb
132
+ - spec/fields/account_identification_spec.rb
133
+ - spec/fields/available_balance_spec.rb
134
+ - spec/fields/closing_balance_spec.rb
135
+ - spec/fields/reference_spec.rb
136
+ - spec/fields/statement_details_spec.rb
137
+ - spec/fields/statement_number_spec.rb
138
+ - spec/fields/statment_line_spec.rb
139
+ - spec/fields/unknown_spec.rb
140
+ - spec/fixtures/lines/account_balance_credit.txt
141
+ - spec/fixtures/lines/account_balance_debit.txt
142
+ - spec/fixtures/lines/account_identification_iban.txt
143
+ - spec/fixtures/lines/account_identification_legacy.txt
144
+ - spec/fixtures/lines/available_balance.txt
145
+ - spec/fixtures/lines/closing_balance.txt
146
+ - spec/fixtures/lines/reference.txt
147
+ - spec/fixtures/lines/statement_details.txt
148
+ - spec/fixtures/lines/statement_line.txt
149
+ - spec/fixtures/lines/statement_number.txt
150
+ - spec/fixtures/mt940.txt
151
+ - spec/mt940_parsing_spec.rb
152
+ - spec/spec_helper.rb
153
+ - spec/support/fixtures.rb
154
+ - spec/transaction_spec.rb
155
+ has_rdoc: