camt_parser 2.2.0 → 2.3.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: 6cea54db82055dc9825dec0bd1dc69860c3e241a
4
- data.tar.gz: 71af9966dc5c6b135b27b3b0b585c19b85206b05
3
+ metadata.gz: f9c4efbdb4dee0ae8fd78526f7a73f1383703a2f
4
+ data.tar.gz: 78381a822b9bb67cf618fa3931c35f7461edd527
5
5
  SHA512:
6
- metadata.gz: 98fca3ade4834b9daad53f3f933a4d77b539744c028fda5deda730f4bc26dd8f07c009bc01287bbce749bc7929cf0a2691a911550698025127d1c278a577d415
7
- data.tar.gz: 52f3495532f6c3c88b0bce030edf174af6e22cad7e43e5a9eedf7e6ebed5ca6149a33ba9bdbff221f6f5c0c850ed7072159860bd1f476ced55de657c71fe129c
6
+ metadata.gz: 64761fdefb33d2e13a8a768c20944d40843e96cd4373fb6c4b3bb13a4ef0e858b7114ff2313ba9019371f6cd0c5fcfbb50d1e3d71dce0ac72651b2cbc2062eaf
7
+ data.tar.gz: b5ac7fd402d1ea2ed5ebdd07c84b1f3a73e00b267bdd117a9d3f1d59e948041e0c2f8a938aa551040ae9b7c462c6a7487b3d1fa94e2ea8789de75f20527df200
data/lib/camt_parser.rb CHANGED
@@ -11,9 +11,14 @@ require_relative "camt_parser/general/account_balance"
11
11
  require_relative "camt_parser/general/creditor"
12
12
  require_relative "camt_parser/general/debitor"
13
13
  require_relative "camt_parser/general/entry"
14
+ require_relative "camt_parser/general/record"
15
+ require_relative "camt_parser/general/charges"
14
16
  require_relative "camt_parser/general/account"
15
17
  require_relative "camt_parser/general/group_header"
16
18
  require_relative "camt_parser/general/transaction"
19
+ require_relative "camt_parser/general/type/builder"
20
+ require_relative "camt_parser/general/type/code"
21
+ require_relative "camt_parser/general/type/proprietary"
17
22
  require_relative "camt_parser/052/report"
18
23
  require_relative "camt_parser/052/base"
19
24
  require_relative "camt_parser/053/statement"
@@ -39,7 +39,7 @@ module CamtParser
39
39
 
40
40
  def opening_balance
41
41
  @opening_balance ||= begin
42
- bal = @xml_data.xpath('Bal/Tp//Cd[contains(text(), "PRCD")]').first.ancestors('Bal')
42
+ bal = @xml_data.xpath('Bal/Tp//Cd[contains(text(), "OPBD") or contains(text(), "PRCD")]').first.ancestors('Bal')
43
43
  date = bal.xpath('Dt/Dt/text()').text
44
44
  currency = bal.xpath('Amt').attribute('Ccy').value
45
45
  AccountBalance.new bal.xpath('Amt/text()').text, currency, date, true
@@ -0,0 +1,20 @@
1
+ module CamtParser
2
+ class Charges
3
+ def initialize(xml_data)
4
+ @xml_data = xml_data
5
+ @total_charges_and_tax_amount = @xml_data.xpath('TtlChrgsAndTaxAmt/text()').text
6
+ end
7
+
8
+ def total_charges_and_tax_amount
9
+ CamtParser::Misc.to_amount(@total_charges_and_tax_amount)
10
+ end
11
+
12
+ def total_charges_and_tax_amount_in_cents
13
+ CamtParser::Misc.to_amount_in_cents(@total_charges_and_tax_amount)
14
+ end
15
+
16
+ def records
17
+ @records ||= @xml_data.xpath('Rcrd').map{ |x| CamtParser::Record.new(x) }
18
+ end
19
+ end
20
+ end
@@ -58,6 +58,10 @@ module CamtParser
58
58
  end
59
59
  alias_method :description, :additional_information
60
60
 
61
+ def charges
62
+ @charges ||= CamtParser::Charges.new(@xml_data.xpath('Chrgs'))
63
+ end
64
+
61
65
  private
62
66
 
63
67
  def parse_transactions
@@ -0,0 +1,44 @@
1
+ module CamtParser
2
+ class Record
3
+ def initialize(xml_data)
4
+ @xml_data = xml_data
5
+ @amount = @xml_data.xpath('Amt/text()').text
6
+ end
7
+
8
+ def amount
9
+ CamtParser::Misc.to_amount(@amount)
10
+ end
11
+
12
+ def amount_in_cents
13
+ CamtParser::Misc.to_amount_in_cents(@amount)
14
+ end
15
+
16
+ def currency
17
+ @currency ||= @xml_data.xpath('Amt/@Ccy').text
18
+ end
19
+
20
+ def type
21
+ @type ||= CamtParser::Type::Builder.build_type(@xml_data.xpath('Tp'))
22
+ end
23
+
24
+ def charges_included?
25
+ @charges_included ||= @xml_data.xpath('ChrgInclInd/text()').text.downcase == 'true'
26
+ end
27
+
28
+ def debit
29
+ @debit ||= @xml_data.xpath('CdtDbtInd/text()').text.upcase == 'DBIT'
30
+ end
31
+
32
+ def credit?
33
+ !debit
34
+ end
35
+
36
+ def debit?
37
+ debit
38
+ end
39
+
40
+ def sign
41
+ credit? ? 1 : -1
42
+ end
43
+ end
44
+ end
@@ -3,8 +3,8 @@ module CamtParser
3
3
  def initialize(xml_data, debit, amount = nil, currency = nil)
4
4
  @xml_data = xml_data
5
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
6
+ @amount = parse_amount || amount
7
+ @currency = parse_currency || currency
8
8
  end
9
9
 
10
10
  def amount
@@ -96,5 +96,27 @@ module CamtParser
96
96
  def payment_information # May be missing
97
97
  @payment_information ||= @xml_data.xpath('Refs/PmtInfId/text()').text
98
98
  end
99
+
100
+ private
101
+
102
+ def parse_amount
103
+ @amount = if @xml_data.xpath('Amt').any?
104
+ @xml_data.xpath('Amt/text()').text
105
+ elsif @xml_data.xpath('AmtDtls').any?
106
+ @xml_data.xpath('AmtDtls/TxAmt/Amt/text()').text
107
+ else
108
+ nil
109
+ end
110
+ end
111
+
112
+ def parse_currency
113
+ @currenty = if @xml_data.xpath('Amt').any?
114
+ @xml_data.xpath('Amt/@Ccy').text
115
+ elsif @xml_data.xpath('AmtDtls').any?
116
+ @xml_data.xpath('AmtDtls/TxAmt/Amt/@Ccy').text
117
+ else
118
+ nil
119
+ end
120
+ end
99
121
  end
100
122
  end
@@ -0,0 +1,18 @@
1
+ module CamtParser
2
+ module Type
3
+ class Builder
4
+ def self.build_type(xml_data)
5
+ if xml_data.xpath('Prtry').any?
6
+ Proprietary.new(
7
+ xml_data.xpath('Prtry/Id/text()').text,
8
+ xml_data.xpath('Prtry/Issr/text()').text
9
+ )
10
+ elsif xml_data.xpath('Cd').any?
11
+ Code.new(xml_data.xpath('Cd/text()').text)
12
+ else
13
+ nil
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,11 @@
1
+ module CamtParser
2
+ module Type
3
+ class Code
4
+ attr_reader :code
5
+
6
+ def initialize(code)
7
+ @code = code
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module CamtParser
2
+ module Type
3
+ class Proprietary
4
+ attr_reader :id, :issuer
5
+
6
+ def initialize(id, issuer)
7
+ @id, @issuer = id, issuer
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module CamtParser
2
- VERSION = "2.2.0"
2
+ VERSION = "2.3.0"
3
3
  end
@@ -9,7 +9,7 @@ module CamtParser
9
9
  case namespaces
10
10
  when 'urn:iso:std:iso:20022:tech:xsd:camt.052.001.02'
11
11
  return CamtParser::Format052::Base.new(doc.xpath('Document'))
12
- when 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.02'
12
+ when 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.02', 'urn:iso:std:iso:20022:tech:xsd:camt.053.001.04'
13
13
  return CamtParser::Format053::Base.new(doc.xpath('Document'))
14
14
  when 'urn:iso:std:iso:20022:tech:xsd:camt.054.001.04'
15
15
  return CamtParser::Format054::Base.new(doc.xpath('Document'))
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: 2.2.0
4
+ version: 2.3.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: 2017-05-22 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -98,11 +98,16 @@ files:
98
98
  - lib/camt_parser/file.rb
99
99
  - lib/camt_parser/general/account.rb
100
100
  - lib/camt_parser/general/account_balance.rb
101
+ - lib/camt_parser/general/charges.rb
101
102
  - lib/camt_parser/general/creditor.rb
102
103
  - lib/camt_parser/general/debitor.rb
103
104
  - lib/camt_parser/general/entry.rb
104
105
  - lib/camt_parser/general/group_header.rb
106
+ - lib/camt_parser/general/record.rb
105
107
  - lib/camt_parser/general/transaction.rb
108
+ - lib/camt_parser/general/type/builder.rb
109
+ - lib/camt_parser/general/type/code.rb
110
+ - lib/camt_parser/general/type/proprietary.rb
106
111
  - lib/camt_parser/misc.rb
107
112
  - lib/camt_parser/string.rb
108
113
  - lib/camt_parser/version.rb