Simplify SiretFormatValidator

We can remove nil checks as we never get nil
values
This commit is contained in:
gregoirenovel 2018-09-18 22:27:38 +02:00
parent 4e4b7c617f
commit 9d18f4187c

View file

@ -14,12 +14,12 @@ class SiretFormatValidator < ActiveModel::EachValidator
LA_POSTE_SIREN = '356000000' LA_POSTE_SIREN = '356000000'
def format_is_valid(value) def format_is_valid(value)
value&.match?(/^\d{14}$/) value.match?(/^\d{14}$/)
end end
def luhn_passed(value) def luhn_passed(value)
# Do not enforce Luhn for La Poste SIRET numbers, the only exception to this rule # Do not enforce Luhn for La Poste SIRET numbers, the only exception to this rule
value.present? && (siret_is_attached_to_la_poste(value) || (luhn_checksum(value) % 10 == 0)) siret_is_attached_to_la_poste(value) || (luhn_checksum(value) % 10 == 0)
end end
def siret_is_attached_to_la_poste(value) def siret_is_attached_to_la_poste(value)