class Faker::NationalHealthService
def check_digit(number: 0)
-
(Integer)-
Parameters:
-
number(Integer) -- Specifies the NHS number the check digit belongs to.
def check_digit(number: 0) sum = 0 number.to_s.chars.each_with_index do |digit, idx| position = idx + 1 sum += (digit.to_i * (11 - position)) end result = 11 - (sum % 11) # A value of 11 is considered the same as 0 # See https://en.wikipedia.org/wiki/NHS_number return 0 if result == 11 result end