swiss_bank_validator 0.5.1 → 0.6.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: '048f3b65cc5d822f99fdc697a857846e63347736b0f2d2c8a202278f20a56f0b'
4
- data.tar.gz: 8e9e8da97b9a658c90c10c3803304e97ed46b867997f4ac3c1d62af1fa0af982
3
+ metadata.gz: c95af9dbac771f3438878918843a5c83977c9788cb5184664b1f5fc7a377c60d
4
+ data.tar.gz: 3fcffd6c211e8fbe883eec96f8102c80a2014383053f821e10154c316316afa0
5
5
  SHA512:
6
- metadata.gz: 862acd1cf148b2bcf065f19fcc6e0707f73776c2d09b234df7f067a58727661b6ed101de924d708117362f84b3e692106d397e5d4789f196880f61112cf0ae57
7
- data.tar.gz: e2bc64e6c71bfc3f0399d9634de95fe4e4a9cacb73f05cf400e05655dc823aca59cfb675b50d0ca9ca3f579db5a0179b4e317121258b048beba6904600375cc0
6
+ metadata.gz: 1978ceb8d56297d4e1e67407ecddcebac4885ed0c218ec0bd8abd480014cb89b1aef74297f09c807d24bc4bcb9b325e2cba93f9088101e8cba3884f567ca7120
7
+ data.tar.gz: 347b4812293f6d5d926b7a3f02ac5d76e9aa2044742398a2d65339d9be5196e74fb64718769ece883cf6ae40135784c95e1a2d090d5ec0fcffe886c5d32f1e82
@@ -8,4 +8,7 @@ Metrics/MethodLength:
8
8
  Max: 20
9
9
 
10
10
  Metrics/BlockLength:
11
- Max: 50
11
+ Max: 50
12
+
13
+ Style/RegexpLiteral:
14
+ EnforcedStyle: mixed
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [0.6.0]
9
+
10
+ - Add validation for bank field that not accept special char
11
+
8
12
  ## [0.5.1]
9
13
 
10
14
  - Change FR translation
@@ -4,6 +4,7 @@ module SwissBankValidator
4
4
  require 'swiss_bank_validator/version'
5
5
  require 'swiss_bank_validator/constants'
6
6
  require 'swiss_bank_validator/validates_iban_format_of'
7
+ require 'swiss_bank_validator/validates_bank_field_of'
7
8
 
8
9
  I18n.load_path += Dir[File.join(__dir__, 'swiss_bank_validator/locale/*.yml')]
9
10
  end
@@ -3,4 +3,10 @@
3
3
  module SwissBankValidator
4
4
  IBAN_REGEX = /\ACH[A-Z0-9]{2}\d{5}[A-Z0-9]{12}\z/.freeze
5
5
  IBAN_LENGTH = 21
6
+
7
+ # Regex that allow only field accepted by Swiss bank to initiate a payment
8
+ # rubocop:disable Style/RedundantRegexpEscape
9
+ BANK_REGEX = %r{\A[a-zA-Z0-9\.\,\;\:\’\+\-\(\)\?\*\[\]\{\}\`\´\~\'\s\!\“#%÷=@_$£àáâäçèéêëìíîïñòóôöùúûüýßÀÁÂÄÇÈÉÊËÌÍÎÏ
10
+ ÒÓÔÖÙÚÛÜÑ]*\z}.freeze
11
+ # rubocop:enable Style/RedundantRegexpEscape
6
12
  end
@@ -6,6 +6,7 @@ de:
6
6
  space_not_authorized_in_iban: Abstände sind nicht zugelassen.
7
7
  iban_format_not_valid: Das Format der angegebenen IBAN ist nicht gültig.
8
8
  must_start_with_ch: "Beginnt mit CH"
9
+ invalid_bank_field: Sonderzeichen (&/<>°\|...) sind nicht erlaubt.
9
10
 
10
11
  activerecord:
11
12
  <<: *activemodel
@@ -6,6 +6,7 @@ en:
6
6
  space_not_authorized_in_iban: "Spaces are not authorized"
7
7
  iban_format_not_valid: "Your IBAN format is not valid"
8
8
  must_start_with_ch: "Must start with CH"
9
+ invalid_bank_field: Not a valid Bank field. It does not accept special character (&/<>°\|...)
9
10
 
10
11
  activerecord:
11
12
  <<: *activemodel
@@ -6,6 +6,8 @@ fr:
6
6
  space_not_authorized_in_iban: "Les espaces ne sont pas autorisés"
7
7
  iban_format_not_valid: "Le format de l'IBAN n'est pas valide"
8
8
  must_start_with_ch: "doit commencer par CH"
9
+ invalid_bank_field: Ce champ n'accepte pas certains caractères spéciaux (&/<>°\|...)
10
+
9
11
 
10
12
  activerecord:
11
13
  <<: *activemodel
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Based on http://www.swissiban.com/fr.htm
4
+ module ActiveModel
5
+ module Validations
6
+ class BankFieldValidator < EachValidator
7
+ def validate_each(record, attribute, value)
8
+ return if value.blank? && options[:allow_blank]
9
+ return if value.nil? && options[:allow_nil]
10
+
11
+ return if value.to_s =~ SwissBankValidator::BANK_REGEX
12
+
13
+ record.errors.add(
14
+ attribute,
15
+ :invalid_bank_field,
16
+ message: options[:message]
17
+ )
18
+ end
19
+ end
20
+
21
+ module ClassMethods
22
+ # Validates whether or not the specified field bank complient.
23
+ #
24
+ # class Account < ActiveRecord::Base
25
+ # validates_bank_field_of :name
26
+ # end
27
+ #
28
+ def validates_bank_field_of(*attr_names)
29
+ validates_with BankFieldValidator, _merge_attributes(attr_names)
30
+ end
31
+
32
+ alias validates_bank_field validates_bank_field_of
33
+ end
34
+ end
35
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwissBankValidator
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swiss_bank_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - QoQa dev Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-02 00:00:00.000000000 Z
11
+ date: 2020-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -77,6 +77,7 @@ files:
77
77
  - lib/swiss_bank_validator/locale/de.yml
78
78
  - lib/swiss_bank_validator/locale/en.yml
79
79
  - lib/swiss_bank_validator/locale/fr.yml
80
+ - lib/swiss_bank_validator/validates_bank_field_of.rb
80
81
  - lib/swiss_bank_validator/validates_iban_format_of.rb
81
82
  - lib/swiss_bank_validator/version.rb
82
83
  - swiss_bank_validator.gemspec