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
|
# frozen_string_literal: true
module Faker
class Relationship < Base
flexible :relationship
class << self
##
# Produces a random family relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.familial #=> "Grandfather"
#
# @faker.version 1.9.2
def familial(connection: nil)
familial_connections = translate('faker.relationship.familial').keys
if connection.nil?
connection = sample(familial_connections).to_s
else
connection = connection.to_s.downcase
unless familial_connections.include?(connection.to_sym)
raise ArgumentError,
"Familial connections can be left blank or #{familial_connections.join(', ')}"
end
end
fetch("relationship.familial.#{connection}")
end
##
# Produces a random in-law relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.in_law #=> "Brother-in-law"
#
# @faker.version 1.9.2
def in_law
fetch('relationship.in_law')
end
##
# Produces a random spouse relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.spouse #=> "Husband"
#
# @faker.version 1.9.2
def spouse
fetch('relationship.spouse')
end
##
# Produces a random parent relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.parent #=> "Father"
#
# @faker.version 1.9.2
def parent
fetch('relationship.parent')
end
##
# Produces a random sibling relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.sibling #=> "Sister"
#
# @faker.version 1.9.2
def sibling
fetch('relationship.sibling')
end
end
end
end
|