Class: Faker::Address

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/address.rb

Constant Summary

Constants inherited from Base

Base::Letters, Base::Numbers, Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.building_numberObject


24
25
26
# File 'lib/faker/default/address.rb', line 24

def building_number
  bothify(fetch('address.building_number'))
end

.city(options = {}) ⇒ Object


8
9
10
# File 'lib/faker/default/address.rb', line 8

def city(options = {})
  parse(options[:with_state] ? 'address.city_with_state' : 'address.city')
end

.city_prefixObject


58
59
60
# File 'lib/faker/default/address.rb', line 58

def city_prefix
  fetch('address.city_prefix')
end

.city_suffixObject


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

def city_suffix
  fetch('address.city_suffix')
end

.communityObject


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

def community
  parse('address.community')
end

.countryObject


70
71
72
# File 'lib/faker/default/address.rb', line 70

def country
  fetch('address.country')
end

.country_by_code(code: 'US') ⇒ Object


74
75
76
# File 'lib/faker/default/address.rb', line 74

def country_by_code(code: 'US')
  fetch('address.country_by_code.' + code)
end

.country_codeObject


82
83
84
# File 'lib/faker/default/address.rb', line 82

def country_code
  fetch('address.country_code')
end

.country_code_longObject


86
87
88
# File 'lib/faker/default/address.rb', line 86

def country_code_long
  fetch('address.country_code_long')
end

.country_name_to_code(name: 'united_states') ⇒ Object


78
79
80
# File 'lib/faker/default/address.rb', line 78

def country_name_to_code(name: 'united_states')
  fetch('address.country_by_name.' + name)
end

.full_addressObject


98
99
100
# File 'lib/faker/default/address.rb', line 98

def full_address
  parse('address.full_address')
end

.latitudeObject


90
91
92
# File 'lib/faker/default/address.rb', line 90

def latitude
  ((rand * 180) - 90).to_f
end

.longitudeObject


94
95
96
# File 'lib/faker/default/address.rb', line 94

def longitude
  ((rand * 360) - 180).to_f
end

.secondary_addressObject


20
21
22
# File 'lib/faker/default/address.rb', line 20

def secondary_address
  bothify(fetch('address.secondary_address'))
end

.stateObject


66
67
68
# File 'lib/faker/default/address.rb', line 66

def state
  fetch('address.state')
end

.state_abbrObject


62
63
64
# File 'lib/faker/default/address.rb', line 62

def state_abbr
  fetch('address.state_abbr')
end

.street_address(include_secondary = false) ⇒ Object


16
17
18
# File 'lib/faker/default/address.rb', line 16

def street_address(include_secondary = false)
  numerify(parse('address.street_address') + (include_secondary ? ' ' + secondary_address : ''))
end

.street_nameObject


12
13
14
# File 'lib/faker/default/address.rb', line 12

def street_name
  parse('address.street_name')
end

.street_suffixObject


50
51
52
# File 'lib/faker/default/address.rb', line 50

def street_suffix
  fetch('address.street_suffix')
end

.time_zoneObject


43
44
45
# File 'lib/faker/default/address.rb', line 43

def time_zone
  fetch('address.time_zone')
end

.zip_code(state_abbreviation = '') ⇒ Object Also known as: zip, postcode


32
33
34
35
36
37
38
39
40
41
# File 'lib/faker/default/address.rb', line 32

def zip_code(state_abbreviation = '')
  if state_abbreviation.empty?
    letterified_string = letterify(fetch('address.postcode'))
    return numerify(letterified_string, leading_zero: true)
  end

  # provide a zip code that is valid for the state provided
  # see http://www.fincen.gov/forms/files/us_state_territory_zip_codes.pdf
  bothify(fetch('address.postcode_by_state.' + state_abbreviation))
end