diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..db9844d --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,2 @@ +* @frantisekrokusek @jlebray @NathanBerthier +/doc/dependency_decisions.yml @pennylane-hq/appsec diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..f44558b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug Report ๐Ÿž +about: Found something that's not working as intended? Use this template to report a bug. +labels: "bug" +--- + + + +### Summary + + + +### Steps to reproduce + + + +### Expected behavior + + + +### Related Links + + + +[Related Issue ๐Ÿ”—]() +[Slack ๐Ÿงต]() +[Video/Loom ๐Ÿ“น]() +[PR ๐Ÿ”ƒ]() +[Notion ๐Ÿ“œ]() diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..4cbe4c9 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,60 @@ +name: Pre-commits + +on: [push] + +jobs: + checks: + name: Run pre-commit + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + + - name: Setup Environment + run: | + echo "NODE_VERSION=18.18.0" >> $GITHUB_ENV + echo "PYTHON_VERSION=$(cat .tool-versions | grep -Po '(?<=python ).*')" >> $GITHUB_ENV + echo "RUBY_VERSION=$(cat .tool-versions | grep -Po '(?<=ruby ).*')" >> $GITHUB_ENV + if [ $GITHUB_REF == 'refs/heads/master' ]; then echo "ENV=prod"; else echo "ENV=staging"; fi >> $GITHUB_ENV + echo "REPOSITORY_NAME=${GITHUB_REPOSITORY#*\/}" >> $GITHUB_ENV + + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ env.RUBY_VERSION }} + + - name: Install Ruby dependencies + run: bundle install + + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Store python version details for cache + run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> "$GITHUB_ENV" + + - name: Pre-commit installation cache + uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} + restore-keys: | + pre-commit|${{ env.PY }}| + + - name: Install pre-commit + run: | + python -m pip install pre-commit + pre-commit install --install-hooks + + - name: Run pre-commit checks + run: | + pre-commit run --all-files + + - name: Run license checks + run: | + pre-commit run license_checks --files doc/dependency_decisions.yml + + - name: Run specs + run: | + rspec diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..a0a0a3f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,89 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-added-large-files + - id: fix-byte-order-marker + - id: check-merge-conflict + - id: trailing-whitespace + exclude: (?x)( + \.yarn/| + spec/files/) + + - repo: https://github.com/tdeo/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: end-of-file-fixer + exclude: spec/files/ + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.8.0.1 + hooks: + - id: shellcheck + + - repo: local + hooks: + - id: do_not_commit + name: Break on DO NOT COMMIT comment + language: pygrep + entry: (?i)(NOT.{,3}COMMIT) + exclude: (?x)( + .pre-commit-config.yaml| + README.md) + - id: rubocop + name: Rubocop + language: system + entry: bash -c 'bundle exec rubocop ${RUBOCOP_OPTIONS:---autocorrect} "$@"' -- + require_serial: true # for proper cache behavior + files: (?x)( + \.(rb|rake|jbuilder|gemspec)$| + Gemfile$| + Rakefile| + .irbrc$) + args: + - --color + - --server + - --config=.rubocop.yml + - --fail-level=convention + - id: ruboclean + name: Ruboclean + language: system + entry: bundle exec ruboclean + files: ^\.rubocop.*\.yml$ + args: + - --silent + - --preserve-comments + - id: ruby + name: Valid ruby syntax + language: system + entry: ruby -c + files: \.rb$ + exclude: lib/templates/rspec/ + - id: prettier-json + name: Prettier JSON + language: system + entry: npx prettier --parser json --write + files: \.json$ + - id: prettier-yaml + name: Prettier YAML + language: system + entry: npx prettier --parser yaml --write + files: \.ya?ml$ + exclude: ^\.rubocop\.yml + - id: prettier-mdx + name: Prettier MDX + language: system + entry: npx prettier --parser mdx --write + files: \.mdx?$ + - id: whitespaces + name: No non-breaking spaces + language: pygrep + entry: \\u00A0 # Non-breaking space + exclude: (?x)^( + \.yarn/releases/| + \.pre-commit-config\.yaml) + - id: license_checks + name: License checks + language: system + entry: .pre-commit/check_license.sh + files: ^doc/dependency_decisions\.yml$ + pass_filenames: false diff --git a/.pre-commit/check_license.sh b/.pre-commit/check_license.sh new file mode 100755 index 0000000..9ba6880 --- /dev/null +++ b/.pre-commit/check_license.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -euo pipefail + +[ -z "${CI+1}" ] || exit 0 + +RESULT=$(bundle exec license_finder) +ERROR=$(cat <<-END +Some licenses are not approved! You need to run "bundle exec license_finder" to determine the missing licenses. +It appears the issues were the following: + +"$RESULT" + +Please check the licenses and especially commercial use terms, loop back to AppSec/Legal if needed. +Different way to approve a license, you can either accept a license kind: + +bundle exec license_finder permitted_licenses add "Zlib" + +Or specific packages: + +bundle exec license_finder approvals add pako + +Finally, please add the proper documentation and explanation in doc/dependency_decisions.yml +END +) + +if echo "$RESULT" | grep "All dependencies are approved for use" +then + exit 0 +else + echo "$ERROR" + exit 1 +fi diff --git a/.rubocop.yml b/.rubocop.yml index c784689..6703839 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,7 @@ --- + +require: rubocop-rspec + Layout/BlockAlignment: EnforcedStyleAlignWith: start_of_block diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..5c1708a --- /dev/null +++ b/.tool-versions @@ -0,0 +1,3 @@ +ruby 3.2.2 +nodejs 18.18.0 +python 3.9.12 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4046953 --- /dev/null +++ b/Gemfile @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '3.2.2' + +group :development do + # License + gem 'license_finder', require: false + + # Testing + gem 'rspec' + + # Linting + gem 'ruboclean', require: false + gem 'rubocop', require: false + gem 'rubocop-rspec', require: false +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..a64d11d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,81 @@ +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.2.6) + 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 + +DEPENDENCIES + license_finder + rspec + ruboclean + rubocop + rubocop-rspec + +RUBY VERSION + ruby 3.2.2p53 + +BUNDLED WITH + 2.4.12 diff --git a/cfonb.gemspec b/cfonb.gemspec index 6bb7367..5f84c71 100644 --- a/cfonb.gemspec +++ b/cfonb.gemspec @@ -1,14 +1,19 @@ # frozen_string_literal: true Gem::Specification.new do |s| - s.name = 'cfonb' - s.version = '0.0.4' - s.summary = 'CFONB parser' - s.description = 'An easy to use CFONB format parser' - s.authors = ['Johan Le Bray', 'Frantisek Rokusek'] - s.email = '' - s.files = Dir["{lib,spec}/**/*.rb"] - s.homepage = - 'https://github.com/pennylane-hq/cfonb' - s.license = 'MIT' + s.name = 'cfonb' + s.version = '0.0.4' + s.required_ruby_version = '>= 3.2.2' + s.summary = 'CFONB parser' + s.description = 'An easy to use CFONB format parser' + s.authors = ['Johan Le Bray', 'Frantisek Rokusek'] + s.email = '' + s.files = Dir['{lib,spec}/**/*.rb'] + s.homepage = 'https://github.com/pennylane-hq/cfonb' + s.license = 'MIT' + s.add_development_dependency('license_finder') + s.add_development_dependency('rspec') + s.add_development_dependency('ruboclean') + s.add_development_dependency('rubocop') + s.add_development_dependency('rubocop-rspec') end diff --git a/doc/dependency_decisions.yml b/doc/dependency_decisions.yml new file mode 100644 index 0000000..34efd68 --- /dev/null +++ b/doc/dependency_decisions.yml @@ -0,0 +1,195 @@ +--- +- - :ignore + - bundler + - :who: Security Team + :why: We don't want to track dependencies related to bundler + :versions: [] + :when: 2023-01-04 10:36:26.354664000 Z +- - :permit + - Apache 2.0 + - :who: Security Team + :why: Nothing prevents us from using Software under an Apache 2.0 license + :versions: [] + :when: 2023-01-04 11:08:39.243579000 Z +- - :permit + - Apache License (2.0) + - :who: Security Team + :why: Nothing prevents us from using a Software under an Apache License (2.0) + :versions: [] + :when: 2023-01-04 11:21:08.088008000 Z +- - :permit + - BlueOak-1.0.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a BlueOak-1.0.0 license + :versions: [] + :when: 2023-04-05 19:52:06.395699000 Z +- - :permit + - BSD + - :who: Security Team + :why: Nothing prevents us from using a Software under a BSD license + :versions: [] + :when: 2023-02-15 15:55:40.230856000 Z +- - :permit + - BSD Zero Clause License + - :who: Security Team + :why: Nothing prevents us from using a Software under a BSD Zero Clause License + :versions: [] + :when: 2023-01-04 11:11:14.266822000 Z +- - :permit + - CC0-1.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a CC0-1.0 license + :versions: [] + :when: 2023-01-04 11:22:38.314535000 Z +- - :permit + - CC-BY-3.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a CC-BY-3.0 license + :versions: [] + :when: 2023-01-04 13:32:05.258670000 Z +- - :permit + - CC-BY-4.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a CC-BY-4.0 license + :versions: [] + :when: 2023-01-04 11:29:42.668183000 Z +- - :permit + - GNU GENERAL PUBLIC LICENSE + - :who: Security Team + :why: + Nothing prevents us from using a Software under a General Public License + (GPL) + :versions: [] + :when: 2023-02-15 15:55:52.568378000 Z +- - :permit + - GPL-2 + - :who: Security Team + :why: Nothing prevents us from using a Software under a GPL-2 license + :versions: [] + :when: 2023-01-04 11:17:00.070704000 Z +- - :permit + - GPL-2.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a GPL-2.0 license + :versions: [] + :when: 2023-01-04 11:12:14.638096000 Z +- - :permit + - GPL-3.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a GPL-3.0 license + :versions: [] + :when: 2023-01-04 11:12:43.464889000 Z +- - :permit + - Hippocratic-2.1 + - :who: Security Team + :why: + Nothing prevents us from using an Hippocratic-2.1 license given that our + activity is ethical + :versions: [] + :when: 2023-02-15 16:19:19.242388000 Z +- - :permit + - ISC + - :who: Security Team + :why: Nothing prevents us from using Software under an ISC license + :versions: [] + :when: 2023-01-04 11:05:37.200861000 Z +- - :permit + - LGPL + - :who: Security Team + :why: Nothing prevents us from using a Software under an LGPL license + :versions: [] + :when: 2023-01-04 11:17:06.043252000 Z +- - :permit + - LGPLv2+ + - :who: Security Team + :why: Nothing prevents us from using a Software under an LGPLv2+ license + :versions: [] + :when: 2023-01-04 11:19:18.276262000 Z +- - :permit + - LGPLv3+ + - :who: Security Team + :why: Nothing prevents us from using a Software under an LGPLv3+ license + :versions: [] + :when: 2023-01-04 11:23:47.785431000 Z +- - :permit + - MIT + - :who: Security Team + :why: Nothing prevents us from using Software under an MIT license + :versions: [] + :when: 2023-01-04 10:47:24.811127000 Z +- - :permit + - Mozilla Public License 2.0 + - :who: Security Team + :why: + Nothing prevents us from using a Software under a Mozilla Public License + 2.0 + :versions: [] + :when: 2023-01-04 11:20:39.327719000 Z +- - :permit + - MPL2.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under an MPL2.0 license + :versions: [] + :when: 2023-01-04 11:27:17.192220000 Z +- - :permit + - New BSD + - :who: Security Team + :why: Nothing prevents us from using a Software under a New BSD license + :versions: [] + :when: 2023-01-04 11:13:57.645677000 Z +- - :permit + - Public Domain + - :who: Security Team + :why: Nothing prevents us from using a Software under a Public Domain license + :versions: [] + :when: 2023-01-04 11:21:32.054670000 Z +- - :permit + - Python-2.0 + - :who: Security Team + :why: Nothing prevents us from using a Software under a Python-2.0 license + :versions: [] + :when: 2023-01-04 13:38:06.455027000 Z +- - :permit + - ruby + - :who: Security Team + :why: Nothing prevents us from using a Software under a Ruby license + :versions: [] + :when: 2023-01-04 13:39:29.337769000 Z +- - :permit + - Simplified BSD + - :who: Security Team + :why: Nothing prevents us from using a Software under a Simplified BSD license + :versions: [] + :when: 2023-01-04 11:09:56.255153000 Z +- - :permit + - Unlicense + - :who: Security Team + :why: + Nothing prevents us from using a Software under an Unlicense as it similar + to Public Domain + :versions: [] + :when: 2023-01-04 13:29:39.503157000 Z +- - :permit + - WTFPL + - :who: Security Team + :why: Nothing prevents us from using a Software under a WTFPL license + :versions: [] + :when: 2023-01-04 11:22:03.357868000 Z +- - :permit + - Zlib + - :who: Security Team + :why: Nothing prevents us from using a Software under a Zlib license + :versions: [] + :when: 2023-02-15 15:56:37.443260000 Z +- - :permit + - 2-clause BSDL + - :who: Security Team + :why: Nothing prevents us from using a Software under a 2-clause BSDL license + :versions: [] + :when: 2023-01-04 11:19:59.403946000 Z +- - :permit + - EPL-2.0 + - :who: Legal team + :why: Nothing prevents us from using a Software under a EPL-2.0 license + :versions: [] + :when: 2023-07-05 12:43:05.575246000 Z diff --git a/lib/cfonb.rb b/lib/cfonb.rb index 4cc52fd..3541335 100644 --- a/lib/cfonb.rb +++ b/lib/cfonb.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'date' require_relative 'cfonb/refinements/strings' diff --git a/lib/cfonb/line_parser/base.rb b/lib/cfonb/line_parser/base.rb index 48a2df1..2f23512 100644 --- a/lib/cfonb/line_parser/base.rb +++ b/lib/cfonb/line_parser/base.rb @@ -14,7 +14,7 @@ class Base ['currency', (16..18)], ['scale', 19, proc { _1.to_i }], ['account', (21..31)], - ['date', (34..39), proc { |value, instance| instance.send(:parse_date, value) }] + ['date', (34..39), proc { |value, instance| instance.send(:parse_date, value) }], ].freeze AMOUNT_SPECIFIERS = { @@ -37,7 +37,7 @@ class Base 'P' => { sign: -1, value: '7' }, 'Q' => { sign: -1, value: '8' }, 'R' => { sign: -1, value: '9' }, - '}' => { sign: -1, value: '0' } + '}' => { sign: -1, value: '0' }, }.transform_values(&:freeze).freeze attr_reader :body, *BASE_DICTIONARY.map(&:first) @@ -58,7 +58,7 @@ def parse_attribute(attr, position, method = nil) def parse_amount(input) specifier = AMOUNT_SPECIFIERS[input.last] - raise ParserError, "Invalid specifier '#{input.last}' for line #{input}" unless specifier + raise ParserError.new("Invalid specifier '#{input.last}' for line #{input}") unless specifier specifier[:sign] * BigDecimal(input[0..-2] + specifier[:value]) / (10**scale) end @@ -68,14 +68,14 @@ def parse_date(input) return if input.strip.empty? input_with_year = if input.last(2).to_i > 60 - "#{input[0..3]}19#{input[4..5]}" - else - "#{input[0..3]}20#{input[4..5]}" - end + "#{input[0..3]}19#{input[4..5]}" + else + "#{input[0..3]}20#{input[4..5]}" + end Date.strptime(input_with_year, '%d%m%Y') rescue Date::Error - raise ParserError, "Invalid date '#{input}' for line #{input}" + raise ParserError.new("Invalid date '#{input}' for line #{input}") end end end diff --git a/lib/cfonb/line_parser/new_balance.rb b/lib/cfonb/line_parser/new_balance.rb index 4852e9b..32d5ca4 100644 --- a/lib/cfonb/line_parser/new_balance.rb +++ b/lib/cfonb/line_parser/new_balance.rb @@ -4,7 +4,7 @@ module CFONB module LineParser class NewBalance < Base DICTIONARY = [ - ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }] + ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }], ].freeze attr_reader(*DICTIONARY.map(&:first)) diff --git a/lib/cfonb/line_parser/operation.rb b/lib/cfonb/line_parser/operation.rb index ff9f405..0cd35ed 100644 --- a/lib/cfonb/line_parser/operation.rb +++ b/lib/cfonb/line_parser/operation.rb @@ -13,7 +13,7 @@ class Operation < Base ['exoneration_code', 88], ['unavailability_code', 89], ['reference', (104..119)], - ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }] + ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }], ].freeze attr_reader(*DICTIONARY.map(&:first)) diff --git a/lib/cfonb/line_parser/operation_detail.rb b/lib/cfonb/line_parser/operation_detail.rb index 07dadee..7886339 100644 --- a/lib/cfonb/line_parser/operation_detail.rb +++ b/lib/cfonb/line_parser/operation_detail.rb @@ -7,7 +7,7 @@ class OperationDetail < Base ['internal_operation_code', (7..10)], ['interbank_operation_code', (32..33)], ['detail_code', (45..47)], - ['detail', (48..117)] + ['detail', (48..117)], ].freeze attr_reader(*DICTIONARY.map(&:first)) diff --git a/lib/cfonb/line_parser/previous_balance.rb b/lib/cfonb/line_parser/previous_balance.rb index 522a1c6..a48ab72 100644 --- a/lib/cfonb/line_parser/previous_balance.rb +++ b/lib/cfonb/line_parser/previous_balance.rb @@ -4,7 +4,7 @@ module CFONB module LineParser class PreviousBalance < Base DICTIONARY = [ - ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }] + ['amount', (90..103), proc { |value, instance| instance.send(:parse_amount, value) }], ].freeze attr_reader(*DICTIONARY.map(&:first)) diff --git a/lib/cfonb/operation_detail/ref.rb b/lib/cfonb/operation_detail/ref.rb index 96fa864..2e748e4 100644 --- a/lib/cfonb/operation_detail/ref.rb +++ b/lib/cfonb/operation_detail/ref.rb @@ -10,7 +10,7 @@ class REF def self.apply(operation, line) operation.reference = [ operation.reference, - line.detail.strip + line.detail.strip, ].filter_map(&:presence).join(' - ') end diff --git a/lib/cfonb/parser.rb b/lib/cfonb/parser.rb index 3be4cd2..7b4dcb3 100644 --- a/lib/cfonb/parser.rb +++ b/lib/cfonb/parser.rb @@ -8,7 +8,7 @@ class Parser PREVIOUS_BALANCE_CODE = '01', OPERATION_CODE = '04', OPERATION_DETAIL_CODE = '05', - NEW_BALANCE_CODE = '07' + NEW_BALANCE_CODE = '07', ].freeze def initialize(input) @@ -52,7 +52,7 @@ def each_line def parse_line(line) return if line.strip.empty? - raise InvalidCodeError, "Invalid line code '#{line.first(2)}'" unless CODES.include?(line.first(2)) + raise InvalidCodeError.new("Invalid line code '#{line.first(2)}'") unless CODES.include?(line.first(2)) line = CFONB::LineParser.parse(line) @@ -97,7 +97,7 @@ def parse_operation_line(line) current_operation.merge_detail(line) else - return handle_error(UnhandledLineCodeError) + handle_error(UnhandledLineCodeError) end end diff --git a/lib/cfonb/statement.rb b/lib/cfonb/statement.rb index ea5f85a..aeadbf1 100644 --- a/lib/cfonb/statement.rb +++ b/lib/cfonb/statement.rb @@ -9,7 +9,7 @@ class Statement from from_balance to to_balance operations - ] + ], ) def initialize(line) @@ -33,7 +33,7 @@ def raw [ begin_raw, operations.map(&:raw), - end_raw + end_raw, ].join("\n") end diff --git a/spec/cfonb/line_parser/new_balance_spec.rb b/spec/cfonb/line_parser/new_balance_spec.rb index a479efb..1ae129d 100644 --- a/spec/cfonb/line_parser/new_balance_spec.rb +++ b/spec/cfonb/line_parser/new_balance_spec.rb @@ -19,7 +19,7 @@ 'scale' => 2, 'account' => '98765432100', 'date' => Date.new(2019, 5, 15), - 'amount' => -190.43 + 'amount' => -190.43, ) end end diff --git a/spec/cfonb/line_parser/operation_detail_spec.rb b/spec/cfonb/line_parser/operation_detail_spec.rb index ed230f8..fb5b520 100644 --- a/spec/cfonb/line_parser/operation_detail_spec.rb +++ b/spec/cfonb/line_parser/operation_detail_spec.rb @@ -22,7 +22,7 @@ 'internal_operation_code' => '9162', 'interbank_operation_code' => 'B1', 'detail_code' => 'LIB', - 'detail' => 'MENSUEAUHTR13133' + 'detail' => 'MENSUEAUHTR13133', ) end end diff --git a/spec/cfonb/line_parser/operation_spec.rb b/spec/cfonb/line_parser/operation_spec.rb index 9c4b2e1..523e3b3 100644 --- a/spec/cfonb/line_parser/operation_spec.rb +++ b/spec/cfonb/line_parser/operation_spec.rb @@ -28,7 +28,7 @@ 'number' => 7_654_321, 'exoneration_code' => 'U', 'unavailability_code' => 'P', - 'reference' => 'XYZ123' + 'reference' => 'XYZ123', ) end end diff --git a/spec/cfonb/line_parser/previous_balance_spec.rb b/spec/cfonb/line_parser/previous_balance_spec.rb index ba38a80..1e2d11f 100644 --- a/spec/cfonb/line_parser/previous_balance_spec.rb +++ b/spec/cfonb/line_parser/previous_balance_spec.rb @@ -19,7 +19,7 @@ 'scale' => 2, 'account' => '98765432100', 'date' => Date.new(2019, 5, 15), - 'amount' => -190.43 + 'amount' => -190.43, ) end end diff --git a/spec/cfonb/operation_spec.rb b/spec/cfonb/operation_spec.rb index 93166ae..b5428f5 100644 --- a/spec/cfonb/operation_spec.rb +++ b/spec/cfonb/operation_spec.rb @@ -13,7 +13,7 @@ date: Date.new(2021, 3, 5), currency: 'EUR', amount: -15, - reference: '42' + reference: '42', ) end @@ -88,7 +88,7 @@ expect(operation).to have_attributes( original_currency: 'USD', - original_amount: -12.34 + original_amount: -12.34, ) end end @@ -118,7 +118,7 @@ OpenStruct.new( body: '', detail_code: 'RCN', - detail: 'SWILE-CMD-TR-YPDHMA TICKET RESTO ' + detail: 'SWILE-CMD-TR-YPDHMA TICKET RESTO ', ) end @@ -135,7 +135,7 @@ OpenStruct.new( body: '0530002112701731EUR2E0000073337DA129082300 REFPENNYLANE B13A93908C36C82DF5C319/1 ', detail_code: 'REF', - detail: 'PENNYLANE B13A93908C36C82DF5C319/1 ' + detail: 'PENNYLANE B13A93908C36C82DF5C319/1 ', ) end @@ -151,7 +151,7 @@ OpenStruct.new( body: '0530004411001871EUR2 0001016255614090823 FEEEUR200000000000740', detail_code: 'FEE', - detail: 'EUR200000000000740' + detail: 'EUR200000000000740', ) end diff --git a/spec/cfonb/parser_spec.rb b/spec/cfonb/parser_spec.rb index 24a87e9..3030f9a 100644 --- a/spec/cfonb/parser_spec.rb +++ b/spec/cfonb/parser_spec.rb @@ -12,7 +12,7 @@ it 'parses correctly' do expect(statements).to contain_exactly( an_instance_of(CFONB::Statement), - an_instance_of(CFONB::Statement) + an_instance_of(CFONB::Statement), ) expect(statements[0]).to have_attributes( @@ -23,7 +23,7 @@ from: Date.new(2019, 5, 15), from_balance: -190.4, to: Date.new(2019, 5, 16), - to_balance: -241.21 + to_balance: -241.21, ) expect(statements[0].operations.size).to eq(3) @@ -44,7 +44,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'INTERNET SFR' + debtor: 'INTERNET SFR', ) expect(statements[0].operations[1]).to have_attributes( @@ -62,7 +62,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) expect(statements[0].operations[2]).to have_attributes( @@ -79,7 +79,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1]).to have_attributes( @@ -90,7 +90,7 @@ from: Date.new(2019, 5, 16), from_balance: -241.21, to: Date.new(2019, 5, 17), - to_balance: -163.72 + to_balance: -163.72, ) expect(statements[1].operations.size).to eq(3) @@ -109,7 +109,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1].operations[1]).to have_attributes( @@ -126,7 +126,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1].operations[2]).to have_attributes( @@ -143,7 +143,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 16), original_currency: nil, - original_amount: nil + original_amount: nil, ) end end @@ -203,7 +203,7 @@ it 'parses correctly' do expect(statements).to contain_exactly( an_instance_of(CFONB::Statement), - an_instance_of(CFONB::Statement) + an_instance_of(CFONB::Statement), ) expect(statements[0]).to have_attributes( @@ -214,7 +214,7 @@ from: Date.new(2019, 5, 15), from_balance: -190.4, to: Date.new(2019, 5, 16), - to_balance: -241.21 + to_balance: -241.21, ) expect(statements[0].operations.size).to eq(3) @@ -234,7 +234,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'INTERNET SFR' + debtor: 'INTERNET SFR', ) expect(statements[0].operations[1]).to have_attributes( @@ -252,7 +252,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) expect(statements[0].operations[2]).to have_attributes( @@ -269,7 +269,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1]).to have_attributes( @@ -280,7 +280,7 @@ from: Date.new(2019, 5, 16), from_balance: -241.21, to: Date.new(2019, 5, 17), - to_balance: -163.72 + to_balance: -163.72, ) expect(statements[1].operations.size).to eq(3) @@ -299,7 +299,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1].operations[1]).to have_attributes( @@ -316,7 +316,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 15), original_currency: nil, - original_amount: nil + original_amount: nil, ) expect(statements[1].operations[2]).to have_attributes( @@ -333,7 +333,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 16), original_currency: nil, - original_amount: nil + original_amount: nil, ) end end @@ -359,7 +359,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) end end @@ -385,7 +385,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) end end @@ -411,7 +411,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) end end @@ -437,7 +437,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) expect(statements[0].operations[1]).to have_attributes( amount: -7.9, @@ -453,7 +453,7 @@ unavailability_code: '0', value_date: Date.new(2019, 5, 16), original_currency: nil, - original_amount: nil + original_amount: nil, ) end end @@ -494,7 +494,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'INTERNET SFR' + debtor: 'INTERNET SFR', ) end end @@ -553,7 +553,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'INTERNET SFR' + debtor: 'INTERNET SFR', ) end end @@ -577,7 +577,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'INTERNET SFR' + debtor: 'INTERNET SFR', ) end end @@ -609,7 +609,7 @@ value_date: Date.new(2019, 5, 16), original_currency: nil, original_amount: nil, - debtor: 'ELEC ERDF' + debtor: 'ELEC ERDF', ) end end diff --git a/spec/cfonb/statement_spec.rb b/spec/cfonb/statement_spec.rb index 6dd4bd8..118fcdc 100644 --- a/spec/cfonb/statement_spec.rb +++ b/spec/cfonb/statement_spec.rb @@ -5,8 +5,8 @@ describe CFONB::Statement do subject(:statement) do described_class.new(begin_line) - .tap { _1.operations << operation } - .tap { _1.merge_new_balance(end_line) } + .tap { _1.operations << operation } + .tap { _1.merge_new_balance(end_line) } end let(:operation) do @@ -17,22 +17,22 @@ let(:begin_line) do CFONB::LineParser.parse( - '0115589 00000EUR2 98765432100 150519 0000000001904}150519160519 ' + '0115589 00000EUR2 98765432100 150519 0000000001904}150519160519 ', ) end let(:operation_line) do CFONB::LineParser.parse( - '0415589916200000EUR2 98765432100B1160519 160519PRLV SEPA TEST CABINET 0000000000000000000322J ' + '0415589916200000EUR2 98765432100B1160519 160519PRLV SEPA TEST CABINET 0000000000000000000322J ', ) end let(:detail_line) do CFONB::LineParser.parse( - '0515589916200000EUR2 98765432100B1160519 LIBMENSUEAUHTR13133 ' + '0515589916200000EUR2 98765432100B1160519 LIBMENSUEAUHTR13133 ', ) end let(:end_line) do CFONB::LineParser.parse( - '0715489 00000EUR2 98765432100 160519 0000000002412J ' + '0715489 00000EUR2 98765432100 160519 0000000002412J ', ) end