class SecurityIdentifiers::Base
Attributes
original_check_digit[R]
Public Instance Methods
to_s()
click to toggle source
# File lib/security_identifiers/base.rb, line 12 def to_s "#{@identifier}#{check_digit}" end
valid?()
click to toggle source
# File lib/security_identifiers/base.rb, line 8 def valid? @original_check_digit.to_i == check_digit end
Private Instance Methods
digits()
click to toggle source
# File lib/security_identifiers/base.rb, line 25 def digits @digits ||= @identifier.each_char.flat_map { |char| digits_for(char) } end
digits_for(char)
click to toggle source
# File lib/security_identifiers/base.rb, line 18 def digits_for(char) return char.to_i unless char =~ /[A-Z]/ ord = char.to_i(36) [ord / 10, ord % 10] end
even_values()
click to toggle source
# File lib/security_identifiers/base.rb, line 29 def even_values @even_values ||= digits.select.with_index(1) { |digit, i| i.even? && digit } end
fix!()
click to toggle source
# File lib/security_identifiers/base.rb, line 37 def fix! @original_check_digit = check_digit end
mod_10(sum)
click to toggle source
# File lib/security_identifiers/base.rb, line 41 def mod_10(sum) (10 - sum % 10) % 10 end
odd_values()
click to toggle source
# File lib/security_identifiers/base.rb, line 33 def odd_values @odd_values ||= digits.select.with_index(1) { |digit, i| i.odd? && digit } end