swiss_bank_validator 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/changelog.md +4 -0
- data/lib/swiss_bank_validator.rb +1 -0
- data/lib/swiss_bank_validator/constants.rb +6 -0
- data/lib/swiss_bank_validator/locale/de.yml +1 -0
- data/lib/swiss_bank_validator/locale/en.yml +1 -0
- data/lib/swiss_bank_validator/locale/fr.yml +2 -0
- data/lib/swiss_bank_validator/validates_bank_field_of.rb +35 -0
- data/lib/swiss_bank_validator/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c95af9dbac771f3438878918843a5c83977c9788cb5184664b1f5fc7a377c60d
|
4
|
+
data.tar.gz: 3fcffd6c211e8fbe883eec96f8102c80a2014383053f821e10154c316316afa0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1978ceb8d56297d4e1e67407ecddcebac4885ed0c218ec0bd8abd480014cb89b1aef74297f09c807d24bc4bcb9b325e2cba93f9088101e8cba3884f567ca7120
|
7
|
+
data.tar.gz: 347b4812293f6d5d926b7a3f02ac5d76e9aa2044742398a2d65339d9be5196e74fb64718769ece883cf6ae40135784c95e1a2d090d5ec0fcffe886c5d32f1e82
|
data/.rubocop.yml
CHANGED
data/changelog.md
CHANGED
@@ -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
|
data/lib/swiss_bank_validator.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|