sepa_file_parser 0.11.1 → 0.12.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e3d4c9dd4f2835c1bd8e01abfe30067f0781287be95a49cc7f1f85a469c174c1
4
- data.tar.gz: 181904b224d038fd2c8ff609b4917b2979b7056cd8ad48f87951a657822a781a
3
+ metadata.gz: 70e87263b0dc7f3a5c18d790aed0ed6be4502e070237d4ddb903a3135d9680be
4
+ data.tar.gz: 1784c3d48c7610d6f8b731739ff7d6e9feb244acf6322e8c233f12ba6d65d9db
5
5
  SHA512:
6
- metadata.gz: a30180907db45a71a6954bd158ead499e69f6511259e6b0068e688dfd4e3fea2b835b73eecd47e0d26cf8908f61c7aa502733d547f2945a414001bd2ab22cc52
7
- data.tar.gz: 601ee6524df3c9cc7fbf8ec2362ccf9ed0f799e545273324b7e4891d9c421347a75553c07ace3bfd1bb86afa68a3dd9787bd7d7b1e67019b591bd3f7bca63f90
6
+ metadata.gz: 61f0297ade7874f67ccf9545acc46693df4725816d5f1fc1ba22df6bf0dbb12fa0c1864525f5b8d1d87b2d3172311400c6a1c3ca1acccff463a878d4a014aeb9
7
+ data.tar.gz: cf02403d399711621b75c84ab9b6e24a9161002f23b95e6955a375a958c4a11e9da1b0fcdcb0c03e3d967c5b4209e0ace9ced94aafce45bdf4e20eaf316e1339
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SepaFileParser
4
+ class CounterValueAmount
5
+
6
+ attr_reader :xml_data
7
+
8
+ def initialize(xml_data)
9
+ @xml_data = xml_data
10
+ @amount = xml_data.xpath('Amt/text()').text
11
+ end
12
+
13
+ def amount
14
+ SepaFileParser::Misc.to_amount(@amount)
15
+ end
16
+
17
+ def amount_in_cents
18
+ SepaFileParser::Misc.to_amount_in_cents(@amount)
19
+ end
20
+
21
+ def exchange_rate
22
+ @exchange_rate ||= SepaFileParser::Misc.to_amount(xml_data.xpath('CcyXchg/XchgRate/text()').text)
23
+ end
24
+
25
+ def source_currency
26
+ @source_currency ||= xml_data.xpath('CcyXchg/SrcCcy/text()').text
27
+ end
28
+
29
+ def target_currency
30
+ @target_currency ||= xml_data.xpath('CcyXchg/TrgtCcy/text()').text
31
+ end
32
+ end
33
+ end
@@ -85,7 +85,13 @@ module SepaFileParser
85
85
 
86
86
  # @return [Boolean]
87
87
  def booked?
88
- @booked ||= xml_data.xpath('Sts/text()').text.upcase == 'BOOK'
88
+ return @booked if defined?(@booked)
89
+
90
+ # Since .08 Sts is a choice (<Sts><Cd>BOOK</Cd></Sts>), before it was a plain code (<Sts>BOOK</Sts>)
91
+ status = xml_data.xpath('Sts/Cd/text()').text
92
+ status = xml_data.xpath('Sts/text()').text if status.empty?
93
+
94
+ @booked = status.strip.upcase == 'BOOK'
89
95
  end
90
96
 
91
97
  # @return [String]
@@ -98,6 +104,12 @@ module SepaFileParser
98
104
  def charges
99
105
  @charges ||= SepaFileParser::Charges.new(xml_data.xpath('Chrgs'))
100
106
  end
107
+
108
+ # @return [SepaFileParser::CounterValueAmount]
109
+ def counter_value_amount
110
+ @charges ||= SepaFileParser::CounterValueAmount.new(xml_data.xpath('AmtDtls/CntrValAmt'))
111
+ end
112
+
101
113
  # @return [SepaFileParser::BatchDetail, nil]
102
114
  def batch_detail
103
115
  @batch_detail ||= xml_data.xpath('NtryDtls/Btch').empty? ? nil : parse_batch_detail
@@ -2,17 +2,34 @@
2
2
 
3
3
  module SepaFileParser
4
4
  class Misc
5
+
5
6
  class << self
6
7
 
8
+ # Convert a string representation of an amount to an integer representation in cents.
9
+ # NOTE: This method does not handle amounts with more than 2 decimals.
10
+ # For any value with 2 decimals or less, the result will be correct and formatted
11
+ # to 2 decimals.
12
+ # For amounts with more than 2 decimals, an exception will be raised.
13
+ # The method is not currency aware and does not distinguish currencies without decimals.
14
+ #
7
15
  # @param value [nil, String]
8
16
  # @return [Integer, nil]
9
17
  def to_amount_in_cents(value)
10
18
  return nil if value == nil || value.strip == ''
11
19
 
12
20
  # Using dollars and cents as representation for parts before and after the decimal separator
13
- dollars, cents = value.split(/,|\./)
21
+ # The decimal separator can be either a comma or a dot, depending on the locale.
22
+ # This assumes that there are no thousand separators in the value.
23
+ dollars, cents = value.split(/,|\./, 2)
14
24
  cents ||= '0'
15
- format('%s%s', dollars, cents.ljust(2, '0')).to_i
25
+ if cents.length > 2
26
+ raise ArgumentError, "Amount has more than 2 decimals: #{value}"
27
+ end
28
+ format(
29
+ '%<dollars>s%<cents>s',
30
+ dollars: dollars,
31
+ cents: cents.ljust(2, '0'),
32
+ ).to_i
16
33
  end
17
34
 
18
35
  # @param value [nil, String]
@@ -24,5 +41,6 @@ module SepaFileParser
24
41
  end
25
42
 
26
43
  end
44
+
27
45
  end
28
46
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module SepaFileParser
4
4
 
5
- VERSION = '0.11.1'
5
+ VERSION = '0.12.0'
6
6
 
7
7
  end
@@ -15,6 +15,7 @@ require_relative 'sepa_file_parser/general/debitor'
15
15
  require_relative 'sepa_file_parser/general/entry'
16
16
  require_relative 'sepa_file_parser/general/record'
17
17
  require_relative 'sepa_file_parser/general/charges'
18
+ require_relative 'sepa_file_parser/general/counter_value_amount'
18
19
  require_relative 'sepa_file_parser/general/account'
19
20
  require_relative 'sepa_file_parser/general/owner'
20
21
  require_relative 'sepa_file_parser/general/batch_detail'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sepa_file_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schoknecht
@@ -114,6 +114,7 @@ files:
114
114
  - lib/sepa_file_parser/general/bank_transaction_code.rb
115
115
  - lib/sepa_file_parser/general/batch_detail.rb
116
116
  - lib/sepa_file_parser/general/charges.rb
117
+ - lib/sepa_file_parser/general/counter_value_amount.rb
117
118
  - lib/sepa_file_parser/general/creditor.rb
118
119
  - lib/sepa_file_parser/general/creditor_reference_information.rb
119
120
  - lib/sepa_file_parser/general/debitor.rb
@@ -162,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  - !ruby/object:Gem::Version
163
164
  version: '0'
164
165
  requirements: []
165
- rubygems_version: 4.0.10
166
+ rubygems_version: 4.0.20
166
167
  specification_version: 4
167
168
  summary: Gem for parsing camt, pain, ... files into a speaking object.
168
169
  test_files: []