forked from faker-ruby/faker
/
relationship.rb
91 lines (81 loc) · 2.08 KB
/
relationship.rb
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
# 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 next
def familial(legacy_connection = NOT_GIVEN, connection: nil)
warn_for_deprecated_arguments do |keywords|
keywords << :connection if legacy_connection != NOT_GIVEN
end
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 next
def in_law
fetch('relationship.in_law')
end
##
# Produces a random spouse relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.spouse #=> "Husband"
#
# @faker.version next
def spouse
fetch('relationship.spouse')
end
##
# Produces a random parent relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.parent #=> "Father"
#
# @faker.version next
def parent
fetch('relationship.parent')
end
##
# Produces a random sibling relationship.
#
# @return [String]
#
# @example
# Faker::Relationship.sibling #=> "Sister"
#
# @faker.version next
def sibling
fetch('relationship.sibling')
end
end
end
end