class Faker::Medical::NPI
Public Class Methods
npi()
click to toggle source
# File lib/faker/medical/npi.rb, line 5 def npi x = [] 10.times do x << rand(10) end x.join end
valid?(num)
click to toggle source
TODO: Use the Luhn algorithm to validate the NPI
(by prefixing 80840)
# File lib/faker/medical/npi.rb, line 16 def valid?(num) odd = false num.to_s.gsub(/\D/,'').reverse.split('').map(&:to_i).collect { |d| d *= 2 if odd = !odd d > 9 ? d - 9 : d }.inject(:+) % 10 == 0 end