Sha256: 4026eeb0584188e57c726befb1109842a958f53cdd39a57a4ed211dc60f1ce89

Contents?: true

Size: 537 Bytes

Versions: 2

Compression:

Stored size: 537 Bytes

Contents

module Faker
  module Medical
    class NPI < Base
      class << self
        def npi
          x = []

          10.times do
            x << rand(10)
          end

          x.join
        end

        # TODO: Use the Luhn algorithm to validate the NPI (by prefixing 80840)
        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
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
faker-medical-0.5.2 lib/faker/medical/npi.rb
faker-medical-0.5.1 lib/faker/medical/npi.rb