Skip to content

Commit

Permalink
Separate details reference
Browse files Browse the repository at this point in the history
  • Loading branch information
lauragilgz committed Nov 5, 2024
1 parent bd081e4 commit da55d6a
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 58 deletions.
34 changes: 16 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,26 @@ We aimed at making it as easy as possible to add new details. You just need to d
CFONB::OperationDetails.register('FEE', self)
```

| Detail Code | Attributes | Description |
| ----------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| FEE | `fee`, `fee_currency` | Represents operation fees the bank is applying |
| LCC | `unstructured_label` | Not structured label line 1 (first 70 characters) |
| LC2 | `unstructured_label_2` | Not structured label line 2 (last 70 characters) |
| LCS | `structured_label` | Structured label |
| LIB | `free_label` | Free label |
| MMO | `original_currency`, `original_amount`, `scale`, `exchange_rate`, `exchange_rate_scale` | Amount and currency if it has been converted from a foreign currency. The `original_amount` is unsigned, meaning it is always non-negative. |
| NBE | `creditor` | Name of the creditor or beneficiary |
| NPY | `debtor` | Name of the debtor or payer |
| RCN | `reference`, `purpose` | Client reference and Payment nature/purpose |
| REF | `operation_reference` | Bank operation reference |
| IPY | `debtor_identifier`, `debtor_identifier_type` | Debtor identifier and debtor identifier type |
| IBE | `creditor_identifier`, `creditor_identifier_type` | Creditor identifier and the type of identifier |
| NPO | `ultimate_debtor` | Name of the ultimate debtor or beneficiary |
| NBU | `ultimate_creditor` | Name of the ultimate creditor or payer |
| Detail Code | Attributes | Description |
| ----------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| FEE | `fee`, `fee_currency` | Represents operation fees the bank is applying |
| IPY | `debtor_identifier`, `debtor_identifier_type` | Debtor identifier and debtor identifier type |
| IBE | `creditor_identifier`, `creditor_identifier_type` | Creditor identifier and the type of identifier |
| LC2 | `unstructured_label_2` | Not structured label line 2 (last 70 characters) |
| LCC | `unstructured_label` | Not structured label line 1 (first 70 characters) |
| LCS | `structured_label` | Structured label |
| LIB | `free_label` | Free label |
| MMO | `original_currency`, `original_amount`, `exchange_rate` | Amount and currency if it has been converted from a foreign currency. The `original_amount` is unsigned, meaning it is always non-negative. |
| NBE | `creditor` | Name of the creditor or beneficiary |
| NBU | `ultimate_creditor` | Name of the ultimate creditor or payer |
| NPO | `ultimate_debtor` | Name of the ultimate debtor or beneficiary |
| NPY | `debtor` | Name of the debtor or payer |
| RCN | `client_reference`, `purpose` | Client reference and Payment nature/purpose |
| REF | `operation_reference` | Bank operation reference |

TODO:
| Detail Code | Attributes | Description |
| --- | --- | --- |
| NPO | `ultimate_debtor` | Name of the ultimate debtor or beneficiary |
| NBU | `ultimate_creditor` | Name of the ultimate creditor or payer |
| RET | `unifi_code`, `sit_code`, `payback_label` | Payback informations |
| CBE | `creditor_account` | Account of the creditor or beneficiary |
| BDB | `creditor_bank` | Bank of the creditor or beneficiary |
Expand Down
2 changes: 1 addition & 1 deletion cfonb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Gem::Specification.new do |s|
s.name = 'cfonb'
s.version = '1.0.0'
s.required_ruby_version = '>= 3.3'
s.required_ruby_version = '>= 3.2'
s.summary = 'CFONB parser'
s.description = 'An easy to use CFONB format parser'
s.authors = ['Johan Le Bray', 'Frantisek Rokusek']
Expand Down
3 changes: 0 additions & 3 deletions lib/cfonb/details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,5 @@

module CFONB
class Details
def initialize(reference)
@reference = reference
end
end
end
3 changes: 2 additions & 1 deletion lib/cfonb/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def initialize(line)
self.value_date = line.value_date
self.label = line.label.strip
self.number = line.number
self.details = Details.new(line.reference)
self.reference = line.reference
self.details = Details.new
end

def merge_detail(line)
Expand Down
8 changes: 2 additions & 6 deletions lib/cfonb/operation_details/rcn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@ module OperationDetails
class RCN < Base
using CFONB::Refinements::Strings

ATTRIBUTES = %i[reference purpose].freeze
ATTRIBUTES = %i[client_reference purpose].freeze

def self.apply(details, line)
details.reference = [
details.reference,
line.detail[0..34].strip,
].filter_map(&:presence).join(' - ')

details.client_reference = line.detail[0..34].strip
details.purpose = line.detail[35..-1]&.strip
end

Expand Down
7 changes: 2 additions & 5 deletions lib/cfonb/operation_details/ref.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ module OperationDetails
class REF < Base
using CFONB::Refinements::Strings

ATTRIBUTES = %i[reference].freeze
ATTRIBUTES = %i[operation_reference].freeze

def self.apply(details, line)
details.reference = [
details.reference,
line.detail.strip,
].filter_map(&:presence).join(' - ')
details.operation_reference = line.detail.strip
end

CFONB::OperationDetails.register('REF', self)
Expand Down
8 changes: 4 additions & 4 deletions spec/cfonb/operation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@
)
end

it 'adds the reference information' do
it 'adds the client reference information' do
operation.merge_detail(detail)

expect(operation.details.reference).to eq('42 - SWILE-CMD-TR-YPDHMA')
expect(operation.details.client_reference).to eq('SWILE-CMD-TR-YPDHMA')
expect(operation.details.purpose).to eq('TICKET RESTO')
end
end
Expand All @@ -180,10 +180,10 @@
)
end

it 'adds the reference information' do
it 'adds the operation reference information' do
operation.merge_detail(detail)

expect(operation.details.reference).to eq('42 - PENNYLANE B13A93908C36C82DF5C319/1')
expect(operation.details.operation_reference).to eq('PENNYLANE B13A93908C36C82DF5C319/1')
end
end

Expand Down
46 changes: 26 additions & 20 deletions spec/cfonb/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)
expect(statements[0].operations[0].details).to have_attributes(
free_label: 'MENSUEAUHTR13133',
Expand All @@ -62,11 +63,11 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: 'REFERENCE',
)

expect(statements[0].operations[1].details).to have_attributes(
debtor: 'ELEC ERDF',
reference: 'REFERENCE',
free_label: nil,
original_currency: nil,
original_amount: nil,
Expand All @@ -86,10 +87,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[0].operations[2].details).to have_attributes(
reference: '',
free_label: nil,
purpose: nil,
original_currency: nil,
Expand Down Expand Up @@ -122,11 +123,11 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[1].operations[0].details).to have_attributes(
free_label: 'P051928612 22793301700040',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -146,10 +147,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[1].operations[1].details).to have_attributes(
reference: '',
free_label: nil,
original_currency: nil,
original_amount: nil,
Expand All @@ -170,10 +171,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)

expect(statements[1].operations[2].details).to have_attributes(
reference: '',
free_label: nil,
original_currency: nil,
original_amount: nil,
Expand Down Expand Up @@ -270,9 +271,10 @@
)

expect(statements[0].operations[0].details).to have_attributes(
operation_reference: 'REFERENCE',
free_label: 'MENSUEAUHTR13133',
debtor: 'INTERNET SFR',
reference: 'REFERENCE - OTHER REFERENCE',
client_reference: 'OTHER REFERENCE',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -289,10 +291,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: 'REFERENCE',
)

expect(statements[0].operations[1].details).to have_attributes(
reference: 'REFERENCE',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -311,10 +313,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[0].operations[2].details).to have_attributes(
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand Down Expand Up @@ -345,11 +347,11 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[1].operations[0].details).to have_attributes(
free_label: 'P051928612 22793301700040',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -367,10 +369,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 15),
reference: '',
)

expect(statements[1].operations[1].details).to have_attributes(
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -388,10 +390,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)

expect(statements[1].operations[2].details).to have_attributes(
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -417,11 +419,11 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)

expect(statements[0].operations[0].details).to have_attributes(
debtor: 'ELEC ERDF',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -447,10 +449,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)
expect(statements[0].operations[0].details).to have_attributes(
debtor: 'ELEC ERDF',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -476,10 +478,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)
expect(statements[0].operations[0].details).to have_attributes(
debtor: 'ELEC ERDF',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -505,10 +507,10 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)
expect(statements[0].operations[0].details).to have_attributes(
debtor: 'ELEC ERDF',
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand All @@ -525,9 +527,9 @@
rejection_code: '',
unavailability_code: '0',
value_date: Date.new(2019, 5, 16),
reference: '',
)
expect(statements[0].operations[1].details).to have_attributes(
reference: '',
original_currency: nil,
original_amount: nil,
exchange_rate: nil,
Expand Down Expand Up @@ -570,7 +572,8 @@
value_date: Date.new(2019, 5, 16),
)
expect(operation.details).to have_attributes(
reference: 'REFERENCE - OTHER REFERENCE',
operation_reference: 'REFERENCE',
client_reference: 'OTHER REFERENCE',
debtor: 'INTERNET SFR',
free_label: 'MENSUEAUHTR13133',
original_currency: nil,
Expand Down Expand Up @@ -633,7 +636,8 @@
value_date: Date.new(2019, 5, 16),
)
expect(operation.details).to have_attributes(
reference: 'REFERENCE - OTHER REFERENCE',
operation_reference: 'REFERENCE',
client_reference: 'OTHER REFERENCE',
free_label: 'MENSUEAUHTR13133',
debtor: 'INTERNET SFR',
original_currency: nil,
Expand Down Expand Up @@ -661,7 +665,8 @@
value_date: Date.new(2019, 5, 16),
)
expect(operation.details).to have_attributes(
reference: 'REFERENCE - OTHER REFERENCE',
client_reference: 'OTHER REFERENCE',
operation_reference: 'REFERENCE',
free_label: 'MENSUEAUHTR13133',
debtor: 'INTERNET SFR',
original_currency: nil,
Expand Down Expand Up @@ -698,7 +703,8 @@
)

expect(operation.details).to have_attributes(
reference: 'REFERENCE - OTHER REFERENCE',
operation_reference: 'REFERENCE',
client_reference: 'OTHER REFERENCE',
free_label: "MENSUEAUHTR13133\nP051928612 22793301700040",
debtor: 'ELEC ERDF',
original_currency: nil,
Expand Down

0 comments on commit da55d6a

Please sign in to comment.