cfonb 1.0.0 → 1.1.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
  SHA256:
3
- metadata.gz: f80902862080f864dd6e69edc2f15d1d07d863fef754f47eb70bf052d4628cc2
4
- data.tar.gz: 3258fdf0214ee434a09643ce033cc4fbf56500ad5d3633b3e424ed36f0d0a93d
3
+ metadata.gz: 057c580fc124d3731dc852832c8c6f601584bbd235604fd5c44605b4509429c0
4
+ data.tar.gz: 037c88124d45e136b909660a8ef7f840a03fa5a7bc06c9e19e592e2eb67080a5
5
5
  SHA512:
6
- metadata.gz: f0b35b9c4d7aa76957195c087e26f9777dad59308fcdb12a02c77da031d86798c726b3dc90e9fb9756c995414d34ce92f7d35638bed80fe10f5ff5c64e332659
7
- data.tar.gz: b55fa730f6659cd878fa46a965a832bc3eb3b26e0fca3182a43af4b04bb4827995d73bfee61c7c1cb39674f01074f31a255ab060caf3fd0b3c0dc05a9c563f46
6
+ metadata.gz: b803bf7c0a2c0803e7ae54ea937d3ccb06eeeced3f7dcc033ce202a658137c41da085adf462c2ebcf9d76352cb3990467a45deeaf0a80ad6c86b713a9733248e
7
+ data.tar.gz: 02c6b90c2732f5da3b481ec2c9b811b17377d0a7e602780d2048baf86499c3115abe4fcff98cd1cf454a80967565167aa6475fd53cc8442e43c14ddad79d89a4
@@ -7,10 +7,23 @@ module CFONB
7
7
  base.singleton_class.prepend(
8
8
  Module.new do
9
9
  def apply(details, line)
10
- details.instance_variable_set(:"@#{line.detail_code}", line.detail)
10
+ code = :"@#{line.detail_code}"
11
+ details.instance_variable_set(code, instance_value(details, line, code))
11
12
 
12
13
  super
13
14
  end
15
+
16
+ private
17
+
18
+ def append_detail?(details, line, code)
19
+ details.instance_variable_defined?(code) && line.detail.is_a?(String)
20
+ end
21
+
22
+ def instance_value(details, line, code)
23
+ return line.detail unless append_detail?(details, line, code)
24
+
25
+ details.instance_variable_get(code) + "\n#{line.detail}"
26
+ end
14
27
  end,
15
28
  )
16
29
  end
@@ -7,7 +7,7 @@ module CFONB
7
7
 
8
8
  def self.apply(details, line)
9
9
  details.creditor_identifier = line.detail[0..34].strip
10
- details.creditor_identifier_type = line.detail[35..-1].strip
10
+ details.creditor_identifier_type = line.detail[35..-1]&.strip
11
11
  end
12
12
 
13
13
  CFONB::OperationDetails.register('IBE', self)
@@ -7,7 +7,7 @@ module CFONB
7
7
 
8
8
  def self.apply(details, line)
9
9
  details.debtor_identifier = line.detail[0..34].strip
10
- details.debtor_identifier_type = line.detail[35..-1].strip
10
+ details.debtor_identifier_type = line.detail[35..-1]&.strip
11
11
  end
12
12
 
13
13
  CFONB::OperationDetails.register('IPY', self)
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CFONB
4
+ module OperationDetails
5
+ class Unknown < Base
6
+ ATTRIBUTES = %i[unknown].freeze
7
+
8
+ def self.apply(details, line)
9
+ details.unknown ||= {}
10
+ code = line.detail_code
11
+
12
+ details.unknown[code] =
13
+ if details.unknown[code] && line.detail.is_a?(String)
14
+ details.unknown[code] + "\n#{line.detail}"
15
+ else
16
+ line.detail
17
+ end
18
+ end
19
+
20
+ CFONB::OperationDetails.register('Unknown', self)
21
+ end
22
+ end
23
+ end
@@ -15,7 +15,9 @@ module CFONB
15
15
  end
16
16
 
17
17
  def self.for(line)
18
- @details[line.detail_code]
18
+ return unless line.respond_to?(:detail_code)
19
+
20
+ @details[line.detail_code] || Unknown
19
21
  end
20
22
  end
21
23
  end
data/lib/cfonb.rb CHANGED
@@ -32,6 +32,7 @@ require_relative 'cfonb/operation_details/fee'
32
32
  require_relative 'cfonb/operation_details/ibe'
33
33
  require_relative 'cfonb/operation_details/npo'
34
34
  require_relative 'cfonb/operation_details/nbu'
35
+ require_relative 'cfonb/operation_details/unknown'
35
36
 
36
37
  module CFONB
37
38
  def self.parse(input, optimistic: false)
@@ -272,6 +272,29 @@ describe CFONB::Operation do
272
272
  expect(operation.details.ultimate_creditor).to eq('Patrick')
273
273
  end
274
274
  end
275
+
276
+ context 'with an unknown detail' do
277
+ let(:detail) do
278
+ OpenStruct.new(
279
+ body: '0530004411001871EUR2 0001016255614090823 AAAEUR200000000000740',
280
+ detail_code: 'AAA',
281
+ detail: 'EUR200000000000740',
282
+ )
283
+ end
284
+
285
+ it 'adds the detail to the unknown details hash' do
286
+ operation.merge_detail(detail)
287
+
288
+ expect(operation.details.unknown).to eq({ 'AAA' => 'EUR200000000000740' })
289
+ end
290
+
291
+ it 'updates the current details in case of duplicated codes' do
292
+ operation.merge_detail(detail)
293
+ operation.merge_detail(detail)
294
+
295
+ expect(operation.details.unknown).to eq({ 'AAA' => "EUR200000000000740\nEUR200000000000740" })
296
+ end
297
+ end
275
298
  end
276
299
 
277
300
  describe '#type_code' do
@@ -43,12 +43,17 @@ describe CFONB::Parser do
43
43
  reference: '',
44
44
  )
45
45
  expect(statements[0].operations[0].details).to have_attributes(
46
- free_label: 'MENSUEAUHTR13133',
46
+ free_label: "MENSUEAUHTR13133\nMENSUEAUHTR13DUP",
47
47
  original_currency: nil,
48
48
  original_amount: nil,
49
49
  exchange_rate: nil,
50
50
  purpose: 'PURPOSE',
51
51
  debtor: 'INTERNET SFR',
52
+ unknown: {
53
+ 'AAA' => "INTERNETA AAA\nINTERNETA ABB",
54
+ 'BBB' => 'INTERNETE BBB',
55
+ 'CCC' => 'INTERNETI CCC',
56
+ },
52
57
  )
53
58
 
54
59
  expect(statements[0].operations[1]).to have_attributes(
@@ -272,7 +277,7 @@ describe CFONB::Parser do
272
277
 
273
278
  expect(statements[0].operations[0].details).to have_attributes(
274
279
  operation_reference: 'REFERENCE',
275
- free_label: 'MENSUEAUHTR13133',
280
+ free_label: "MENSUEAUHTR13133\nMENSUEAUHTR13DUP",
276
281
  debtor: 'INTERNET SFR',
277
282
  client_reference: 'OTHER REFERENCE',
278
283
  original_currency: nil,
@@ -705,7 +710,7 @@ describe CFONB::Parser do
705
710
  expect(operation.details).to have_attributes(
706
711
  operation_reference: 'REFERENCE',
707
712
  client_reference: 'OTHER REFERENCE',
708
- free_label: "MENSUEAUHTR13133\nP051928612 22793301700040",
713
+ free_label: "MENSUEAUHTR13133\nMENSUEAUHTR13DUP\nP051928612 22793301700040",
709
714
  debtor: 'ELEC ERDF',
710
715
  original_currency: nil,
711
716
  original_amount: nil,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfonb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Le Bray
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-11-15 00:00:00.000000000 Z
12
+ date: 2024-12-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: license_finder
@@ -112,6 +112,7 @@ files:
112
112
  - lib/cfonb/operation_details/npy.rb
113
113
  - lib/cfonb/operation_details/rcn.rb
114
114
  - lib/cfonb/operation_details/ref.rb
115
+ - lib/cfonb/operation_details/unknown.rb
115
116
  - lib/cfonb/parser.rb
116
117
  - lib/cfonb/refinements/strings.rb
117
118
  - lib/cfonb/statement.rb