camt_parser 1.1.0 → 2.0.0

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: 89b432e8beb46ea683a5d897d11a3e3f7a923c6b
4
- data.tar.gz: c90fca06cf5c7c2758ff54de9b5621e4caefc561
3
+ metadata.gz: 683b4dfccdf419dbd3dfd37e7a4002d354283995
4
+ data.tar.gz: 87c93c3d59bc8f83d44b7d02323fdfe044cf5e2d
5
5
  SHA512:
6
- metadata.gz: 1975140e3c8293086a96811e6c63f0e2cfb32169866391ab0191cc96d0c71fecb5e66f35796830f481e43e8788dc0d85088b9e2c9a410d26ccbb7cd1415e2273
7
- data.tar.gz: 6c9d7648926d601d6afb9982b9fb28a6f5af9b46c6f53139a8f1d4d00ad7c368c78ff76762a7244e84330e9230228d4814e9c45b72261644607b7161649cf5d1
6
+ metadata.gz: 0f02b7ecd0a390a709831cbbfe58494f5aa69251b1cf3930f4fe919d297a8f2b87c1c4239899f2b895d25636f12c26fe3ae21d927d719ced342953a6cef2471f
7
+ data.tar.gz: aad82828f6b3735eff91d5adfbcc1c3d846a0360331111a556be4b1fa60fc460280d2b3bf31e7763ff9f0e0992d2361e979ad08f9b7623952e013d666594eda2
@@ -5,19 +5,19 @@ module CamtParser
5
5
  end
6
6
 
7
7
  def name
8
- @name ||= @xml_data.xpath('TxDtls/RltdPties/Cdtr/Nm/text()').text
8
+ @name ||= @xml_data.xpath('RltdPties/Cdtr/Nm/text()').text
9
9
  end
10
10
 
11
11
  def iban
12
- @iban ||= @xml_data.xpath('TxDtls/RltdPties/CdtrAcct/Id/IBAN/text()').text
12
+ @iban ||= @xml_data.xpath('RltdPties/CdtrAcct/Id/IBAN/text()').text
13
13
  end
14
14
 
15
15
  def bic
16
- @bic ||= @xml_data.xpath('TxDtls/RltdAgts/CdtrAgt/FinInstnId/BIC/text()').text
16
+ @bic ||= @xml_data.xpath('RltdAgts/CdtrAgt/FinInstnId/BIC/text()').text
17
17
  end
18
18
 
19
19
  def bank_name
20
- @bank_name ||= @xml_data.xpath('TxDtls/RltdAgts/CdtrAgt/FinInstnId/Nm/text()').text
20
+ @bank_name ||= @xml_data.xpath('RltdAgts/CdtrAgt/FinInstnId/Nm/text()').text
21
21
  end
22
22
  end
23
23
  end
@@ -5,19 +5,19 @@ module CamtParser
5
5
  end
6
6
 
7
7
  def name
8
- @name ||= @xml_data.xpath('TxDtls/RltdPties/Dbtr/Nm/text()').text
8
+ @name ||= @xml_data.xpath('RltdPties/Dbtr/Nm/text()').text
9
9
  end
10
10
 
11
11
  def iban
12
- @iban ||= @xml_data.xpath('TxDtls/RltdPties/DbtrAcct/Id/IBAN/text()').text
12
+ @iban ||= @xml_data.xpath('RltdPties/DbtrAcct/Id/IBAN/text()').text
13
13
  end
14
14
 
15
15
  def bic
16
- @bic ||= @xml_data.xpath('TxDtls/RltdAgts/DbtrAgt/FinInstnId/BIC/text()').text
16
+ @bic ||= @xml_data.xpath('RltdAgts/DbtrAgt/FinInstnId/BIC/text()').text
17
17
  end
18
18
 
19
19
  def bank_name
20
- @bank_name ||= @xml_data.xpath('TxDtls/RltdAgts/DbtrAgt/FinInstnId/Nm/text()').text
20
+ @bank_name ||= @xml_data.xpath('RltdAgts/DbtrAgt/FinInstnId/Nm/text()').text
21
21
  end
22
22
  end
23
23
  end
@@ -29,18 +29,14 @@ module CamtParser
29
29
  @booking_date ||= Date.parse(@xml_data.xpath('BookgDt/Dt/text()').text)
30
30
  end
31
31
 
32
- def creditor
33
- @creditor ||= CamtParser::Creditor.new(@xml_data.xpath('NtryDtls'))
32
+ def transactions
33
+ @transactions ||= parse_transactions
34
34
  end
35
35
 
36
36
  def credit?
37
37
  !debit
38
38
  end
39
39
 
40
- def debitor
41
- @debitor ||= CamtParser::Debitor.new(@xml_data.xpath('NtryDtls'))
42
- end
43
-
44
40
  def debit?
45
41
  debit
46
42
  end
@@ -54,58 +50,20 @@ module CamtParser
54
50
  end
55
51
  alias_method :description, :additional_information
56
52
 
57
- def remittance_information
58
- @remittance_information ||= begin
59
- if (x = @xml_data.xpath('NtryDtls/TxDtls/RmtInf/Ustrd')).empty?
60
- nil
61
- else
62
- x.collect(&:content).join(' ')
63
- end
64
- end
65
- end
66
-
67
- def name
68
- credit? ? debitor.name : creditor.name
69
- end
70
-
71
- def iban
72
- credit? ? debitor.iban : creditor.iban
73
- end
74
-
75
- def bic
76
- credit? ? debitor.bic : creditor.bic
77
- end
78
-
79
- def swift_code
80
- @swift_code ||= @xml_data.xpath('NtryDtls/TxDtls/BkTxCd/Prtry/Cd/text()').text.split('+')[0]
81
- end
82
-
83
- def reference
84
- @reference ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/InstrId/text()').text
85
- end
53
+ private
86
54
 
87
- def bank_reference # May be missing
88
- @bank_reference ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/AcctSvcrRef/text()').text
89
- end
55
+ def parse_transactions
56
+ transaction_details = @xml_data.xpath('NtryDtls/TxDtls')
90
57
 
91
- def end_to_end_reference # May be missing
92
- @end_to_end_reference ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/EndToEndId/text()').text
93
- end
58
+ amt = nil
59
+ ccy = nil
94
60
 
95
- def mandate_reference # May be missing
96
- @mandate_reference ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/MndtId/text()').text
97
- end
98
-
99
- def transaction_id # May be missing
100
- @transaction_id ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/TxId/text()').text
101
- end
102
-
103
- def creditor_identifier # May be missing
104
- @creditor_identifier ||= @xml_data.xpath('NtryDtls/TxDtls/RltdPties/Cdtr/Id/PrvtId/Othr/Id/text()').text
105
- end
61
+ if transaction_details.length == 1
62
+ amt = @xml_data.xpath('Amt/text()').text
63
+ ccy = @xml_data.xpath('Amt/@Ccy').text
64
+ end
106
65
 
107
- def payment_information # May be missing
108
- @payment_information ||= @xml_data.xpath('NtryDtls/TxDtls/Refs/PmtInfId/text()').text
66
+ @xml_data.xpath('NtryDtls/TxDtls').map { |x| Transaction.new(x, debit?, amt, ccy) }
109
67
  end
110
68
  end
111
69
  end
@@ -0,0 +1,100 @@
1
+ module CamtParser
2
+ class Transaction
3
+ def initialize(xml_data, debit, amount = nil, currency = nil)
4
+ @xml_data = xml_data
5
+ @debit = debit
6
+ @amount = amount || @xml_data.xpath('AmtDtls/TxAmt/Amt/text()').text
7
+ @currency = currency || @xml_data.xpath('AmtDtls/TxAmt/Amt/@Ccy').text
8
+ end
9
+
10
+ def amount
11
+ CamtParser::Misc.to_amount(@amount)
12
+ end
13
+
14
+ def amount_in_cents
15
+ CamtParser::Misc.to_amount_in_cents(@amount)
16
+ end
17
+
18
+ def currency
19
+ @currency
20
+ end
21
+
22
+ def creditor
23
+ @creditor ||= CamtParser::Creditor.new(@xml_data)
24
+ end
25
+
26
+ def debitor
27
+ @debitor ||= CamtParser::Debitor.new(@xml_data)
28
+ end
29
+
30
+ def name
31
+ credit? ? debitor.name : creditor.name
32
+ end
33
+
34
+ def iban
35
+ credit? ? debitor.iban : creditor.iban
36
+ end
37
+
38
+ def bic
39
+ credit? ? debitor.bic : creditor.bic
40
+ end
41
+
42
+ def credit?
43
+ !debit
44
+ end
45
+
46
+ def debit?
47
+ debit
48
+ end
49
+
50
+ def debit
51
+ @debit
52
+ end
53
+
54
+ def sign
55
+ credit? ? 1 : -1
56
+ end
57
+
58
+ def remittance_information
59
+ @remittance_information ||= begin
60
+ if (x = @xml_data.xpath('RmtInf/Ustrd')).empty?
61
+ nil
62
+ else
63
+ x.collect(&:content).join(' ')
64
+ end
65
+ end
66
+ end
67
+
68
+ def swift_code
69
+ @swift_code ||= @xml_data.xpath('BkTxCd/Prtry/Cd/text()').text.split('+')[0]
70
+ end
71
+
72
+ def reference
73
+ @reference ||= @xml_data.xpath('Refs/InstrId/text()').text
74
+ end
75
+
76
+ def bank_reference # May be missing
77
+ @bank_reference ||= @xml_data.xpath('Refs/AcctSvcrRef/text()').text
78
+ end
79
+
80
+ def end_to_end_reference # May be missing
81
+ @end_to_end_reference ||= @xml_data.xpath('Refs/EndToEndId/text()').text
82
+ end
83
+
84
+ def mandate_reference # May be missing
85
+ @mandate_reference ||= @xml_data.xpath('Refs/MndtId/text()').text
86
+ end
87
+
88
+ def transaction_id # May be missing
89
+ @transaction_id ||= @xml_data.xpath('Refs/TxId/text()').text
90
+ end
91
+
92
+ def creditor_identifier # May be missing
93
+ @creditor_identifier ||= @xml_data.xpath('RltdPties/Cdtr/Id/PrvtId/Othr/Id/text()').text
94
+ end
95
+
96
+ def payment_information # May be missing
97
+ @payment_information ||= @xml_data.xpath('Refs/PmtInfId/text()').text
98
+ end
99
+ end
100
+ end
@@ -1,3 +1,3 @@
1
1
  module CamtParser
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/camt_parser.rb CHANGED
@@ -13,6 +13,7 @@ require_relative "camt_parser/general/debitor"
13
13
  require_relative "camt_parser/general/entry"
14
14
  require_relative "camt_parser/general/account"
15
15
  require_relative "camt_parser/general/group_header"
16
+ require_relative "camt_parser/general/transaction"
16
17
  require_relative "camt_parser/052/report"
17
18
  require_relative "camt_parser/052/base"
18
19
  require_relative "camt_parser/053/statement"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camt_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2017-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -100,6 +100,7 @@ files:
100
100
  - lib/camt_parser/general/debitor.rb
101
101
  - lib/camt_parser/general/entry.rb
102
102
  - lib/camt_parser/general/group_header.rb
103
+ - lib/camt_parser/general/transaction.rb
103
104
  - lib/camt_parser/misc.rb
104
105
  - lib/camt_parser/string.rb
105
106
  - lib/camt_parser/version.rb
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
124
  version: '0'
124
125
  requirements: []
125
126
  rubyforge_project:
126
- rubygems_version: 2.2.2
127
+ rubygems_version: 2.4.8
127
128
  signing_key:
128
129
  specification_version: 4
129
130
  summary: Gem for parsing camt files into a speaking object.