-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaddress.go
171 lines (144 loc) · 3.63 KB
/
address.go
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package faker
import (
"fmt"
"strconv"
"strings"
)
// Addresser interface
type Addresser interface {
ZipCode() string
City() string
CityPrefix() string
CitySuffix() string
StreetName() string
StreetAddress() string
StreetSuffix() string
StreetPrefix() string
SecondaryAddress() string
County() string
Country() string
CountryCode() string
State() string
StateAbbr() string
Latitude() float64
Longitude() float64
Direction(bool) string
OrdinalDirection(bool) string
CardinalDirection(bool) string
}
// Address struct
type Address struct {
*Fake
}
//ZipCode returns a zip code
func (a *Address) ZipCode() string {
// TODO handle format choices
return replaceSymbols(a.pick(addressPrefix + "/postcode"))
}
//City returns a city
func (a *Address) City() string {
return a.format(a.pick(addressPrefix+"/city"), addressPrefix)
}
//CityPrefix returns a city prefix
func (a *Address) CityPrefix() string {
return a.pick(addressPrefix + "/city_prefix")
}
//CitySuffix returns a city suffix
func (a *Address) CitySuffix() string {
return a.pick(addressPrefix + "/city_suffix")
}
//StreetName returns a street name
func (a *Address) StreetName() string {
s := " " + a.StreetSuffix()
switch random(2) {
case 0:
return a.Name().LastName() + s
case 1:
return a.Name().FirstName() + s
}
return a.Name().FirstName() + s
}
//StreetAddress returns a street address
func (a *Address) StreetAddress() string {
return strings.Repeat("#", random(6))
}
//StreetPrefix returns a street prefix
func (a *Address) StreetPrefix() string {
return a.pick(addressPrefix + "/street_prefix")
}
//StreetSuffix returns a street suffix
func (a *Address) StreetSuffix() string {
return a.pick(addressPrefix + "/street_suffix")
}
//SecondaryAddress returns a secondary address
func (a *Address) SecondaryAddress() string {
opts := []string{"Apt. ###", "Suite ###"}
return replaceSymbols(opts[random(len(opts))])
}
//County returns a county
func (a *Address) County() string {
return a.pick(addressPrefix + "/county")
}
//Country returns a country
func (a *Address) Country() string {
return a.pick(addressPrefix + "/country")
}
//CountryCode returns a country code
func (a *Address) CountryCode() string {
return a.pick(addressPrefix + "/country_code")
}
//State returns a state
func (a *Address) State() string {
return a.pick(addressPrefix + "/state")
}
//StateAbbr returns a state abbreviation
func (a *Address) StateAbbr() string {
return a.pick(addressPrefix + "/state_abbr")
}
//Latitude returns a latitude
func (a *Address) Latitude() float64 {
v, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", randomFloatRange(-90, 90)), 64)
return v
}
//Longitude returns a longitude
func (a *Address) Longitude() float64 {
v, _ := strconv.ParseFloat(fmt.Sprintf("%.4f", randomFloatRange(-180, 180)), 64)
return v
}
//Direction returns a navigational direction
func (a *Address) Direction(abbr bool) string {
if abbr {
return a.pick(addressPrefix + "/direction_abbr")
}
return a.pick(addressPrefix + "/direction")
}
//CardinalDirection returns a navigational cardinal direction
func (a *Address) CardinalDirection(abbr bool) string {
var affix string
if abbr {
affix = "/direction_abbr"
} else {
affix = "/direction"
}
v, err := getList(a.Engine, affix, a.DefaultLocale)
if err != nil {
panic(err)
}
v = v[:4]
return v[random(len(v))]
}
//OrdinalDirection returns a navigational ordinal direction
func (a *Address) OrdinalDirection(abbr bool) string {
var affix string
if abbr {
affix = "/direction_abbr"
} else {
affix = "/direction"
}
v, err := getList(a.Engine, affix, a.DefaultLocale)
if err != nil {
panic(err)
}
v = v[4:]
return v[random(len(v))]
}