cmxl 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.mdown +3 -0
- data/cmxl.gemspec +1 -0
- data/lib/cmxl/fields/transaction.rb +32 -11
- data/lib/cmxl/version.rb +1 -1
- data/spec/fields/transaction_spec.rb +35 -13
- data/spec/fixtures/lines/statement_line.txt +1 -0
- data/spec/statement_spec.rb +3 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e340ee71a0d76d03da864295d93afb2c812b6464
|
4
|
+
data.tar.gz: 82be1d2e99b73202cb01d5f3dab45d3fd37b401a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d0e77e0ad38165e4ee188f4beb1d96a26e09703a39968a98921763a22d3b4cef27f00d2268909d165a2848fb517826749d24ade78efd7dcdd02c131c4535393
|
7
|
+
data.tar.gz: b4737a5959501989f6046c50064d002a3671be688d1fb8d5430ee8ce8f0637241264df50deb8b42b4fbe76b9d19d2b90ba2ffc4c07c835a5cc54063784f80782
|
data/CHANGELOG.mdown
CHANGED
data/cmxl.gemspec
CHANGED
@@ -2,7 +2,7 @@ module Cmxl
|
|
2
2
|
module Fields
|
3
3
|
class Transaction < Field
|
4
4
|
self.tag = 61
|
5
|
-
self.parser = /^(?<date>\d{6})(?<entry_date>\d{4})?(?<funds_code>[
|
5
|
+
self.parser = /^(?<date>\d{6})(?<entry_date>\d{4})?(?<storno_flag>R?)(?<funds_code>[CD]{1})(?<currency_letter>[a-zA-Z])?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:N|F).{3})(?<reference>NONREF|.{0,16})(?:$|\/\/)(?<bank_reference>.*)/i
|
6
6
|
|
7
7
|
attr_accessor :details
|
8
8
|
|
@@ -15,35 +15,55 @@ module Cmxl
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def credit?
|
18
|
-
|
18
|
+
data['funds_code'].to_s.casecmp('C').zero?
|
19
19
|
end
|
20
20
|
|
21
21
|
def debit?
|
22
|
-
|
22
|
+
data['funds_code'].to_s.casecmp('D').zero?
|
23
|
+
end
|
24
|
+
|
25
|
+
def storno_credit?
|
26
|
+
credit? && storno?
|
27
|
+
end
|
28
|
+
|
29
|
+
def storno_debit?
|
30
|
+
debit? && storno?
|
31
|
+
end
|
32
|
+
|
33
|
+
def storno?
|
34
|
+
!storno_flag.empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def funds_code
|
38
|
+
data.values_at('storno_flag', 'funds_code').join
|
39
|
+
end
|
40
|
+
|
41
|
+
def storno_flag
|
42
|
+
data['storno_flag']
|
23
43
|
end
|
24
44
|
|
25
45
|
def sign
|
26
|
-
|
46
|
+
credit? ? 1 : -1
|
27
47
|
end
|
28
48
|
|
29
49
|
def amount
|
30
|
-
to_amount(
|
50
|
+
to_amount(data['amount'])
|
31
51
|
end
|
32
52
|
|
33
53
|
def amount_in_cents
|
34
|
-
to_amount_in_cents(
|
54
|
+
to_amount_in_cents(data['amount'])
|
35
55
|
end
|
36
56
|
|
37
57
|
def date
|
38
|
-
to_date(
|
58
|
+
to_date(data['date'])
|
39
59
|
end
|
40
60
|
|
41
61
|
def entry_date
|
42
|
-
if
|
43
|
-
if date.month == 1 && date.month < to_date(
|
44
|
-
to_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)
|
45
65
|
else
|
46
|
-
to_date(
|
66
|
+
to_date(data['entry_date'], date.year)
|
47
67
|
end
|
48
68
|
end
|
49
69
|
end
|
@@ -82,6 +102,7 @@ module Cmxl
|
|
82
102
|
'sign' => sign,
|
83
103
|
'debit' => debit?,
|
84
104
|
'credit' => credit?,
|
105
|
+
'storno' => storno?,
|
85
106
|
'funds_code' => funds_code,
|
86
107
|
'swift_code' => swift_code,
|
87
108
|
'reference' => reference,
|
data/lib/cmxl/version.rb
CHANGED
@@ -1,19 +1,41 @@
|
|
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
6
|
|
5
|
-
|
7
|
+
let(:fixture) { fixture_line(:statement_line).split(/\n/) }
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
context 'debit' do
|
10
|
+
it { expect(debit_transaction.date).to eql(Date.new(2014,9,1)) }
|
11
|
+
it { expect(debit_transaction.entry_date).to eql(Date.new(2014,9,2)) }
|
12
|
+
it { expect(debit_transaction.funds_code).to eql('D') }
|
13
|
+
it { expect(debit_transaction.currency_letter).to eql('R') }
|
14
|
+
it { expect(debit_transaction.amount).to eql(1.62) }
|
15
|
+
it { expect(debit_transaction.amount_in_cents).to eql(162) }
|
16
|
+
it { expect(debit_transaction.swift_code).to eql('NTRF') }
|
17
|
+
it { expect(debit_transaction.reference).to eql('0000549855700010') }
|
18
|
+
it { expect(debit_transaction.bank_reference).to eql('025498557/000001') }
|
19
|
+
it { expect(debit_transaction).to_not be_credit }
|
20
|
+
it { expect(debit_transaction).to be_debit }
|
21
|
+
it { expect(debit_transaction).not_to be_storno }
|
22
|
+
it { expect(debit_transaction.sign).to eql(-1) }
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'storno credit' do
|
26
|
+
it { expect(storno_credit_transaction.date).to eql(Date.new(2014,9,1)) }
|
27
|
+
it { expect(storno_credit_transaction.entry_date).to eql(Date.new(2014,9,2)) }
|
28
|
+
it { expect(storno_credit_transaction.funds_code).to eql('RC') }
|
29
|
+
it { expect(storno_credit_transaction.currency_letter).to eql('R') }
|
30
|
+
it { expect(storno_credit_transaction.amount).to eql(1.62) }
|
31
|
+
it { expect(storno_credit_transaction.amount_in_cents).to eql(162) }
|
32
|
+
it { expect(storno_credit_transaction.swift_code).to eql('NTRF') }
|
33
|
+
it { expect(storno_credit_transaction.reference).to eql('0000549855700010') }
|
34
|
+
it { expect(storno_credit_transaction.bank_reference).to eql('025498557/000001') }
|
35
|
+
it { expect(storno_credit_transaction).to be_credit }
|
36
|
+
it { expect(storno_credit_transaction).not_to be_debit }
|
37
|
+
it { expect(storno_credit_transaction).not_to be_storno_debit }
|
38
|
+
it { expect(storno_credit_transaction).to be_storno }
|
39
|
+
it { expect(storno_credit_transaction.sign).to eql(1) }
|
40
|
+
end
|
19
41
|
end
|
data/spec/statement_spec.rb
CHANGED
@@ -27,6 +27,7 @@ describe Cmxl do
|
|
27
27
|
"sign" => -1,
|
28
28
|
"debit" => true,
|
29
29
|
"credit" => false,
|
30
|
+
"storno" => false,
|
30
31
|
"bic" => "HYVEDEMMXXX",
|
31
32
|
"iban" => "HUkkbbbsssskcccccccccccccccx",
|
32
33
|
"name" => "Peter Pan",
|
@@ -85,7 +86,8 @@ describe Cmxl do
|
|
85
86
|
"amount_in_cents" => 162,
|
86
87
|
"sign" => -1,
|
87
88
|
"debit" => true,
|
88
|
-
"credit" => false
|
89
|
+
"credit" => false,
|
90
|
+
"storno" => false
|
89
91
|
})
|
90
92
|
end
|
91
93
|
end
|
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: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bumann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rchardet19
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
179
|
version: '0'
|
166
180
|
requirements: []
|
167
181
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.
|
182
|
+
rubygems_version: 2.5.1
|
169
183
|
signing_key:
|
170
184
|
specification_version: 4
|
171
185
|
summary: Cmxl is your friendly MT940 bank statement parser
|