Class: Faker::Demographic

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/demographic.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

.demonymString

Produces a denonym.

Examples:

Faker::Demographic.denonym #=> "Panamanian"

Returns:



41
42
43
# File 'lib/faker/default/demographic.rb', line 41

def demonym
  fetch('demographic.demonym')
end

.educational_attainmentString

Produces a level of educational attainment.

Examples:

Faker::Demographic.educational_attainment #=> "GED or alternative credential"

Returns:



28
29
30
# File 'lib/faker/default/demographic.rb', line 28

def educational_attainment
  fetch('demographic.educational_attainment')
end

.height(unit: :metric) ⇒ String

Produces a height as a string.

Examples:

Faker::Demographic.height #=> "1.61"
Faker::Demographic.height(unit: :imperial) #=> "6 ft, 2 in"

Parameters:

  • unit (Symbol) (defaults to: :metric)

    either ‘:metric` or `imperial`.

Returns:



83
84
85
86
87
88
89
90
91
# File 'lib/faker/default/demographic.rb', line 83

def height(unit: :metric)
  case unit
  when :imperial
    inches = rand_in_range(57, 86)
    "#{inches / 12} ft, #{inches % 12} in"
  when :metric
    rand_in_range(1.45, 2.13).round(2).to_s
  end
end

.marital_statusString

Produces a marital status.

Examples:

Faker::Demographic.marital_status #=> "Widowed"

Returns:



54
55
56
# File 'lib/faker/default/demographic.rb', line 54

def marital_status
  fetch('demographic.marital_status')
end

.raceString

Produces the name of a race.

Examples:

Faker::Demographic.race #=> "Native Hawaiian or Other Pacific Islander"

Returns:



15
16
17
# File 'lib/faker/default/demographic.rb', line 15

def race
  fetch('demographic.race')
end

.sexString

Produces a sex for demographic purposes.

Examples:

Faker::Demographic.sex #=> "Female"

Returns:



67
68
69
# File 'lib/faker/default/demographic.rb', line 67

def sex
  fetch('demographic.sex')
end