Class: Faussaire::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/faussaire/address.rb

Constant Summary collapse

DATA_PATH =
File.expand_path('../../locale/fr.yml', __dir__)

Class Method Summary collapse

Class Method Details

.cityString

Produces a random city name.

Examples:

Faussaire::Address.city #=> "Paris"

Returns:

  • (String)


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

def city
  fetch('fr.faussaire.address.city')
end

.dpt_nameString

Produces a random department name.

Examples:

Faussaire::Address.dpt_name #=> "Yvelines"

Returns:

  • (String)


92
93
94
# File 'lib/faussaire/address.rb', line 92

def dpt_name
  fetch('fr.faussaire.address.dpt_name')
end

.dpt_numberString

Produces a random department number for metropolitan France.

Examples:

Faussaire::Address.dpt_number #=> "78"

Returns:

  • (String)


104
105
106
# File 'lib/faussaire/address.rb', line 104

def dpt_number
  fetch('fr.faussaire.address.dpt_number_metropolis')
end

.dpt_number_otherString

Produces a random department number for overseas departments.

Examples:

Faussaire::Address.dpt_number_other #=> "971"

Returns:

  • (String)


116
117
118
# File 'lib/faussaire/address.rb', line 116

def dpt_number_other
  fetch('fr.faussaire.address.dpt_number_overseas')
end

.full_addressString

Generates a complete address using various components such as street number, street type, street name, postal code, city, and region.

Examples:

Faussaire::Address.full_address #=> "3 Rue du Bac, 75007 Paris, Tarn (44), Région Nouvelle-Aquitaine"

Returns:

  • (String)

    The full address in a standard format.



154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/faussaire/address.rb', line 154

def full_address
  number = random_street_number
  type = street_type
  name = street_name
  postal = postal_code
  city_name = city
  department_name = dpt_name
  department_number = department_number_select
  reg = region


  "#{number} #{type} #{name}, #{postal} #{city_name}, #{department_name} (#{department_number}), Région #{reg}"
end

.initialize_dataObject



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

def initialize_data
  @data = YAML.load_file(DATA_PATH)
end

.postal_codeString

Produces a random postal code, formatted to five digits.

Examples:

Faussaire::Address.postal_code #=> "75001"

Returns:

  • (String)


128
129
130
131
# File 'lib/faussaire/address.rb', line 128

def postal_code
  code = fetch('fr.faussaire.address.postal_code')
  code.to_s.rjust(5, '0')
end

.regionString

Produces a random region name.

Examples:

Faussaire::Address.region #=> "Île-de-France"

Returns:

  • (String)


141
142
143
# File 'lib/faussaire/address.rb', line 141

def region
  fetch('fr.faussaire.address.region')
end

.street_nameString

Produces a random street name.

Examples:

Faussaire::Address.street_name #=> "Champs-Élysées"

Returns:

  • (String)


80
81
82
# File 'lib/faussaire/address.rb', line 80

def street_name
  fetch('fr.faussaire.address.street_name')
end

.street_number_99String

Produces a random street number up to 99.

Examples:

Faussaire::Address.street_number_99 #=> "42"

Returns:

  • (String)


32
33
34
# File 'lib/faussaire/address.rb', line 32

def street_number_99
  fetch('fr.faussaire.address.street_number_99')
end

.street_number_999String

Produces a random street number up to 999.

Examples:

Faussaire::Address.street_number_999 #=> "123"

Returns:

  • (String)


44
45
46
# File 'lib/faussaire/address.rb', line 44

def street_number_999
  fetch('fr.faussaire.address.street_number_999')
end

.street_number_9999String

Produces a random street number up to 9999.

Examples:

Faussaire::Address.street_number_9999 #=> "1234"

Returns:

  • (String)


56
57
58
# File 'lib/faussaire/address.rb', line 56

def street_number_9999
  fetch('fr.faussaire.address.street_number_9999')
end

.street_typeString

Produces a random street type.

Examples:

Faussaire::Address.street_type #=> "Avenue"

Returns:

  • (String)


68
69
70
# File 'lib/faussaire/address.rb', line 68

def street_type
  fetch('fr.faussaire.address.street_type')
end