cfonb 0.0.3 → 0.0.5

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: 5ba0bfa88edcb3ffba5faa6dbed80c645e237f2a733c27e8f08d3d7232529dd4
4
- data.tar.gz: f1b37e0493ca187685ec6cc4ccda93ecfa154aa318c97fd794224b9aef0ff0dc
3
+ metadata.gz: 894f7b20e6c030c8343e833f79f0a5a69c4701e4d262c66a5740c1872efd4603
4
+ data.tar.gz: 380cb8f1225d203fdf845456a2630d3ca13605c03c7bc0deb11f64da6f8e905c
5
5
  SHA512:
6
- metadata.gz: 261088061d0fab58203fd779bd3ea0ccb6133a8432ec633e189d49f173b8a6dc1d6237b7094d654c714b69c7c7746b48176aa1b7303751ceb5e4b71193b37a4f
7
- data.tar.gz: 8a6d89059e1dcae01fae5f6dfb16da6519efe300b927729dd22d8464d4806a9bd6a27fb5e980acfc135fb36b69cdb964fb97199654fe69eaf1314040bcde5c44
6
+ metadata.gz: f6ba5f905c66dc4a4c60916ca5548703484e5270893efc1785d94aa100d60ef4933784589c75964e7dab358c7843b12958348f2476e2d04cc364b3687c0bc604
7
+ data.tar.gz: 5cc5774eb790f41f28fb9b885a50fd4682719feb9d6083351600e50ac9045dc375202a382ef36cd748fd4991b35ce84d7fdd4ffb6ccaf96c586c56f7a510df3f
data/lib/cfonb/error.rb CHANGED
@@ -12,4 +12,8 @@ module CFONB
12
12
  class UnstartedOperationError < ParserError; end
13
13
 
14
14
  class UnfinishedStatementError < ParserError; end
15
+
16
+ class AlreadyDefinedOperationError < ParserError; end
17
+
18
+ class UnhandledLineCodeError < ParserError; end
15
19
  end
@@ -14,7 +14,7 @@ module CFONB
14
14
  ['currency', (16..18)],
15
15
  ['scale', 19, proc { _1.to_i }],
16
16
  ['account', (21..31)],
17
- ['date', (34..39), proc { |value, instance| instance.send(:parse_date, value) }]
17
+ ['date', (34..39), proc { |value, instance| instance.send(:parse_date, value) }],
18
18
  ].freeze
19
19
 
20
20
  AMOUNT_SPECIFIERS = {
@@ -37,7 +37,7 @@ module CFONB
37
37
  'P' => { sign: -1, value: '7' },
38
38
  'Q' => { sign: -1, value: '8' },
39
39
  'R' => { sign: -1, value: '9' },
40
- '}' => { sign: -1, value: '0' }
40
+ '}' => { sign: -1, value: '0' },
41
41
  }.transform_values(&:freeze).freeze
42
42
 
43
43
  attr_reader :body, *BASE_DICTIONARY.map(&:first)
@@ -58,7 +58,7 @@ module CFONB
58
58
 
59
59
  def parse_amount(input)
60
60
  specifier = AMOUNT_SPECIFIERS[input.last]
61
- raise ParserError, "Invalid specifier '#{input.last}' for line #{input}" unless specifier
61
+ raise ParserError.new("Invalid specifier '#{input.last}' for line #{input}") unless specifier
62
62
 
63
63
  specifier[:sign] * BigDecimal(input[0..-2] + specifier[:value]) / (10**scale)
64
64
  end
@@ -68,14 +68,14 @@ module CFONB
68
68
  return if input.strip.empty?
69
69
 
70
70
  input_with_year = if input.last(2).to_i > 60
71
- "#{input[0..3]}19#{input[4..5]}"
72
- else
73
- "#{input[0..3]}20#{input[4..5]}"
74
- end
71
+ "#{input[0..3]}19#{input[4..5]}"
72
+ else
73
+ "#{input[0..3]}20#{input[4..5]}"
74
+ end
75
75
 
76
76
  Date.strptime(input_with_year, '%d%m%Y')
77
77
  rescue Date::Error
78
- raise ParserError, "Invalid date '#{input}' for line #{input}"
78
+ raise ParserError.new("Invalid date '#{input}' for line #{input}")
79
79
  end
80
80
  end
81
81
  end
@@ -4,7 +4,7 @@ module CFONB
4
4
  module LineParser
5
5
  class NewBalance < Base
6
6
  DICTIONARY = [
7
- ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }]
7
+ ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }],
8
8
  ].freeze
9
9
 
10
10
  attr_reader(*DICTIONARY.map(&:first))
@@ -13,7 +13,7 @@ module CFONB
13
13
  ['exoneration_code', 88],
14
14
  ['unavailability_code', 89],
15
15
  ['reference', (104..119)],
16
- ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }]
16
+ ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }],
17
17
  ].freeze
18
18
 
19
19
  attr_reader(*DICTIONARY.map(&:first))
@@ -7,7 +7,7 @@ module CFONB
7
7
  ['internal_operation_code', (7..10)],
8
8
  ['interbank_operation_code', (32..33)],
9
9
  ['detail_code', (45..47)],
10
- ['detail', (48..117)]
10
+ ['detail', (48..117)],
11
11
  ].freeze
12
12
 
13
13
  attr_reader(*DICTIONARY.map(&:first))
@@ -4,7 +4,7 @@ module CFONB
4
4
  module LineParser
5
5
  class PreviousBalance < Base
6
6
  DICTIONARY = [
7
- ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }]
7
+ ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }],
8
8
  ].freeze
9
9
 
10
10
  attr_reader(*DICTIONARY.map(&:first))
@@ -8,9 +8,8 @@ module CFONB
8
8
  def self.apply(operation, line)
9
9
  operation.fee_currency = line.detail[0..2]
10
10
  scale = line.detail[3].to_i
11
- sign = operation.amount <=> 0 # the detail amount is unsigned
12
11
 
13
- operation.fee = sign * BigDecimal(line.detail[4..17]) / (10**scale)
12
+ operation.fee = BigDecimal(line.detail[4..17]) / (10**scale)
14
13
  end
15
14
 
16
15
  CFONB::OperationDetail.register('FEE', self)
@@ -10,7 +10,7 @@ module CFONB
10
10
  def self.apply(operation, line)
11
11
  operation.reference = [
12
12
  operation.reference,
13
- line.detail.strip
13
+ line.detail.strip,
14
14
  ].filter_map(&:presence).join(' - ')
15
15
  end
16
16
 
data/lib/cfonb/parser.rb CHANGED
@@ -8,7 +8,7 @@ module CFONB
8
8
  PREVIOUS_BALANCE_CODE = '01',
9
9
  OPERATION_CODE = '04',
10
10
  OPERATION_DETAIL_CODE = '05',
11
- NEW_BALANCE_CODE = '07'
11
+ NEW_BALANCE_CODE = '07',
12
12
  ].freeze
13
13
 
14
14
  def initialize(input)
@@ -26,6 +26,15 @@ module CFONB
26
26
  statements
27
27
  end
28
28
 
29
+ def parse_operation(optimistic: false)
30
+ @current_operation = nil
31
+ @optimistic = optimistic
32
+
33
+ each_line { parse_operation_line(_1) }
34
+
35
+ current_operation
36
+ end
37
+
29
38
  private
30
39
 
31
40
  attr_reader :input, :statements, :current_statement, :current_operation, :optimistic
@@ -43,7 +52,7 @@ module CFONB
43
52
 
44
53
  def parse_line(line)
45
54
  return if line.strip.empty?
46
- raise InvalidCodeError, "Invalid line code '#{line.first(2)}'" unless CODES.include?(line.first(2))
55
+ raise InvalidCodeError.new("Invalid line code '#{line.first(2)}'") unless CODES.include?(line.first(2))
47
56
 
48
57
  line = CFONB::LineParser.parse(line)
49
58
 
@@ -75,6 +84,23 @@ module CFONB
75
84
  handle_error(e)
76
85
  end
77
86
 
87
+ def parse_operation_line(line)
88
+ line = CFONB::LineParser.parse(line)
89
+
90
+ case line.code
91
+ when OPERATION_CODE
92
+ return handle_error(AlreadyDefinedOperationError) if current_operation
93
+
94
+ @current_operation = CFONB::Operation.new(line)
95
+ when OPERATION_DETAIL_CODE
96
+ return handle_error(UnstartedOperationError) unless current_operation
97
+
98
+ current_operation.merge_detail(line)
99
+ else
100
+ handle_error(UnhandledLineCodeError)
101
+ end
102
+ end
103
+
78
104
  def handle_error(error)
79
105
  raise error unless optimistic
80
106
  end
@@ -9,7 +9,7 @@ module CFONB
9
9
  from from_balance
10
10
  to to_balance
11
11
  operations
12
- ]
12
+ ],
13
13
  )
14
14
 
15
15
  def initialize(line)
@@ -33,7 +33,7 @@ module CFONB
33
33
  [
34
34
  begin_raw,
35
35
  operations.map(&:raw),
36
- end_raw
36
+ end_raw,
37
37
  ].join("\n")
38
38
  end
39
39
 
data/lib/cfonb.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'date'
2
4
 
3
5
  require_relative 'cfonb/refinements/strings'
@@ -30,4 +32,8 @@ module CFONB
30
32
  def self.parse(input, optimistic: false)
31
33
  Parser.new(input).parse(optimistic: optimistic)
32
34
  end
35
+
36
+ def self.parse_operation(input, optimistic: false)
37
+ Parser.new(input).parse_operation(optimistic: optimistic)
38
+ end
33
39
  end
@@ -19,7 +19,7 @@ describe CFONB::LineParser::NewBalance do
19
19
  'scale' => 2,
20
20
  'account' => '98765432100',
21
21
  'date' => Date.new(2019, 5, 15),
22
- 'amount' => -190.43
22
+ 'amount' => -190.43,
23
23
  )
24
24
  end
25
25
  end
@@ -22,7 +22,7 @@ describe CFONB::LineParser::OperationDetail do
22
22
  'internal_operation_code' => '9162',
23
23
  'interbank_operation_code' => 'B1',
24
24
  'detail_code' => 'LIB',
25
- 'detail' => 'MENSUEAUHTR13133'
25
+ 'detail' => 'MENSUEAUHTR13133',
26
26
  )
27
27
  end
28
28
  end
@@ -28,7 +28,7 @@ describe CFONB::LineParser::Operation do
28
28
  'number' => 7_654_321,
29
29
  'exoneration_code' => 'U',
30
30
  'unavailability_code' => 'P',
31
- 'reference' => 'XYZ123'
31
+ 'reference' => 'XYZ123',
32
32
  )
33
33
  end
34
34
  end
@@ -19,7 +19,7 @@ describe CFONB::LineParser::PreviousBalance do
19
19
  'scale' => 2,
20
20
  'account' => '98765432100',
21
21
  'date' => Date.new(2019, 5, 15),
22
- 'amount' => -190.43
22
+ 'amount' => -190.43,
23
23
  )
24
24
  end
25
25
  end
@@ -13,7 +13,7 @@ describe CFONB::Operation do
13
13
  date: Date.new(2021, 3, 5),
14
14
  currency: 'EUR',
15
15
  amount: -15,
16
- reference: '42'
16
+ reference: '42',
17
17
  )
18
18
  end
19
19
 
@@ -88,7 +88,7 @@ describe CFONB::Operation do
88
88
 
89
89
  expect(operation).to have_attributes(
90
90
  original_currency: 'USD',
91
- original_amount: -12.34
91
+ original_amount: -12.34,
92
92
  )
93
93
  end
94
94
  end
@@ -118,7 +118,7 @@ describe CFONB::Operation do
118
118
  OpenStruct.new(
119
119
  body: '',
120
120
  detail_code: 'RCN',
121
- detail: 'SWILE-CMD-TR-YPDHMA TICKET RESTO '
121
+ detail: 'SWILE-CMD-TR-YPDHMA TICKET RESTO ',
122
122
  )
123
123
  end
124
124
 
@@ -135,7 +135,7 @@ describe CFONB::Operation do
135
135
  OpenStruct.new(
136
136
  body: '0530002112701731EUR2E0000073337DA129082300 REFPENNYLANE B13A93908C36C82DF5C319/1 ',
137
137
  detail_code: 'REF',
138
- detail: 'PENNYLANE B13A93908C36C82DF5C319/1 '
138
+ detail: 'PENNYLANE B13A93908C36C82DF5C319/1 ',
139
139
  )
140
140
  end
141
141
 
@@ -151,7 +151,7 @@ describe CFONB::Operation do
151
151
  OpenStruct.new(
152
152
  body: '0530004411001871EUR2 0001016255614090823 FEEEUR200000000000740',
153
153
  detail_code: 'FEE',
154
- detail: 'EUR200000000000740'
154
+ detail: 'EUR200000000000740',
155
155
  )
156
156
  end
157
157
 
@@ -159,7 +159,7 @@ describe CFONB::Operation do
159
159
  operation.merge_detail(detail)
160
160
 
161
161
  expect(operation.fee_currency).to eq('EUR')
162
- expect(operation.fee).to eq(-7.4)
162
+ expect(operation.fee).to eq(7.4)
163
163
  end
164
164
  end
165
165
  end
@@ -12,7 +12,7 @@ describe CFONB::Parser do
12
12
  it 'parses correctly' do
13
13
  expect(statements).to contain_exactly(
14
14
  an_instance_of(CFONB::Statement),
15
- an_instance_of(CFONB::Statement)
15
+ an_instance_of(CFONB::Statement),
16
16
  )
17
17
 
18
18
  expect(statements[0]).to have_attributes(
@@ -23,7 +23,7 @@ describe CFONB::Parser do
23
23
  from: Date.new(2019, 5, 15),
24
24
  from_balance: -190.4,
25
25
  to: Date.new(2019, 5, 16),
26
- to_balance: -241.21
26
+ to_balance: -241.21,
27
27
  )
28
28
 
29
29
  expect(statements[0].operations.size).to eq(3)
@@ -44,7 +44,7 @@ describe CFONB::Parser do
44
44
  value_date: Date.new(2019, 5, 16),
45
45
  original_currency: nil,
46
46
  original_amount: nil,
47
- debtor: 'INTERNET SFR'
47
+ debtor: 'INTERNET SFR',
48
48
  )
49
49
 
50
50
  expect(statements[0].operations[1]).to have_attributes(
@@ -62,7 +62,7 @@ describe CFONB::Parser do
62
62
  value_date: Date.new(2019, 5, 16),
63
63
  original_currency: nil,
64
64
  original_amount: nil,
65
- debtor: 'ELEC ERDF'
65
+ debtor: 'ELEC ERDF',
66
66
  )
67
67
 
68
68
  expect(statements[0].operations[2]).to have_attributes(
@@ -79,7 +79,7 @@ describe CFONB::Parser do
79
79
  unavailability_code: '0',
80
80
  value_date: Date.new(2019, 5, 15),
81
81
  original_currency: nil,
82
- original_amount: nil
82
+ original_amount: nil,
83
83
  )
84
84
 
85
85
  expect(statements[1]).to have_attributes(
@@ -90,7 +90,7 @@ describe CFONB::Parser do
90
90
  from: Date.new(2019, 5, 16),
91
91
  from_balance: -241.21,
92
92
  to: Date.new(2019, 5, 17),
93
- to_balance: -163.72
93
+ to_balance: -163.72,
94
94
  )
95
95
 
96
96
  expect(statements[1].operations.size).to eq(3)
@@ -109,7 +109,7 @@ describe CFONB::Parser do
109
109
  unavailability_code: '0',
110
110
  value_date: Date.new(2019, 5, 15),
111
111
  original_currency: nil,
112
- original_amount: nil
112
+ original_amount: nil,
113
113
  )
114
114
 
115
115
  expect(statements[1].operations[1]).to have_attributes(
@@ -126,7 +126,7 @@ describe CFONB::Parser do
126
126
  unavailability_code: '0',
127
127
  value_date: Date.new(2019, 5, 15),
128
128
  original_currency: nil,
129
- original_amount: nil
129
+ original_amount: nil,
130
130
  )
131
131
 
132
132
  expect(statements[1].operations[2]).to have_attributes(
@@ -143,7 +143,7 @@ describe CFONB::Parser do
143
143
  unavailability_code: '0',
144
144
  value_date: Date.new(2019, 5, 16),
145
145
  original_currency: nil,
146
- original_amount: nil
146
+ original_amount: nil,
147
147
  )
148
148
  end
149
149
  end
@@ -203,7 +203,7 @@ describe CFONB::Parser do
203
203
  it 'parses correctly' do
204
204
  expect(statements).to contain_exactly(
205
205
  an_instance_of(CFONB::Statement),
206
- an_instance_of(CFONB::Statement)
206
+ an_instance_of(CFONB::Statement),
207
207
  )
208
208
 
209
209
  expect(statements[0]).to have_attributes(
@@ -214,7 +214,7 @@ describe CFONB::Parser do
214
214
  from: Date.new(2019, 5, 15),
215
215
  from_balance: -190.4,
216
216
  to: Date.new(2019, 5, 16),
217
- to_balance: -241.21
217
+ to_balance: -241.21,
218
218
  )
219
219
 
220
220
  expect(statements[0].operations.size).to eq(3)
@@ -234,7 +234,7 @@ describe CFONB::Parser do
234
234
  value_date: Date.new(2019, 5, 16),
235
235
  original_currency: nil,
236
236
  original_amount: nil,
237
- debtor: 'INTERNET SFR'
237
+ debtor: 'INTERNET SFR',
238
238
  )
239
239
 
240
240
  expect(statements[0].operations[1]).to have_attributes(
@@ -252,7 +252,7 @@ describe CFONB::Parser do
252
252
  value_date: Date.new(2019, 5, 16),
253
253
  original_currency: nil,
254
254
  original_amount: nil,
255
- debtor: 'ELEC ERDF'
255
+ debtor: 'ELEC ERDF',
256
256
  )
257
257
 
258
258
  expect(statements[0].operations[2]).to have_attributes(
@@ -269,7 +269,7 @@ describe CFONB::Parser do
269
269
  unavailability_code: '0',
270
270
  value_date: Date.new(2019, 5, 15),
271
271
  original_currency: nil,
272
- original_amount: nil
272
+ original_amount: nil,
273
273
  )
274
274
 
275
275
  expect(statements[1]).to have_attributes(
@@ -280,7 +280,7 @@ describe CFONB::Parser do
280
280
  from: Date.new(2019, 5, 16),
281
281
  from_balance: -241.21,
282
282
  to: Date.new(2019, 5, 17),
283
- to_balance: -163.72
283
+ to_balance: -163.72,
284
284
  )
285
285
 
286
286
  expect(statements[1].operations.size).to eq(3)
@@ -299,7 +299,7 @@ describe CFONB::Parser do
299
299
  unavailability_code: '0',
300
300
  value_date: Date.new(2019, 5, 15),
301
301
  original_currency: nil,
302
- original_amount: nil
302
+ original_amount: nil,
303
303
  )
304
304
 
305
305
  expect(statements[1].operations[1]).to have_attributes(
@@ -316,7 +316,7 @@ describe CFONB::Parser do
316
316
  unavailability_code: '0',
317
317
  value_date: Date.new(2019, 5, 15),
318
318
  original_currency: nil,
319
- original_amount: nil
319
+ original_amount: nil,
320
320
  )
321
321
 
322
322
  expect(statements[1].operations[2]).to have_attributes(
@@ -333,7 +333,7 @@ describe CFONB::Parser do
333
333
  unavailability_code: '0',
334
334
  value_date: Date.new(2019, 5, 16),
335
335
  original_currency: nil,
336
- original_amount: nil
336
+ original_amount: nil,
337
337
  )
338
338
  end
339
339
  end
@@ -359,7 +359,7 @@ describe CFONB::Parser do
359
359
  value_date: Date.new(2019, 5, 16),
360
360
  original_currency: nil,
361
361
  original_amount: nil,
362
- debtor: 'ELEC ERDF'
362
+ debtor: 'ELEC ERDF',
363
363
  )
364
364
  end
365
365
  end
@@ -385,7 +385,7 @@ describe CFONB::Parser do
385
385
  value_date: Date.new(2019, 5, 16),
386
386
  original_currency: nil,
387
387
  original_amount: nil,
388
- debtor: 'ELEC ERDF'
388
+ debtor: 'ELEC ERDF',
389
389
  )
390
390
  end
391
391
  end
@@ -411,7 +411,7 @@ describe CFONB::Parser do
411
411
  value_date: Date.new(2019, 5, 16),
412
412
  original_currency: nil,
413
413
  original_amount: nil,
414
- debtor: 'ELEC ERDF'
414
+ debtor: 'ELEC ERDF',
415
415
  )
416
416
  end
417
417
  end
@@ -437,7 +437,7 @@ describe CFONB::Parser do
437
437
  value_date: Date.new(2019, 5, 16),
438
438
  original_currency: nil,
439
439
  original_amount: nil,
440
- debtor: 'ELEC ERDF'
440
+ debtor: 'ELEC ERDF',
441
441
  )
442
442
  expect(statements[0].operations[1]).to have_attributes(
443
443
  amount: -7.9,
@@ -453,7 +453,7 @@ describe CFONB::Parser do
453
453
  unavailability_code: '0',
454
454
  value_date: Date.new(2019, 5, 16),
455
455
  original_currency: nil,
456
- original_amount: nil
456
+ original_amount: nil,
457
457
  )
458
458
  end
459
459
  end
@@ -467,4 +467,152 @@ describe CFONB::Parser do
467
467
  end
468
468
  end
469
469
  end
470
+
471
+ describe '.parse_operation' do
472
+ subject(:operation) { described_class.new(input).parse_operation }
473
+
474
+ let(:input) { File.read('spec/files/operation.txt') }
475
+
476
+ context 'with a valid input' do
477
+ it 'returns CFONB::Operation' do
478
+ expect(operation).to be_an_instance_of(CFONB::Operation)
479
+ end
480
+
481
+ it 'parses correctly' do
482
+ expect(operation).to have_attributes(
483
+ amount: -32.21,
484
+ currency: 'EUR',
485
+ date: Date.new(2019, 5, 16),
486
+ exoneration_code: '0',
487
+ interbank_code: 'B1',
488
+ internal_code: '9162',
489
+ label: "PRLV SEPA TEST CABINET\nMENSUEAUHTR13133",
490
+ number: 0,
491
+ reference: 'REFERENCE - OTHER REFERENCE',
492
+ rejection_code: '',
493
+ unavailability_code: '0',
494
+ value_date: Date.new(2019, 5, 16),
495
+ original_currency: nil,
496
+ original_amount: nil,
497
+ debtor: 'INTERNET SFR',
498
+ )
499
+ end
500
+ end
501
+
502
+ context 'with an already defined operation' do
503
+ let(:input) { File.read('spec/files/operation_already_defined.txt') }
504
+
505
+ it 'raises AlreadyDefinedOperationError' do
506
+ expect do
507
+ operation
508
+ end.to raise_error(CFONB::AlreadyDefinedOperationError)
509
+ end
510
+ end
511
+
512
+ context 'with an unstarted operation' do
513
+ let(:input) { File.read('spec/files/operation_unstarted.txt') }
514
+
515
+ it 'raises UnstartedOperationError' do
516
+ expect do
517
+ operation
518
+ end.to raise_error(CFONB::UnstartedOperationError)
519
+ end
520
+ end
521
+
522
+ context 'with an unhandled line code' do
523
+ let(:input) { File.read('spec/files/example.txt') }
524
+
525
+ it 'raises UnhandledLineCodeError' do
526
+ expect do
527
+ operation
528
+ end.to raise_error(CFONB::UnhandledLineCodeError)
529
+ end
530
+ end
531
+
532
+ context 'with an optimistic parse' do
533
+ subject(:operation) { described_class.new(input).parse_operation(optimistic: true) }
534
+
535
+ context 'with a valid input' do
536
+ it 'returns CFONB::Operation' do
537
+ expect(operation).to be_an_instance_of(CFONB::Operation)
538
+ end
539
+
540
+ it 'parses correctly' do
541
+ expect(operation).to have_attributes(
542
+ amount: -32.21,
543
+ currency: 'EUR',
544
+ date: Date.new(2019, 5, 16),
545
+ exoneration_code: '0',
546
+ interbank_code: 'B1',
547
+ internal_code: '9162',
548
+ label: "PRLV SEPA TEST CABINET\nMENSUEAUHTR13133",
549
+ number: 0,
550
+ reference: 'REFERENCE - OTHER REFERENCE',
551
+ rejection_code: '',
552
+ unavailability_code: '0',
553
+ value_date: Date.new(2019, 5, 16),
554
+ original_currency: nil,
555
+ original_amount: nil,
556
+ debtor: 'INTERNET SFR',
557
+ )
558
+ end
559
+ end
560
+
561
+ context 'with an already defined operation' do
562
+ let(:input) { File.read('spec/files/operation_already_defined.txt') }
563
+
564
+ it 'ignores the second operation' do
565
+ expect(operation).to have_attributes(
566
+ amount: -32.21,
567
+ currency: 'EUR',
568
+ date: Date.new(2019, 5, 16),
569
+ exoneration_code: '0',
570
+ interbank_code: 'B1',
571
+ internal_code: '9162',
572
+ label: "PRLV SEPA TEST CABINET\nMENSUEAUHTR13133",
573
+ number: 0,
574
+ reference: 'REFERENCE - OTHER REFERENCE',
575
+ rejection_code: '',
576
+ unavailability_code: '0',
577
+ value_date: Date.new(2019, 5, 16),
578
+ original_currency: nil,
579
+ original_amount: nil,
580
+ debtor: 'INTERNET SFR',
581
+ )
582
+ end
583
+ end
584
+
585
+ context 'with an unstarted operation' do
586
+ let(:input) { File.read('spec/files/operation_unstarted.txt') }
587
+
588
+ it 'returns no operation' do
589
+ expect(operation).to be_nil
590
+ end
591
+ end
592
+
593
+ context 'with an unhandled line code' do
594
+ let(:input) { File.read('spec/files/example.txt') }
595
+
596
+ it 'ignores the unhandled lines' do
597
+ expect(operation).to have_attributes(
598
+ amount: -32.21,
599
+ currency: 'EUR',
600
+ date: Date.new(2019, 5, 16),
601
+ exoneration_code: '0',
602
+ interbank_code: 'B1',
603
+ internal_code: '9162',
604
+ label: "PRLV SEPA TEST CABINET\nMENSUEAUHTR13133\nP051928612 22793301700040",
605
+ number: 0,
606
+ reference: 'REFERENCE - OTHER REFERENCE',
607
+ rejection_code: '',
608
+ unavailability_code: '0',
609
+ value_date: Date.new(2019, 5, 16),
610
+ original_currency: nil,
611
+ original_amount: nil,
612
+ debtor: 'ELEC ERDF',
613
+ )
614
+ end
615
+ end
616
+ end
617
+ end
470
618
  end
@@ -5,8 +5,8 @@ require 'cfonb'
5
5
  describe CFONB::Statement do
6
6
  subject(:statement) do
7
7
  described_class.new(begin_line)
8
- .tap { _1.operations << operation }
9
- .tap { _1.merge_new_balance(end_line) }
8
+ .tap { _1.operations << operation }
9
+ .tap { _1.merge_new_balance(end_line) }
10
10
  end
11
11
 
12
12
  let(:operation) do
@@ -17,22 +17,22 @@ describe CFONB::Statement do
17
17
 
18
18
  let(:begin_line) do
19
19
  CFONB::LineParser.parse(
20
- '0115589 00000EUR2 98765432100 150519 0000000001904}150519160519 '
20
+ '0115589 00000EUR2 98765432100 150519 0000000001904}150519160519 ',
21
21
  )
22
22
  end
23
23
  let(:operation_line) do
24
24
  CFONB::LineParser.parse(
25
- '0415589916200000EUR2 98765432100B1160519 160519PRLV SEPA TEST CABINET 0000000000000000000322J '
25
+ '0415589916200000EUR2 98765432100B1160519 160519PRLV SEPA TEST CABINET 0000000000000000000322J ',
26
26
  )
27
27
  end
28
28
  let(:detail_line) do
29
29
  CFONB::LineParser.parse(
30
- '0515589916200000EUR2 98765432100B1160519 LIBMENSUEAUHTR13133 '
30
+ '0515589916200000EUR2 98765432100B1160519 LIBMENSUEAUHTR13133 ',
31
31
  )
32
32
  end
33
33
  let(:end_line) do
34
34
  CFONB::LineParser.parse(
35
- '0715489 00000EUR2 98765432100 160519 0000000002412J '
35
+ '0715489 00000EUR2 98765432100 160519 0000000002412J ',
36
36
  )
37
37
  end
38
38
 
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: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Le Bray
@@ -9,8 +9,78 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-09-26 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2023-11-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: license_finder
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: ruboclean
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rubocop-rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
14
84
  description: An easy to use CFONB format parser
15
85
  email: ''
16
86
  executables: []
@@ -59,7 +129,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
129
  requirements:
60
130
  - - ">="
61
131
  - !ruby/object:Gem::Version
62
- version: '0'
132
+ version: 3.2.2
63
133
  required_rubygems_version: !ruby/object:Gem::Requirement
64
134
  requirements:
65
135
  - - ">="