Class: Faker::Medical::NPI
- Inherits:
-
Base
- Object
- Base
- Faker::Medical::NPI
- Defined in:
- lib/faker/medical/npi.rb
Class Method Summary collapse
- .npi ⇒ Object
-
.valid?(num) ⇒ Boolean
TODO: Use the Luhn algorithm to validate the NPI (by prefixing 80840).
Class Method Details
.npi ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/faker/medical/npi.rb', line 5 def npi x = [] 10.times do x << rand(10) end x.join end |
.valid?(num) ⇒ Boolean
TODO: Use the Luhn algorithm to validate the NPI (by prefixing 80840)
16 17 18 19 20 21 22 |
# 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 |