From 23f2a039afb8755dd27cde6427bde09454df0627 Mon Sep 17 00:00:00 2001 From: Laura Gil Date: Thu, 31 Oct 2024 09:07:07 +0100 Subject: [PATCH] Add IPY operation detail (#22) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Frantisek Rokusek Co-authored-by: RDeckard --- .gitignore | 2 + .ruby-version | 1 - Gemfile | 2 +- Gemfile.lock | 83 ------------------------------ README.md | 3 ++ cfonb.gemspec | 2 +- lib/cfonb.rb | 1 + lib/cfonb/line_parser/base.rb | 2 +- lib/cfonb/line_parser/operation.rb | 2 +- lib/cfonb/operation_detail/ipy.rb | 16 ++++++ spec/cfonb/operation_spec.rb | 22 +++++++- 11 files changed, 47 insertions(+), 89 deletions(-) create mode 100644 .gitignore delete mode 100644 .ruby-version delete mode 100644 Gemfile.lock create mode 100644 lib/cfonb/operation_detail/ipy.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7edb52d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.ruby-version +Gemfile.lock diff --git a/.ruby-version b/.ruby-version deleted file mode 100644 index be94e6f..0000000 --- a/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -3.2.2 diff --git a/Gemfile b/Gemfile index f1b24f3..5fe06c1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby '3.3.5' +gemspec group :development do # License diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index dec4bc5..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,83 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - ast (2.4.2) - diff-lcs (1.5.0) - json (2.6.3) - language_server-protocol (3.17.0.3) - license_finder (7.1.0) - bundler - rubyzip (>= 1, < 3) - thor (~> 1.2) - tomlrb (>= 1.3, < 2.1) - with_env (= 1.1.0) - xml-simple (~> 1.1.9) - parallel (1.23.0) - parser (3.2.2.4) - ast (~> 2.4.1) - racc - racc (1.7.1) - rainbow (3.1.1) - regexp_parser (2.8.2) - rexml (3.3.9) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.2) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.3) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.6) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.1) - ruboclean (0.4.0) - rubocop (1.57.2) - json (~> 2.3) - language_server-protocol (>= 3.17.0) - parallel (~> 1.10) - parser (>= 3.2.2.4) - rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.28.1, < 2.0) - ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.29.0) - parser (>= 3.2.1.0) - rubocop-capybara (2.19.0) - rubocop (~> 1.41) - rubocop-factory_bot (2.24.0) - rubocop (~> 1.33) - rubocop-rspec (2.24.1) - rubocop (~> 1.33) - rubocop-capybara (~> 2.17) - rubocop-factory_bot (~> 2.22) - ruby-progressbar (1.13.0) - rubyzip (2.3.2) - thor (1.3.0) - tomlrb (2.0.3) - unicode-display_width (2.5.0) - with_env (1.1.0) - xml-simple (1.1.9) - rexml - -PLATFORMS - arm64-darwin-22 - arm64-darwin-23 - x86_64-linux - -DEPENDENCIES - license_finder - rspec - ruboclean - rubocop - rubocop-rspec - -RUBY VERSION - ruby 3.3.5p100 - -BUNDLED WITH - 2.4.12 diff --git a/README.md b/README.md index a28353b..8a2ff46 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ CFONB::OperationDetail.register('FEE', self) | 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 | @@ -59,6 +60,8 @@ TODO: | Detail Code | Attributes | Description | | --- | --- | --- | | IPY | `debtor_identifier` | Identifier of the debtor or payer | +| 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 | diff --git a/cfonb.gemspec b/cfonb.gemspec index 83700c0..f3d542c 100644 --- a/cfonb.gemspec +++ b/cfonb.gemspec @@ -3,7 +3,7 @@ Gem::Specification.new do |s| s.name = 'cfonb' s.version = '0.0.7' - s.required_ruby_version = '>= 3.2.2' + 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'] diff --git a/lib/cfonb.rb b/lib/cfonb.rb index e20f0d0..cfbe50e 100644 --- a/lib/cfonb.rb +++ b/lib/cfonb.rb @@ -24,6 +24,7 @@ require_relative 'cfonb/operation_detail/mmo' require_relative 'cfonb/operation_detail/nbe' require_relative 'cfonb/operation_detail/npy' +require_relative 'cfonb/operation_detail/ipy' require_relative 'cfonb/operation_detail/rcn' require_relative 'cfonb/operation_detail/ref' require_relative 'cfonb/operation_detail/fee' diff --git a/lib/cfonb/line_parser/base.rb b/lib/cfonb/line_parser/base.rb index 2f23512..d0e3d4a 100644 --- a/lib/cfonb/line_parser/base.rb +++ b/lib/cfonb/line_parser/base.rb @@ -12,7 +12,7 @@ class Base ['bank', (2..6)], ['branch', (11..15)], ['currency', (16..18)], - ['scale', 19, proc { _1.to_i }], + ['scale', 19, proc { _1.to_i }], # rubocop:disable Style/SymbolProc ['account', (21..31)], ['date', (34..39), proc { |value, instance| instance.send(:parse_date, value) }], ].freeze diff --git a/lib/cfonb/line_parser/operation.rb b/lib/cfonb/line_parser/operation.rb index 0cd35ed..0d7d3fd 100644 --- a/lib/cfonb/line_parser/operation.rb +++ b/lib/cfonb/line_parser/operation.rb @@ -9,7 +9,7 @@ class Operation < Base ['rejection_code', (40..41)], ['value_date', (42..47), proc { |value, instance| instance.send(:parse_date, value) }], ['label', (48..79)], - ['number', (81..87), proc { _1.to_i }], + ['number', (81..87), proc { _1.to_i }], # rubocop:disable Style/SymbolProc ['exoneration_code', 88], ['unavailability_code', 89], ['reference', (104..119)], diff --git a/lib/cfonb/operation_detail/ipy.rb b/lib/cfonb/operation_detail/ipy.rb new file mode 100644 index 0000000..745b914 --- /dev/null +++ b/lib/cfonb/operation_detail/ipy.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module CFONB + module OperationDetail + class IPY + ATTRIBUTES = %i[debtor_identifier debtor_identifier_type].freeze + + def self.apply(operation, line) + operation.debtor_identifier = line.detail[0..34].strip + operation.debtor_identifier_type = line.detail[35..-1].strip + end + + CFONB::OperationDetail.register('IPY', self) + end + end +end diff --git a/spec/cfonb/operation_spec.rb b/spec/cfonb/operation_spec.rb index 8b43465..36f854c 100644 --- a/spec/cfonb/operation_spec.rb +++ b/spec/cfonb/operation_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true require 'cfonb' -require 'ostruct' require 'securerandom' +require 'ostruct' describe CFONB::Operation do subject(:operation) { described_class.new(line) } @@ -193,6 +193,26 @@ end end + context 'with a IPY detail' do + let(:debtor_identifier) { SecureRandom.alphanumeric(35) } + let(:debtor_identifier_type) { SecureRandom.alphanumeric(35) } + + let(:detail) do + OpenStruct.new( + body: "0530004411001871EUR2 0001016255614090823 IPY#{debtor_identifier}#{debtor_identifier_type}", + detail_code: 'IPY', + detail: "#{debtor_identifier}#{debtor_identifier_type}", + ) + end + + it 'adds the debtor_identifier' do + operation.merge_detail(detail) + + expect(operation.debtor_identifier).to eq(debtor_identifier) + expect(operation.debtor_identifier_type).to eq(debtor_identifier_type) + end + end + context 'with a IBE detail' do let(:creditor_identifier) { SecureRandom.alphanumeric(35) } let(:creditor_identifier_type) { SecureRandom.alphanumeric(35) }