Sha256: 27967f865ce82e5f1edf7dd8d967df14b4b9e52063941ea399465e172fd6de7b
Contents?: true
Size: 736 Bytes
Versions: 4
Compression:
Stored size: 736 Bytes
Contents
require "attr_extras/explicit" require "banktools-gb/errors" module BankTools module GB class SortCode extend AttrExtras.mixin LENGTH = 6 pattr_initialize :original_value def valid? errors.none? end def errors errors = [] errors << Errors::SORT_CODE_TOO_SHORT if compacted_value.length < LENGTH errors << Errors::SORT_CODE_TOO_LONG if compacted_value.length > LENGTH errors << Errors::SORT_CODE_INVALID_CHARACTERS if any_non_digits? errors end def compacted_value original_value.to_s.gsub(/[\s-]/, "") end private def any_non_digits? compacted_value.match(/\D/) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems