cmxl 0.0.6 → 0.0.7
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 +4 -4
- data/lib/cmxl.rb +5 -2
- data/lib/cmxl/field.rb +1 -1
- data/lib/cmxl/statement.rb +3 -2
- data/lib/cmxl/transaction.rb +5 -0
- data/lib/cmxl/version.rb +1 -1
- data/spec/transaction_spec.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29c6b73c044ebe4baf36ef42a8740f0d92a8b186
|
4
|
+
data.tar.gz: 2a69e78bdea382565fec283e23d90eb1809b5222
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0054825050267f040b34236f2105b798b1aebcf68c51659ebc3396358c75f024e1a021368d9cc1679073a08d28e084e496a167b9443a61cb245d8a289c7e685e
|
7
|
+
data.tar.gz: 2fc88b2861fdb09dc48975f538dc4856011194670b818379f93591824c46be8a6a6f1f7db42bebf411b84d4650fe2bf6872053819122eed6985049fb58ead83b
|
data/lib/cmxl.rb
CHANGED
@@ -5,7 +5,10 @@ require 'cmxl/statement'
|
|
5
5
|
require 'cmxl/transaction'
|
6
6
|
Dir[File.join(File.dirname(__FILE__), 'cmxl/fields', '*.rb')].each { |f| require f; }
|
7
7
|
module Cmxl
|
8
|
-
|
8
|
+
def self.config
|
9
|
+
@config
|
10
|
+
end
|
11
|
+
@config = { :statement_separator => /\n-.\n/m, :raise_line_format_errors => true }
|
9
12
|
|
10
13
|
# Public: Parse a MT940 string
|
11
14
|
#
|
@@ -27,6 +30,6 @@ module Cmxl
|
|
27
30
|
data.encode!('UTF-8', options) if !options.empty?
|
28
31
|
end
|
29
32
|
|
30
|
-
data.split(
|
33
|
+
data.split(self.config[:statement_separator]).reject { |s| s.strip.empty? }.collect {|s| Cmxl::Statement.new(s.strip) }
|
31
34
|
end
|
32
35
|
end
|
data/lib/cmxl/field.rb
CHANGED
@@ -48,7 +48,7 @@ module Cmxl
|
|
48
48
|
tag, modifier, content = $1, $2, $3
|
49
49
|
Field.parsers[tag.to_s].new(content, modifier, tag)
|
50
50
|
else
|
51
|
-
raise LineFormatError, "Wrong line format: #{line.dump}"
|
51
|
+
raise LineFormatError, "Wrong line format: #{line.dump}" if Cmxl.config[:raise_line_format_errors]
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
data/lib/cmxl/statement.rb
CHANGED
@@ -35,7 +35,8 @@ module Cmxl
|
|
35
35
|
elsif line.match(/\A:86:/) && !self.transactions.last.nil?
|
36
36
|
self.transactions.last.details = line
|
37
37
|
else
|
38
|
-
|
38
|
+
field = Field.parse(line)
|
39
|
+
self.fields << field unless field.nil?
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -45,7 +46,7 @@ module Cmxl
|
|
45
46
|
#
|
46
47
|
# Retruns the SHA2 of the source
|
47
48
|
def sha
|
48
|
-
|
49
|
+
Digest::SHA2.new.update(self.source).to_s
|
49
50
|
end
|
50
51
|
|
51
52
|
def reference
|
data/lib/cmxl/transaction.rb
CHANGED
@@ -15,6 +15,10 @@ module Cmxl
|
|
15
15
|
@details = Cmxl::Fields::StatementDetails.parse(line) unless line.nil?
|
16
16
|
end
|
17
17
|
|
18
|
+
def sha
|
19
|
+
Digest::SHA2.new.update(self.statement_line.source).to_s
|
20
|
+
end
|
21
|
+
|
18
22
|
def debit?
|
19
23
|
self.statement_line.debit?
|
20
24
|
end
|
@@ -78,6 +82,7 @@ module Cmxl
|
|
78
82
|
|
79
83
|
def to_h
|
80
84
|
{}.tap do |h|
|
85
|
+
h['sha'] = self.sha
|
81
86
|
h.merge!(self.statement_line.to_h)
|
82
87
|
h.merge!(self.details.to_h) if self.details
|
83
88
|
end
|
data/lib/cmxl/version.rb
CHANGED
data/spec/transaction_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe Cmxl::Transaction do
|
|
12
12
|
it { expect(subject.amount).to eql(1.62)}
|
13
13
|
it { expect(subject.statement_line.amount).to eql(1.62)}
|
14
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"}) }
|
15
|
+
it { expect(subject.to_h).to eql({"date"=>Date.new(2014,9,1), "sha" => "3c5e65aa3d3878b06b58b6f1ae2f3693004dfb04e3ab7119a1c1244e612293da", "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
16
|
end
|
17
17
|
|
18
18
|
context 'without details' do
|
@@ -23,6 +23,6 @@ describe Cmxl::Transaction do
|
|
23
23
|
it { expect(subject.entry_date).to eql(Date.new(2014,9,2))}
|
24
24
|
it { expect(subject.amount).to eql(1.62)}
|
25
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}) }
|
26
|
+
it { expect(subject.to_h).to eql({"date"=>Date.new(2014,9,1), "sha" => "3c5e65aa3d3878b06b58b6f1ae2f3693004dfb04e3ab7119a1c1244e612293da", "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
27
|
end
|
28
28
|
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.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bumann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|