cmxl 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5e0a335b0d8a997acf80ab578362f77f08880b0d7258f3c3af365b71eb53925
4
- data.tar.gz: b2d3c8dd9925866da29d27cc43457652f2fdf377bcd1080feb87d654a88b37e4
3
+ metadata.gz: 41f6f1b53eb060758d035fe5d0b3475b42b12bf10c749418a3b72b3c98482140
4
+ data.tar.gz: 1e5f3ee6fcbbdca480600b029c573ccc614a2adba34e66c440286a99d5be963b
5
5
  SHA512:
6
- metadata.gz: fa0be57b4e8643e1a20f4bb276d7953eb7cc3f16cc3c89286b5ca6fa7e2a9b285b1358424f6904d086315907d1ba77f2d89616980a82bb4360f162e91eaf2477
7
- data.tar.gz: 2990c106239b3f65c35abdc662af7afdba0ba4d539e1e9f3838179d5f238e1b72fbf43b82743bce5a060b291a4a9f28031f3bc4aba9e39f76c155d178d1f1b83
6
+ metadata.gz: 1f4af37922a0e6d14795c7274a64a60697660b6e0f7399947e7bdae6973b4ea3dbe22a3e73e2923004a16ce215577565ac4f609283752401359228d8709e7c57
7
+ data.tar.gz: 0a9aecfe5f17a5bd09dcce8e96c45af26c3d89c79ce505aad9806849e1fbaa082dccb02d562ff8552283a14d6027a4f5b11de3a1237dc790d0c609bdc1f15d1f
@@ -1,3 +1,8 @@
1
+ # 1.4.1
2
+
3
+ - [BUGFIX] changes entry date calculation for transaction
4
+ Thanks to [@grncdr](https://github.com/grncdr)
5
+
1
6
  # 1.4.0
2
7
 
3
8
  - [FEATURE] adds ability to parse non-numerical tags ([#23](https://github.com/railslove/cmxl/issues/23)) \
@@ -59,13 +59,19 @@ module Cmxl
59
59
  end
60
60
 
61
61
  def entry_date
62
- if data['entry_date'] && date
63
- if date.month == 1 && date.month < to_date(data['entry_date'], date.year).month
64
- to_date(data['entry_date'], date.year - 1)
65
- else
66
- to_date(data['entry_date'], date.year)
67
- end
68
- end
62
+ return if !date || !data['entry_date']
63
+
64
+ e_date = to_date(data['entry_date'], date.year)
65
+ # we assume that valuta (date) and entry_date have a close connection. so valuta and entry_date should not be
66
+ # further apart than one month. this leads to some edge cases
67
+
68
+ # valuta is in january while entry_date is in december => entry_date was done the year before
69
+ e_date = to_date(data['entry_date'], date.year - 1) if date.month == 1 && e_date.month == 12
70
+
71
+ # valuta is in december but entry_date is in january => entry_date is actually in the year after valuta
72
+ e_date = to_date(data['entry_date'], date.year + 1) if date.month == 12 && e_date.month == 1
73
+
74
+ e_date
69
75
  end
70
76
 
71
77
  def supplementary
@@ -26,12 +26,9 @@ module Cmxl
26
26
  def parse!
27
27
  self.fields = []
28
28
 
29
- # split transactions, each transaction starts with a colon after a linebreak
30
- # do not remove line breaks within transaction lines as they are used to determine field details
31
- # e.g. :61:-supplementary
32
- source.split("\n:").each(&:strip!).each do |line|
33
- line = ":#{line}" unless line =~ /^:/ # prepend lost : via split
29
+ lines = source.split(/(:[0-9A-Z]{2,3}:)/m).reject(&:empty?).each_slice(2).map(&:join)
34
30
 
31
+ lines.map do |line|
35
32
  if line =~ /\A:86:/
36
33
  if field = fields.last
37
34
  field.add_meta_data(line)
@@ -1,3 +1,3 @@
1
1
  module Cmxl
2
- VERSION = '1.4.0'.freeze
2
+ VERSION = '1.4.1'.freeze
3
3
  end
@@ -1,12 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cmxl::Fields::Transaction do
4
- subject(:debit_transaction) { Cmxl::Fields::Transaction.parse(fixture.first) }
5
- subject(:storno_credit_transaction) { Cmxl::Fields::Transaction.parse(fixture.last) }
4
+ subject(:debit_transaction) { Cmxl::Fields::Transaction.parse(fixture[0]) }
5
+ subject(:storno_credit_transaction) { Cmxl::Fields::Transaction.parse(fixture[1]) }
6
6
  subject(:ocmt_transaction) { Cmxl::Fields::Transaction.parse(fixture_line(:statement_ocmt)) }
7
7
  subject(:ocmt_cghs_transaction) { Cmxl::Fields::Transaction.parse(fixture_line(:statement_ocmt_chgs)) }
8
8
  subject(:supplementary_transaction) { Cmxl::Fields::Transaction.parse(fixture_line(:statement_supplementary_plain)) }
9
9
  subject(:complex_supplementary_transaction) { Cmxl::Fields::Transaction.parse(fixture_line(:statement_supplementary_complex)) }
10
+ subject(:valuta_after_enty_date) { Cmxl::Fields::Transaction.parse(fixture[3]) }
11
+ subject(:entry_before_valuta_transaction) { Cmxl::Fields::Transaction.parse(fixture[2]) }
10
12
 
11
13
  let(:fixture) { fixture_line(:statement_line).split(/\n/) }
12
14
 
@@ -77,4 +79,16 @@ describe Cmxl::Fields::Transaction do
77
79
  it { expect(complex_supplementary_transaction.bank_reference).to eql('HERP-DERP-REF') }
78
80
  it { expect(complex_supplementary_transaction.supplementary.source).to eql('random text / and stuff') }
79
81
  end
82
+
83
+ context 'valuta and entry-date assumptions' do
84
+ it 'entry_date before valuta is recognized correclty when including year-change' do
85
+ expect(entry_before_valuta_transaction.date).to eql(Date.new(2014, 1, 10))
86
+ expect(entry_before_valuta_transaction.entry_date).to eql(Date.new(2013, 12, 24))
87
+ end
88
+
89
+ it 'entry_date after valuta is recognized correctly when including year-change' do
90
+ expect(valuta_after_enty_date.date).to eql(Date.new(2014, 12, 24))
91
+ expect(valuta_after_enty_date.entry_date).to eql(Date.new(2015, 1, 2))
92
+ end
93
+ end
80
94
  end
@@ -1,2 +1,4 @@
1
1
  :61:1409010902DR000000000001,62NTRF0000549855700010//025498557/000001
2
2
  :61:1409010902RCR000000000001,62NTRF0000549855700010//025498557/000001
3
+ :61:1401101224CR000000000001,62NTRF0000549855700010//025498557/000001
4
+ :61:1412240102CR000000000001,62NTRF0000549855700010//025498557/000001
@@ -0,0 +1,11 @@
1
+ :20:131110
2
+ :25:45050050/76198810
3
+ :28:27/01
4
+ :60F:C131016DEM84349,74
5
+ :61:131017D6800,NCHK16703074
6
+ /OCMT/CAD47,11
7
+ :86:106?109075/658?20EREF+000000000193592204?21MREF+CN3R3U?22CRED+DE7
8
+ 600200000132558?23SVWZ+STARTER//8449273399/US?24 22-04-2019T03:46
9
+ :08 Karten?25nr. 5355999999999975 Origi?26nal 49,00 USD 1 EUR/1,
10
+ 12385?27 USD Entgelt 0,44 EUR?30DEUTDEDBFRA?31DE1950070024000402
11
+ 0480?32DEUTSCHE BANK
@@ -120,6 +120,14 @@ describe Cmxl do
120
120
  expect(subject.bic).to eq('10020030')
121
121
  end
122
122
  end
123
+
124
+ describe 'statement with colon right after linebreak' do
125
+ subject { Cmxl.parse(mt940_file('mt940-with-colon-after-line-break')).first.transactions.first }
126
+
127
+ it 'has the right details' do
128
+ expect(subject.to_h['details']).to eq('?109075/658?20EREF+000000000193592204?21MREF+CN3R3U?22CRED+DE7600200000132558?23SVWZ+STARTER//8449273399/US?24 22-04-2019T03:46:08 Karten?25nr. 5355999999999975 Origi?26nal 49,00 USD 1 EUR/1,12385?27 USD Entgelt 0,44 EUR?30DEUTDEDBFRA?31DE19500700240004020480?32DEUTSCHE BANK')
129
+ end
130
+ end
123
131
  end
124
132
 
125
133
  context 'mt942' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmxl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bumann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-24 00:00:00.000000000 Z
11
+ date: 2019-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -165,6 +165,7 @@ files:
165
165
  - spec/fixtures/mt940-deutsche_bank.txt
166
166
  - spec/fixtures/mt940-headers.txt
167
167
  - spec/fixtures/mt940-iso8859-1.txt
168
+ - spec/fixtures/mt940-with-colon-after-line-break.txt
168
169
  - spec/fixtures/mt940-with-detailed-end-balance.txt
169
170
  - spec/fixtures/mt940.txt
170
171
  - spec/fixtures/mt942.txt
@@ -239,6 +240,7 @@ test_files:
239
240
  - spec/fixtures/mt940-deutsche_bank.txt
240
241
  - spec/fixtures/mt940-headers.txt
241
242
  - spec/fixtures/mt940-iso8859-1.txt
243
+ - spec/fixtures/mt940-with-colon-after-line-break.txt
242
244
  - spec/fixtures/mt940-with-detailed-end-balance.txt
243
245
  - spec/fixtures/mt940.txt
244
246
  - spec/fixtures/mt942.txt