Repository navigation
Expand file tree
/
Copy pathaddress.rb
More file actions
54 lines (46 loc) · 1.54 KB
/
Copy pathaddress.rb
File metadata and controls
54 lines (46 loc) · 1.54 KB
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
module Faker
class Address
class << self
def city
[
'%s %s%s' % [city_prefix, Name.first_name, city_suffix],
'%s %s' % [city_prefix, Name.first_name],
'%s%s' % [Name.first_name, city_suffix],
'%s%s' % [Name.last_name, city_suffix],
].rand
end
def street_name
[
Proc.new { [Name.last_name, street_suffix].join(' ') },
Proc.new { [Name.first_name, street_suffix].join(' ') }
].rand.call
end
def street_address(include_secondary = false)
Faker.numerify("#{I18n.translate('address.street_address').rand} #{street_name}#{' ' + secondary_address if include_secondary}")
end
def secondary_address
Faker.numerify(I18n.translate('address.secondary_address').rand)
end
def zip_code
Faker.bothify(I18n.translate('address.postcode').rand).upcase
end
alias_method :zip, :zip_code
alias_method :postcode, :zip_code
# UK Variant
def uk_country
['England', 'Scotland', 'Wales', 'Northern Ireland'].rand
end
%w(street_suffix city_suffix city_prefix state_abbr state country county).each do |meth|
define_method(meth) do
I18n.translate("address.#{meth}").rand
end
end
# Deprecated
alias_method :earth_country, :country
alias_method :us_state, :state
alias_method :us_state_abbr, :state_abbr
alias_method :uk_postcode, :zip_code
alias_method :uk_county, :county
end
end
end