sepa_file_parser 0.11.0 → 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 +4 -4
- data/lib/sepa_file_parser/general/counter_value_amount.rb +33 -0
- data/lib/sepa_file_parser/general/entry.rb +13 -1
- data/lib/sepa_file_parser/general/transaction.rb +1 -1
- data/lib/sepa_file_parser/misc.rb +20 -2
- data/lib/sepa_file_parser/version.rb +1 -1
- data/lib/sepa_file_parser.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70e87263b0dc7f3a5c18d790aed0ed6be4502e070237d4ddb903a3135d9680be
|
|
4
|
+
data.tar.gz: 1784c3d48c7610d6f8b731739ff7d6e9feb244acf6322e8c233f12ba6d65d9db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
@@ -119,7 +119,7 @@ module SepaFileParser
|
|
|
119
119
|
end
|
|
120
120
|
|
|
121
121
|
def creditor_reference # May be missing
|
|
122
|
-
@creditor_reference ||= creditor_reference_information
|
|
122
|
+
@creditor_reference ||= creditor_reference_information&.creditor_reference
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def creditor_reference_information
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
data/lib/sepa_file_parser.rb
CHANGED
|
@@ -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.
|
|
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.
|
|
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: []
|