Sha256: 1db96b0fe3675585c20faf638eca06cdfacd45b9b08ff1a99b4fff8b506ffb14
Contents?: true
Size: 468 Bytes
Versions: 2
Compression:
Stored size: 468 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lite-validators-1.2.0 | lib/lite/validators/sedol_validator.rb |
lite-validators-1.1.2 | lib/lite/validators/sedol_validator.rb |