cmxl 0.0.6 → 0.0.7

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: ef139423daa5f2df7f4e36f91b99cb9cc0f33a74
4
- data.tar.gz: 3e3809a8d2fd6a073c198e42222e0545ef40d5ea
3
+ metadata.gz: 29c6b73c044ebe4baf36ef42a8740f0d92a8b186
4
+ data.tar.gz: 2a69e78bdea382565fec283e23d90eb1809b5222
5
5
  SHA512:
6
- metadata.gz: 82192a04913840d6ab0e37c19dbfb908a42a249178133bcd2e488441b700ab3526063b823a04e451e54c48374a8ec7a4a4c722369cb319a3a4c86173d39fa82e
7
- data.tar.gz: c3ce22ebff413224d72061e0714b61201a422168d50d2791efe07d77af2cf4dee26e598dcb6822fe2c99a411d1fae96d198df463760526e984dcbae616b98c20
6
+ metadata.gz: 0054825050267f040b34236f2105b798b1aebcf68c51659ebc3396358c75f024e1a021368d9cc1679073a08d28e084e496a167b9443a61cb245d8a289c7e685e
7
+ data.tar.gz: 2fc88b2861fdb09dc48975f538dc4856011194670b818379f93591824c46be8a6a6f1f7db42bebf411b84d4650fe2bf6872053819122eed6985049fb58ead83b
@@ -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
- STATEMENT_SEPARATOR = "\n-"
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(STATEMENT_SEPARATOR).reject { |s| s.strip.empty? }.collect {|s| Cmxl::Statement.new(s.strip) }
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
@@ -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
 
@@ -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
- self.fields << Field.parse(line)
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
- Digest::SHA2.new.update(self.source).to_s
49
+ Digest::SHA2.new.update(self.source).to_s
49
50
  end
50
51
 
51
52
  def reference
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Cmxl
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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.6
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-24 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler