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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd3e4666e761be27044a4b4e97aabb85ad3d714d
4
- data.tar.gz: 2333bb6d9680fbf7ffafd4488f53760cbce29960
3
+ metadata.gz: e340ee71a0d76d03da864295d93afb2c812b6464
4
+ data.tar.gz: 82be1d2e99b73202cb01d5f3dab45d3fd37b401a
5
5
  SHA512:
6
- metadata.gz: 3bbb768c8b133798c7208f38d62def5b8282661c8eca73a0178eea1826170e1d69bdc200b23ae42b30af38e738368d7641f2babe3c178fc8b5752ff58e0348b7
7
- data.tar.gz: 5fcd0c23e6bdbdb8b1c3465089c76025dc19bce761eb7f7b848287ae82a5138d669857c1719fbc345f0df5377ab69889c7387b4c5a03ab56c9a4c331cbfb5c23
6
+ metadata.gz: 5d0e77e0ad38165e4ee188f4beb1d96a26e09703a39968a98921763a22d3b4cef27f00d2268909d165a2848fb517826749d24ade78efd7dcdd02c131c4535393
7
+ data.tar.gz: b4737a5959501989f6046c50064d002a3671be688d1fb8d5430ee8ce8f0637241264df50deb8b42b4fbe76b9d19d2b90ba2ffc4c07c835a5cc54063784f80782
@@ -1,3 +1,6 @@
1
+ # 0.2.2
2
+ * [FEATURE] adds support for storno transactions (#14)
3
+
1
4
  # 0.2.1
2
5
  * addressing an bug that occoured for transactions submitted end of
3
6
  but were fetched in the new year -> those ended up with the wrong year
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec", '~>3.0'
26
26
  spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "pry"
27
28
 
28
29
  spec.add_dependency "rchardet19"
29
30
  end
@@ -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>[a-zA-Z])(?<currency_letter>[a-zA-Z])?(?<amount>\d{1,12},\d{0,2})(?<swift_code>(?:N|F).{3})(?<reference>NONREF|.{0,16})(?:$|\/\/)(?<bank_reference>.*)/i
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
- self.data['funds_code'].to_s.upcase == 'C'
18
+ data['funds_code'].to_s.casecmp('C').zero?
19
19
  end
20
20
 
21
21
  def debit?
22
- !credit?
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
- self.credit? ? 1 : -1
46
+ credit? ? 1 : -1
27
47
  end
28
48
 
29
49
  def amount
30
- to_amount(self.data['amount'])
50
+ to_amount(data['amount'])
31
51
  end
32
52
 
33
53
  def amount_in_cents
34
- to_amount_in_cents(self.data['amount'])
54
+ to_amount_in_cents(data['amount'])
35
55
  end
36
56
 
37
57
  def date
38
- to_date(self.data['date'])
58
+ to_date(data['date'])
39
59
  end
40
60
 
41
61
  def entry_date
42
- if self.data['entry_date'] && self.date
43
- if date.month == 1 && date.month < to_date(self.data['entry_date'], self.date.year).month
44
- to_date(self.data['entry_date'], self.date.year - 1)
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(self.data['entry_date'], self.date.year)
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,
@@ -1,3 +1,3 @@
1
1
  module Cmxl
2
- VERSION = "0.2.1"
2
+ VERSION = '0.2.2'
3
3
  end
@@ -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
- subject { Cmxl::Fields::Transaction.parse(fixture_line(:statement_line)) }
7
+ let(:fixture) { fixture_line(:statement_line).split(/\n/) }
6
8
 
7
- it { expect(subject.date).to eql(Date.new(2014,9,1)) }
8
- it { expect(subject.entry_date).to eql(Date.new(2014,9,2)) }
9
- it { expect(subject.funds_code).to eql('D') }
10
- it { expect(subject.currency_letter).to eql('R') }
11
- it { expect(subject.amount).to eql(1.62) }
12
- it { expect(subject.amount_in_cents).to eql(162) }
13
- it { expect(subject.swift_code).to eql('NTRF') }
14
- it { expect(subject.reference).to eql('0000549855700010') }
15
- it { expect(subject.bank_reference).to eql('025498557/000001') }
16
- it { expect(subject).to_not be_credit }
17
- it { expect(subject).to be_debit }
18
- it { expect(subject.sign).to eql(-1) }
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
@@ -1 +1,2 @@
1
1
  :61:1409010902DR000000000001,62NTRF0000549855700010//025498557/000001
2
+ :61:1409010902RCR000000000001,62NTRF0000549855700010//025498557/000001
@@ -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.1
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-02-17 00:00:00.000000000 Z
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.6.14
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