Sha256: cbf04d6f4e7ca5eeab038d062d30e618e77a83ad46aa48b7884ff80dea849a49
Contents?: true
Size: 472 Bytes
Versions: 10
Compression:
Stored size: 472 Bytes
Contents
# frozen_string_literal: true class SedolValidator < BaseValidator REGEXP ||= /^([A-Z0-9]{6})(\d{1})$/.freeze WEIGHTS ||= [ 1, 3, 1, 7, 3, 9, 1 ].freeze private def valid_attr? valid_regexp? && valid_checksum? end def valid_checksum? total = 0 digits = value.chars.map { |dgt| /[A-Z]/.match?(dgt) ? (dgt.ord - 55) : dgt.to_i } digits.each_with_index { |dgt, idx| total += (WEIGHTS[idx] * dgt) } (10 - total % 10) % 10 end end
Version data entries
10 entries across 10 versions & 1 rubygems