Class: Faker::NationalHealthService

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/national_health_service.rb

Constant Summary

Constants inherited from Base

Base::LLetters, Base::Letters, Base::NOT_GIVEN, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, generate, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, shuffle!, translate, unique, with_locale

Class Method Details

.british_numberString

Produces a random British NHS number.

The NHS sets aside a range of numbers from 999 000 0000 to 999 999 9999 for test purposes.

Examples:

Faker::NationalHealthService.british_number #=> "999 464 0232"

Returns:

  • (String)

Available since:

  • 1.9.2



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faker/default/national_health_service.rb', line 18

def british_number
  base_number = rand(999_000_001...999_999_999)
  # If the check digit is equivalent to 10, the number is invalid.
  # See https://en.wikipedia.org/wiki/NHS_number
  base_number -= 1 if check_digit(number: base_number) == 10
  "#{base_number}#{check_digit(number: base_number)}".to_s
                                                     .chars
                                                     .insert(3, ' ')
                                                     .insert(7, ' ')
                                                     .join
end