1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
# frozen_string_literal: true
module Faker
class Demographic < Base
class << self
##
# Produces the name of a race.
#
# @return [String]
#
# @example
# Faker::Demographic.race #=> "Native Hawaiian or Other Pacific Islander"
#
# @faker.version 1.7.3
def race
fetch('demographic.race')
end
##
# Produces a level of educational attainment.
#
# @return [String]
#
# @example
# Faker::Demographic.educational_attainment #=> "GED or alternative credential"
#
# @faker.version 1.7.3
def educational_attainment
fetch('demographic.educational_attainment')
end
##
# Produces a denonym.
#
# @return [String]
#
# @example
# Faker::Demographic.denonym #=> "Panamanian"
#
# @faker.version 1.7.3
def demonym
fetch('demographic.demonym')
end
##
# Produces a marital status.
#
# @return [String]
#
# @example
# Faker::Demographic.marital_status #=> "Widowed"
#
# @faker.version 1.7.3
def marital_status
fetch('demographic.marital_status')
end
##
# Produces a sex for demographic purposes.
#
# @return [String]
#
# @example
# Faker::Demographic.sex #=> "Female"
#
# @faker.version 1.7.3
def sex
fetch('demographic.sex')
end
##
# Produces a height as a string.
#
# @param unit [Symbol] either `:metric` or `imperial`.
# @return [String]
#
# @example
# Faker::Demographic.height #=> "1.61"
# @example
# Faker::Demographic.height(unit: :imperial) #=> "6 ft, 2 in"
#
# @faker.version 1.7.3
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
end
end
end
|