worlddb 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest.txt +9 -0
- data/db/at/cities.rb +53 -0
- data/db/cities.rb +263 -0
- data/db/countries.rb +109 -0
- data/db/de/cities.rb +51 -0
- data/lib/worlddb/cli/runner.rb +5 -14
- data/lib/worlddb/loader.rb +75 -0
- data/lib/worlddb/models/city.rb +48 -0
- data/lib/worlddb/models/country.rb +28 -0
- data/lib/worlddb/models/prop.rb +9 -0
- data/lib/worlddb/models/region.rb +35 -0
- data/lib/worlddb/schema.rb +28 -4
- data/lib/worlddb/version.rb +1 -1
- data/lib/worlddb.rb +8 -0
- metadata +12 -3
data/Manifest.txt
CHANGED
@@ -3,8 +3,17 @@ Manifest.txt
|
|
3
3
|
README.markdown
|
4
4
|
Rakefile
|
5
5
|
bin/worlddb
|
6
|
+
db/at/cities.rb
|
7
|
+
db/cities.rb
|
8
|
+
db/countries.rb
|
9
|
+
db/de/cities.rb
|
6
10
|
lib/worlddb.rb
|
7
11
|
lib/worlddb/cli/opts.rb
|
8
12
|
lib/worlddb/cli/runner.rb
|
13
|
+
lib/worlddb/loader.rb
|
14
|
+
lib/worlddb/models/city.rb
|
15
|
+
lib/worlddb/models/country.rb
|
16
|
+
lib/worlddb/models/prop.rb
|
17
|
+
lib/worlddb/models/region.rb
|
9
18
|
lib/worlddb/schema.rb
|
10
19
|
lib/worlddb/version.rb
|
data/db/at/cities.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
at = Country.find_by_key!( 'at' )
|
4
|
+
|
5
|
+
|
6
|
+
## 9 Bundeslaender
|
7
|
+
|
8
|
+
regions_at = [
|
9
|
+
['wien', 'Wien'], # Wien
|
10
|
+
['noe', 'NÖ'], # Niederösterreich
|
11
|
+
['ooe', 'OÖ'], # Oberösterreich
|
12
|
+
['bgld', 'Bgld.'], # Burgenland
|
13
|
+
['stmk', 'Stmk.'], # Steiermark
|
14
|
+
['sbg', 'Sbg.'], # Salzburg
|
15
|
+
['ktn', 'Ktn.'], # Kärnten
|
16
|
+
['tirol', 'Tirol'], # Tirol
|
17
|
+
['vbg', 'Vbg.'] # Vorarlberg
|
18
|
+
]
|
19
|
+
|
20
|
+
Region.create_from_ary!( regions_at, country: at )
|
21
|
+
|
22
|
+
cities_at = [
|
23
|
+
['wien', 'Wien|Vienna', 'region:wien'],
|
24
|
+
|
25
|
+
['stpoelten', 'St. Pölten', 'region:noe'],
|
26
|
+
['moedling', 'Mödling|Moedling', 'region:noe'],
|
27
|
+
['wrneustadt', 'Wiener Neustadt|Wr. Neustadt', 'region:noe'],
|
28
|
+
['horn', 'Horn', 'region:noe'],
|
29
|
+
|
30
|
+
['linz', 'Linz', 'region:ooe'],
|
31
|
+
['ried', 'Ried', 'region:ooe'],
|
32
|
+
|
33
|
+
['mattersburg', 'Mattersburg', 'region:bgld'],
|
34
|
+
|
35
|
+
['graz', 'Graz', 'region:stmk'],
|
36
|
+
['hartberg', 'Hartberg', 'region:stmk'],
|
37
|
+
['kapfenberg', 'Kapfenberg', 'region:stmk'],
|
38
|
+
|
39
|
+
['salzburg', 'Salzburg', 'region:sbg'],
|
40
|
+
['groedig', 'Grödig', 'region:sbg'],
|
41
|
+
|
42
|
+
['wolfsberg', 'Wolfsberg', 'region:ktn'],
|
43
|
+
|
44
|
+
['innsbruck', 'Innsbruck', 'region:tirol'],
|
45
|
+
|
46
|
+
['altach', 'Altach', 'region:vbg'],
|
47
|
+
['lustenau', 'Lustenau', 'region:vbg']
|
48
|
+
]
|
49
|
+
|
50
|
+
City.create_from_ary!( cities_at, country: at )
|
51
|
+
|
52
|
+
|
53
|
+
Prop.create!( key: 'db.at.cities.version', value: '1' )
|
data/db/cities.rb
ADDED
@@ -0,0 +1,263 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
cities_en = [
|
5
|
+
['manchester', 'Manchester'],
|
6
|
+
['london', 'London'],
|
7
|
+
['liverpool', 'Liverpool'],
|
8
|
+
['birmingham', 'Birmingham'], # e.g.Aston Villa
|
9
|
+
['westbrom', 'West Bromwich'],
|
10
|
+
['newcastle', 'Newcastle upon Tyne'],
|
11
|
+
['stoke', 'Stoke-on-Trent'],
|
12
|
+
['sunderland', 'Sunderland'],
|
13
|
+
['wigan', 'Wigan'],
|
14
|
+
['southampton', 'Southampton'],
|
15
|
+
['reading', 'Reading'],
|
16
|
+
['norwich', 'Norwich'],
|
17
|
+
['swansea', 'Swansea']
|
18
|
+
]
|
19
|
+
|
20
|
+
en = Country.find_by_key!( 'en' )
|
21
|
+
City.create_from_ary!( cities_en, country: en )
|
22
|
+
|
23
|
+
|
24
|
+
cities_es = [
|
25
|
+
['bilbao', 'Bilbao'],
|
26
|
+
['valencia', 'Valencia'],
|
27
|
+
['barcelona', 'Barcelona'],
|
28
|
+
['madrid', 'Madrid'],
|
29
|
+
['malaga', 'Málaga']
|
30
|
+
]
|
31
|
+
|
32
|
+
es = Country.find_by_key!( 'es' )
|
33
|
+
City.create_from_ary!( cities_es, country: es )
|
34
|
+
|
35
|
+
|
36
|
+
cities_fr = [
|
37
|
+
['lille', 'Lille'],
|
38
|
+
['paris', 'Paris'],
|
39
|
+
['marseille', 'Marseille'],
|
40
|
+
['montpellier', 'Montpellier']
|
41
|
+
]
|
42
|
+
|
43
|
+
fr = Country.find_by_key!( 'fr' )
|
44
|
+
City.create_from_ary!( cities_fr, country: fr )
|
45
|
+
|
46
|
+
|
47
|
+
cities_it = [
|
48
|
+
['turin', 'Turin'],
|
49
|
+
['milano', 'Mailand|Milano'],
|
50
|
+
['napoli', 'Neapel|Napoli']
|
51
|
+
]
|
52
|
+
|
53
|
+
it = Country.find_by_key!( 'it' )
|
54
|
+
City.create_from_ary!( cities_it, country: it )
|
55
|
+
|
56
|
+
|
57
|
+
cities_pt = [
|
58
|
+
['porto', 'Porto'],
|
59
|
+
['braga', 'Braga'],
|
60
|
+
['lisboa', 'Lissabon|Lisboa']
|
61
|
+
]
|
62
|
+
|
63
|
+
pt = Country.find_by_key!( 'pt' )
|
64
|
+
City.create_from_ary!( cities_pt, country: pt )
|
65
|
+
|
66
|
+
|
67
|
+
cities_ru = [
|
68
|
+
['moskva', 'Moskau|Moskva'],
|
69
|
+
['stpetersburg','St. Petersburg']
|
70
|
+
]
|
71
|
+
|
72
|
+
ru = Country.find_by_key!( 'ru' )
|
73
|
+
City.create_from_ary!( cities_ru, country: ru )
|
74
|
+
|
75
|
+
|
76
|
+
cities_be = [
|
77
|
+
['brussel', 'Brüssel|Brussel|Bruxelles|Brussels'] # de|nl|fr|en - RCA Anderlecht
|
78
|
+
]
|
79
|
+
|
80
|
+
be = Country.find_by_key!( 'be' )
|
81
|
+
City.create_from_ary!( cities_be, country: be )
|
82
|
+
|
83
|
+
|
84
|
+
cities_ua = [
|
85
|
+
['kiev', 'Kiew|Kiev|Kyiv' ],
|
86
|
+
['donetsk', 'Donezk|Donetsk'],
|
87
|
+
['kharkov', 'Kharkiv|Kharkov']
|
88
|
+
]
|
89
|
+
|
90
|
+
ua = Country.find_by_key!( 'ua' )
|
91
|
+
City.create_from_ary!( cities_ua, country: ua )
|
92
|
+
|
93
|
+
|
94
|
+
cities_nl = [
|
95
|
+
['amsterdam','Amsterdam'],
|
96
|
+
['alkmaar','Alkmaar'] ## region: North Holland
|
97
|
+
]
|
98
|
+
|
99
|
+
nl = Country.find_by_key!( 'nl' )
|
100
|
+
City.create_from_ary!( cities_nl, country: nl )
|
101
|
+
|
102
|
+
|
103
|
+
cities_hr = [
|
104
|
+
['zagreb','Zagreb']
|
105
|
+
]
|
106
|
+
|
107
|
+
hr = Country.find_by_key!( 'hr' )
|
108
|
+
City.create_from_ary!( cities_hr, country: hr )
|
109
|
+
|
110
|
+
|
111
|
+
cities_gr = [
|
112
|
+
['piraeus','Piräus|Piraeus']
|
113
|
+
]
|
114
|
+
|
115
|
+
gr = Country.find_by_key!( 'gr' )
|
116
|
+
City.create_from_ary!( cities_gr, country: gr )
|
117
|
+
|
118
|
+
|
119
|
+
cities_dk = [
|
120
|
+
['farum','Farum'] ## region: North Zealand ??
|
121
|
+
]
|
122
|
+
|
123
|
+
dk = Country.find_by_key!( 'dk' )
|
124
|
+
City.create_from_ary!( cities_dk, country: dk )
|
125
|
+
|
126
|
+
|
127
|
+
cities_by = [
|
128
|
+
['borisov','Borissow|Borisov|Barysaw']
|
129
|
+
]
|
130
|
+
|
131
|
+
by = Country.find_by_key!( 'by' )
|
132
|
+
City.create_from_ary!( cities_by, country: by )
|
133
|
+
|
134
|
+
|
135
|
+
cities_sc = [
|
136
|
+
['glasgow','Glasgow']
|
137
|
+
]
|
138
|
+
|
139
|
+
sc = Country.find_by_key!( 'sc' )
|
140
|
+
City.create_from_ary!( cities_sc, country: sc )
|
141
|
+
|
142
|
+
|
143
|
+
cities_tr = [
|
144
|
+
['istanbul','Istanbul']
|
145
|
+
]
|
146
|
+
|
147
|
+
tr = Country.find_by_key!( 'tr' )
|
148
|
+
City.create_from_ary!( cities_tr, country: tr )
|
149
|
+
|
150
|
+
|
151
|
+
cities_ro = [
|
152
|
+
['cluj','Cluj']
|
153
|
+
]
|
154
|
+
|
155
|
+
ro = Country.find_by_key!( 'ro' )
|
156
|
+
City.create_from_ary!( cities_ro, country: ro )
|
157
|
+
|
158
|
+
|
159
|
+
cities_ch = [
|
160
|
+
['basel','Basel']
|
161
|
+
]
|
162
|
+
|
163
|
+
ch = Country.find_by_key!( 'ch' )
|
164
|
+
City.create_from_ary!( cities_ch, country: ch )
|
165
|
+
|
166
|
+
|
167
|
+
cities_cy = [
|
168
|
+
['nikosia','Nikosia|Nicosia']
|
169
|
+
]
|
170
|
+
|
171
|
+
cy = Country.find_by_key!( 'cy' )
|
172
|
+
City.create_from_ary!( cities_cy, country: cy )
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
cities_mx = [
|
177
|
+
['mexico', 'México' ],
|
178
|
+
['cancun', 'Cancún' ],
|
179
|
+
['guadalajara', 'Guadalajara' ],
|
180
|
+
['tuxtla', 'Tuxtla Gutiérrez' ],
|
181
|
+
['leon', 'León' ],
|
182
|
+
['morelia', 'Morelia' ],
|
183
|
+
['monterrey', 'Monterrey' ],
|
184
|
+
['pachuca', 'Pachuca' ],
|
185
|
+
['puebla', 'Puebla' ],
|
186
|
+
['queretaro', 'Querétaro' ],
|
187
|
+
['sanluispotosi', 'San Luis Potosì' ],
|
188
|
+
['torreon', 'Torreón' ],
|
189
|
+
['tijuana', 'Tijuana' ],
|
190
|
+
['toluca', 'Toluca' ],
|
191
|
+
['sannicolas', 'San Nicolás de los Garza' ]
|
192
|
+
]
|
193
|
+
|
194
|
+
mx = Country.find_by_key!( 'mx' )
|
195
|
+
City.create_from_ary!( cities_mx, country: mx )
|
196
|
+
|
197
|
+
|
198
|
+
regions_ca = [
|
199
|
+
['on', 'Ontario'],
|
200
|
+
['qc', 'Quebec'],
|
201
|
+
['ns', 'Nova Scotia'],
|
202
|
+
['nb', 'New Brunswick'],
|
203
|
+
['mb', 'Manitoba'],
|
204
|
+
['bc', 'British Columbia'],
|
205
|
+
['pe', 'Prince Edward Island'],
|
206
|
+
['sk', 'Saskatchewan'],
|
207
|
+
['ab', 'Alberta'],
|
208
|
+
['nl', 'Newfoundland and Labrador']
|
209
|
+
]
|
210
|
+
|
211
|
+
cities_ca = [
|
212
|
+
['montreal', 'Montreal', 'region:qc'],
|
213
|
+
['ottawa', 'Ottawa', 'region:on'],
|
214
|
+
['toronto', 'Toronto', 'region:on'],
|
215
|
+
['winnipeg', 'Winnipeg', 'region:mb'],
|
216
|
+
['calgary', 'Calgary', 'region:ab'],
|
217
|
+
['edmonton', 'Edmonton', 'region:ab'],
|
218
|
+
['vancouver', 'Vancouver', 'region:bc']
|
219
|
+
]
|
220
|
+
|
221
|
+
ca = Country.find_by_key!( 'ca' )
|
222
|
+
Region.create_from_ary!( regions_ca, country: ca )
|
223
|
+
City.create_from_ary!( cities_ca, country: ca )
|
224
|
+
|
225
|
+
|
226
|
+
regions_us = [
|
227
|
+
['ca', 'California'],
|
228
|
+
['ny', 'New York'],
|
229
|
+
['ma', 'Massachusetts'],
|
230
|
+
['pa', 'Pennsylvania'],
|
231
|
+
['il', 'Illinois'],
|
232
|
+
['oh', 'Ohio'],
|
233
|
+
['mi', 'Michigan'],
|
234
|
+
['tn', 'Tennessee'],
|
235
|
+
['tx', 'Texas'],
|
236
|
+
['az', 'Arizona']
|
237
|
+
]
|
238
|
+
|
239
|
+
cities_us = [
|
240
|
+
['newyork', 'New York', 'region:ny'],
|
241
|
+
['buffalo', 'Buffalo', 'region:ny'],
|
242
|
+
['philadelphia', 'Philadelphia', 'region:pa'],
|
243
|
+
['boston', 'Boston', 'region:ma'],
|
244
|
+
['chicago', 'Chicago', 'region:il'],
|
245
|
+
['columbus', 'Columbus', 'region:oh'],
|
246
|
+
['detroit', 'Detroit', 'region:mi'],
|
247
|
+
['nashville', 'Nashville', 'region:tn'],
|
248
|
+
['dallas', 'Dallas', 'region:tx'],
|
249
|
+
['phoenix', 'Phoenix', 'region:az'],
|
250
|
+
['losangeles', 'Los Angeles', 'region:ca'],
|
251
|
+
['sanjose', 'San Jose', 'region:ca'],
|
252
|
+
['anaheim', 'Anaheim', 'region:ca'],
|
253
|
+
['stlouis', 'St. Louis'],
|
254
|
+
['pittsburgh', 'Pittsburgh'],
|
255
|
+
['washington', 'Washington']
|
256
|
+
]
|
257
|
+
|
258
|
+
us = Country.find_by_key!( 'us' )
|
259
|
+
Region.create_from_ary!( regions_us, country: us )
|
260
|
+
City.create_from_ary!( cities_us, country: us )
|
261
|
+
|
262
|
+
|
263
|
+
Prop.create!( key: 'db.cities.version', value: '1' )
|
data/db/countries.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
## NB: for keys use internet domain/iso two letter code
|
4
|
+
#
|
5
|
+
# more info about iso country codes:
|
6
|
+
# -> http://en.wikipedia.org/wiki/ISO_3166-1
|
7
|
+
# two letter codes -> http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
8
|
+
# three letter codes -> http://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
|
9
|
+
#
|
10
|
+
# for three letter codes use fifa code or iso code
|
11
|
+
# - fifa three letter country codes
|
12
|
+
# -> http://en.wikipedia.org/wiki/List_of_FIFA_country_codes
|
13
|
+
# -> differences (fifa,ioc,iso) -> http://en.wikipedia.org/wiki/Comparison_of_IOC,_FIFA,_and_ISO_3166_country_codes
|
14
|
+
|
15
|
+
|
16
|
+
countries = [
|
17
|
+
|
18
|
+
####################
|
19
|
+
### europe
|
20
|
+
|
21
|
+
[ 'ad', 'Andorra', 'AND' ],
|
22
|
+
[ 'al', 'Albanien', 'ALB' ],
|
23
|
+
[ 'am', 'Armenien', 'ARM' ],
|
24
|
+
[ 'at', 'Österreich', 'AUT' ],
|
25
|
+
[ 'be', 'Belgien', 'BEL' ],
|
26
|
+
[ 'bg', 'Bulgarien', 'BUL' ], # NB: ISO (BGR) <> FIFA (BUL)
|
27
|
+
[ 'by', 'Weißrussland', 'BLR' ],
|
28
|
+
[ 'ch', 'Schweiz', 'SUI' ], # NB: ISO (CHE) <> FIFA (SUI)
|
29
|
+
[ 'cy', 'Zypern', 'CYP' ],
|
30
|
+
[ 'cz', 'Tschechien', 'CZE' ],
|
31
|
+
[ 'de', 'Deutschland', 'GER' ], # NB: ISO (DEU) <> FIFA (GER)
|
32
|
+
[ 'dk', 'Dänemark', 'DEN' ], # NB: ISO (DNK) <> FIFA (DEN)
|
33
|
+
[ 'en', 'England', 'ENG' ], # NB: FIFA (ENG); not a valid iso country n internet domain / it's uk - what to use - anything better?
|
34
|
+
[ 'es', 'Spanien', 'ESP' ],
|
35
|
+
[ 'fi', 'Finnland', 'FIN' ],
|
36
|
+
[ 'fo', 'Färöer', 'FRO' ],
|
37
|
+
[ 'fr', 'Frankreich', 'FRA' ],
|
38
|
+
[ 'ge', 'Georgien', 'GEO' ],
|
39
|
+
[ 'gr', 'Griechenland', 'GRE' ], # NB: ISO (GRC) <> FIFA (GRE)
|
40
|
+
[ 'hr', 'Kroatien', 'CRO' ], # NB: ISO (HRV) <> FIFA (CRO); local name: Hrvatska
|
41
|
+
[ 'hu', 'Ungarn', 'HUN' ],
|
42
|
+
[ 'ie', 'Irland', 'IRL' ],
|
43
|
+
[ 'it', 'Italien', 'ITA' ],
|
44
|
+
[ 'kz', 'Kasachstan', 'KAZ' ],
|
45
|
+
[ 'mt', 'Malta', 'MLT' ],
|
46
|
+
[ 'nl', 'Niederlande', 'NED' ], # NB: ISO (NLD) <> FIFA (NED)
|
47
|
+
[ 'pl', 'Polen', 'POL' ],
|
48
|
+
[ 'pt', 'Portugal', 'POR' ], # NB: ISO (PRT) <> FIFA (POR)
|
49
|
+
[ 'ro', 'Rumänien', 'ROU' ],
|
50
|
+
[ 'rs', 'Serbien', 'SRB' ],
|
51
|
+
[ 'ru', 'Russland', 'RUS' ],
|
52
|
+
[ 'sc', 'Schottland', 'SCO' ], # NB: FIFA (SCO); not a valid iso country/internet domain - it's uk - what to use - anything better?
|
53
|
+
[ 'se', 'Schweden', 'SWE' ],
|
54
|
+
[ 'si', 'Slowenien', 'SVN' ],
|
55
|
+
[ 'sk', 'Slowakei', 'SVK' ],
|
56
|
+
[ 'tr', 'Türkei', 'TUR' ],
|
57
|
+
[ 'ua', 'Ukraine', 'UKR' ],
|
58
|
+
|
59
|
+
##############
|
60
|
+
## south america
|
61
|
+
|
62
|
+
[ 'ar', 'Argentinien', 'ARG' ],
|
63
|
+
[ 'br', 'Brasilien', 'BRA' ],
|
64
|
+
[ 'cl', 'Chile', 'CHI' ],
|
65
|
+
[ 'py', 'Paraguay', 'PAR' ],
|
66
|
+
[ 'uy', 'Uruguay', 'URU' ],
|
67
|
+
[ 'ec', 'Ecuador', 'ECU' ],
|
68
|
+
[ 'co', 'Colombia', 'COL' ],
|
69
|
+
|
70
|
+
#####################
|
71
|
+
#### north/central america & caribbean islands
|
72
|
+
|
73
|
+
[ 'ca', 'Kanada', 'CAN' ],
|
74
|
+
[ 'mx', 'Mexiko', 'MEX' ],
|
75
|
+
[ 'us', 'United States', 'USA' ],
|
76
|
+
[ 'hn', 'Honduras', 'HON' ],
|
77
|
+
[ 'cr', 'Costa Rica', 'CRC' ],
|
78
|
+
[ 'sv', 'El Salvador', 'SLV' ],
|
79
|
+
[ 'gy', 'Guyana', 'GUY' ],
|
80
|
+
|
81
|
+
########################
|
82
|
+
## africa
|
83
|
+
|
84
|
+
[ 'dz', 'Algerien', 'ALG' ],
|
85
|
+
[ 'ci', 'Elfenbeinküste', 'CIV' ],
|
86
|
+
[ 'gh', 'Ghana', 'GHA' ],
|
87
|
+
[ 'cm', 'Kamerun', 'CMR' ],
|
88
|
+
[ 'ng', 'Nigeria', 'NGA' ],
|
89
|
+
[ 'za', 'Südafrika', 'RSA' ],
|
90
|
+
|
91
|
+
#############################
|
92
|
+
## asia w/ australia
|
93
|
+
|
94
|
+
[ 'au', 'Australien', 'AUS' ],
|
95
|
+
[ 'jp', 'Japan', 'JPN' ],
|
96
|
+
[ 'kp', 'Nordkorea', 'PRK' ],
|
97
|
+
[ 'kr', 'Südkorea', 'KOR' ],
|
98
|
+
|
99
|
+
###############################
|
100
|
+
## oceania
|
101
|
+
|
102
|
+
[ 'nz', 'Neuseeland', 'NZL' ]
|
103
|
+
]
|
104
|
+
|
105
|
+
|
106
|
+
Country.create_from_ary!( countries )
|
107
|
+
|
108
|
+
|
109
|
+
Prop.create!( key: 'db.countries.version', value: '1' )
|
data/db/de/cities.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
de = Country.find_by_key!( 'de' )
|
4
|
+
|
5
|
+
regions_de = [
|
6
|
+
['bw', 'Baden-Württemberg'],
|
7
|
+
['by', 'Bayern'],
|
8
|
+
['be', 'Berlin'],
|
9
|
+
['bb', 'Brandenburg'],
|
10
|
+
['hb', 'Bremen'],
|
11
|
+
['hh', 'Hamburg'],
|
12
|
+
['he', 'Hessen'],
|
13
|
+
['mv', 'Mecklenburg-Vorpommern'],
|
14
|
+
['ni', 'Niedersachsen'],
|
15
|
+
['nw', 'Nordrhein-Westfalen'],
|
16
|
+
['rp', 'Rheinland-Pfalz'],
|
17
|
+
['sl', 'Saarland'],
|
18
|
+
['sn', 'Sachsen'],
|
19
|
+
['st', 'Sachsen-Anhalt'],
|
20
|
+
['sh', 'Schleswig-Holstein'],
|
21
|
+
['th', 'Thüringen']
|
22
|
+
]
|
23
|
+
|
24
|
+
Region.create_from_ary!( regions_de, country: de )
|
25
|
+
|
26
|
+
|
27
|
+
cities_de = [
|
28
|
+
['muenchen', 'München', 'region:by'],
|
29
|
+
['nuernberg', 'Nürnberg', 'region:by'],
|
30
|
+
['augsburg', 'Augsburg', 'region:by'],
|
31
|
+
['fuerth', 'Fürth', 'region:by'],
|
32
|
+
['stuttgart', 'Stuttgart', 'region:bw'],
|
33
|
+
['hoffenheim', 'Hoffenheim', 'region:bw'],
|
34
|
+
['freiburg', 'Freiburg', 'region:bw'],
|
35
|
+
['hannover', 'Hannover', 'region:ni'],
|
36
|
+
['wolfsburg', 'Wolfsburg', 'region:ni'],
|
37
|
+
['gelsenkirchen', 'Gelsenkirchen', 'region:nw'],
|
38
|
+
['dortmund', 'Dortmund', 'region:nw'],
|
39
|
+
['leverkusen', 'Leverkusen', 'region:nw'],
|
40
|
+
['duesseldorf', 'Düsseldorf', 'region:nw'],
|
41
|
+
['mgladbach', "Mönchengladbach|M'gladbach", 'region:nw' ],
|
42
|
+
['frankfurt', 'Frankfurt', 'region:he'],
|
43
|
+
['mainz', 'Mainz', 'region:rp'],
|
44
|
+
['hamburg', 'Hamburg', 'region:hh'],
|
45
|
+
['bremen', 'Bremen', 'region:hb']
|
46
|
+
]
|
47
|
+
|
48
|
+
City.create_from_ary!( cities_de, country: de )
|
49
|
+
|
50
|
+
|
51
|
+
Prop.create!( key: 'db.de.cities.version', value: '1' )
|
data/lib/worlddb/cli/runner.rb
CHANGED
@@ -3,8 +3,7 @@ module WorldDB
|
|
3
3
|
|
4
4
|
class Runner
|
5
5
|
|
6
|
-
|
7
|
-
### include WorldDB::Models
|
6
|
+
include WorldDB::Models
|
8
7
|
|
9
8
|
def initialize
|
10
9
|
@logger = Logger.new(STDOUT)
|
@@ -51,7 +50,7 @@ worlddb - world.db command line tool, version #{VERSION}
|
|
51
50
|
#{cmd.help}
|
52
51
|
|
53
52
|
Examples:
|
54
|
-
worlddb at
|
53
|
+
worlddb at/cities # import austrian regions n cities
|
55
54
|
worlddb -c # create database schema
|
56
55
|
|
57
56
|
More Examples:
|
@@ -89,13 +88,8 @@ EOS
|
|
89
88
|
# tbd
|
90
89
|
end
|
91
90
|
|
91
|
+
Loader.new( logger ).run( opts, args ) # load ruby fixtures
|
92
92
|
|
93
|
-
args.each do |arg|
|
94
|
-
name = arg # File.basename( arg, '.*' )
|
95
|
-
|
96
|
-
# tbd
|
97
|
-
end
|
98
|
-
|
99
93
|
dump_stats
|
100
94
|
dump_props
|
101
95
|
|
@@ -106,22 +100,19 @@ EOS
|
|
106
100
|
|
107
101
|
def dump_stats
|
108
102
|
# todo: use %5d or similar to format string
|
109
|
-
=begin
|
110
103
|
puts "Stats:"
|
111
104
|
puts " #{Country.count} countries"
|
112
|
-
|
105
|
+
puts " #{Region.count} regions"
|
106
|
+
puts " #{City.count} cities"
|
113
107
|
end
|
114
108
|
|
115
109
|
|
116
110
|
def dump_props
|
117
|
-
|
118
|
-
=begin
|
119
111
|
# todo: use %5 or similar to format string
|
120
112
|
puts "Props:"
|
121
113
|
Prop.order( 'created_at asc' ).all.each do |prop|
|
122
114
|
puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
|
123
115
|
end
|
124
|
-
=end
|
125
116
|
end
|
126
117
|
|
127
118
|
end # class Runner
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module WorldDB
|
2
|
+
|
3
|
+
class Loader
|
4
|
+
|
5
|
+
## make models available in worlddb module by default with namespace
|
6
|
+
# e.g. lets you use City instead of Models::City
|
7
|
+
include WorldDB::Models
|
8
|
+
|
9
|
+
|
10
|
+
def initialize( logger=nil )
|
11
|
+
if logger.nil?
|
12
|
+
@logger = Logger.new(STDOUT)
|
13
|
+
@logger.level = Logger::INFO
|
14
|
+
else
|
15
|
+
@logger = logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :logger
|
20
|
+
|
21
|
+
|
22
|
+
def run( opts, args )
|
23
|
+
|
24
|
+
args.each do |arg|
|
25
|
+
name = arg # File.basename( arg, '.*' )
|
26
|
+
|
27
|
+
if opts.load?
|
28
|
+
load_fixtures_builtin( name )
|
29
|
+
else
|
30
|
+
load_fixtures_with_include_path( name, opts.data_path )
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end # method run
|
35
|
+
|
36
|
+
|
37
|
+
def load_fixtures_with_include_path( name, include_path ) # load from file system
|
38
|
+
path = "#{include_path}/#{name}.rb"
|
39
|
+
|
40
|
+
puts "*** loading data '#{name}' (#{path})..."
|
41
|
+
|
42
|
+
code = File.read( path )
|
43
|
+
|
44
|
+
load_fixtures_worker( code )
|
45
|
+
end
|
46
|
+
|
47
|
+
def load_fixtures_builtin( name ) # load from gem (built-in)
|
48
|
+
path = "#{WorldDB.root}/db/#{name}.rb"
|
49
|
+
|
50
|
+
puts "*** loading data '#{name}' (#{path})..."
|
51
|
+
|
52
|
+
code = File.read( path )
|
53
|
+
|
54
|
+
load_fixtures_worker( code )
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
private
|
59
|
+
def load_fixtures_worker( code )
|
60
|
+
|
61
|
+
self.class_eval( code )
|
62
|
+
|
63
|
+
# NB: same as
|
64
|
+
#
|
65
|
+
# module WorldDB
|
66
|
+
# include WorldDB::Models
|
67
|
+
# <code here>
|
68
|
+
# end
|
69
|
+
|
70
|
+
# Prop.create!( :key => "db.#{name}.version", :value => SportDB::VERSION )
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end # class Loader
|
75
|
+
end # module WorldDB
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WorldDB::Models
|
4
|
+
|
5
|
+
class City < ActiveRecord::Base
|
6
|
+
self.table_name = 'cities'
|
7
|
+
|
8
|
+
belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
|
9
|
+
belongs_to :region, :class_name => 'Region', :foreign_key => 'region_id'
|
10
|
+
|
11
|
+
def self.create_from_ary!( cities, more_values={} )
|
12
|
+
cities.each do |values|
|
13
|
+
|
14
|
+
## key & title & country required
|
15
|
+
attr = {
|
16
|
+
key: values[0]
|
17
|
+
}
|
18
|
+
|
19
|
+
## title (split of optional synonyms)
|
20
|
+
# e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern
|
21
|
+
titles = values[1].split('|')
|
22
|
+
|
23
|
+
attr[ :title ] = titles[0]
|
24
|
+
## add optional synonyms
|
25
|
+
attr[ :synonyms ] = titles[1..-1].join('|') if titles.size > 1
|
26
|
+
|
27
|
+
attr = attr.merge( more_values )
|
28
|
+
|
29
|
+
## check for optional values
|
30
|
+
values[2..-1].each do |value|
|
31
|
+
if value.is_a? Country
|
32
|
+
attr[ :country_id ] = value.id
|
33
|
+
elsif value =~ /^region:/ ## region:
|
34
|
+
value_region_key = value[7..-1] ## cut off region: prefix
|
35
|
+
value_region = Region.find_by_key!( value_region_key )
|
36
|
+
attr[ :region_id ] = value_region.id
|
37
|
+
else
|
38
|
+
# issue warning: unknown type for value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
City.create!( attr )
|
43
|
+
end # each city
|
44
|
+
end
|
45
|
+
|
46
|
+
end # class Cities
|
47
|
+
|
48
|
+
end # module WorldDB::Models
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WorldDB::Models
|
4
|
+
|
5
|
+
class Country < ActiveRecord::Base
|
6
|
+
self.table_name = 'countries'
|
7
|
+
|
8
|
+
has_many :regions, :class_name => 'Region', :foreign_key => 'country_id'
|
9
|
+
has_many :cities, :class_name => 'City', :foreign_key => 'country_id'
|
10
|
+
|
11
|
+
def self.create_from_ary!( countries )
|
12
|
+
countries.each do |values|
|
13
|
+
|
14
|
+
## key & title required
|
15
|
+
attr = {
|
16
|
+
:key => values[0],
|
17
|
+
:title => values[1],
|
18
|
+
:tag => values[2]
|
19
|
+
}
|
20
|
+
|
21
|
+
Country.create!( attr )
|
22
|
+
end # each country
|
23
|
+
end
|
24
|
+
|
25
|
+
end # class Country
|
26
|
+
|
27
|
+
|
28
|
+
end # module WorldDB::Models
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module WorldDB::Models
|
2
|
+
|
3
|
+
class Region < ActiveRecord::Base
|
4
|
+
|
5
|
+
belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
|
6
|
+
|
7
|
+
has_many :cities, :class_name => 'City', :foreign_key => 'region_id'
|
8
|
+
|
9
|
+
def self.create_from_ary!( regions, more_values={} )
|
10
|
+
regions.each do |values|
|
11
|
+
|
12
|
+
## key & title & country required
|
13
|
+
attr = {
|
14
|
+
key: values[0],
|
15
|
+
title: values[1]
|
16
|
+
}
|
17
|
+
|
18
|
+
attr = attr.merge( more_values )
|
19
|
+
|
20
|
+
## check for optional values
|
21
|
+
values[2..-1].each do |value|
|
22
|
+
if value.is_a? Country
|
23
|
+
attr[ :country_id ] = value.id
|
24
|
+
else
|
25
|
+
# issue warning: unknown type for value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
Region.create!( attr )
|
30
|
+
end # each region
|
31
|
+
end
|
32
|
+
|
33
|
+
end # class Region
|
34
|
+
|
35
|
+
end # module WorldDB::Models
|
data/lib/worlddb/schema.rb
CHANGED
@@ -3,7 +3,7 @@ module WorldDB
|
|
3
3
|
|
4
4
|
class CreateDB
|
5
5
|
|
6
|
-
|
6
|
+
include WorldDB::Models
|
7
7
|
|
8
8
|
|
9
9
|
def self.up
|
@@ -12,14 +12,38 @@ def self.up
|
|
12
12
|
|
13
13
|
create_table :countries do |t|
|
14
14
|
t.string :title, :null => false
|
15
|
-
t.string :tag, :null => false # short three letter tag
|
16
15
|
t.string :key, :null => false
|
16
|
+
t.string :tag, :null => false # short three letter tag (FIFA country code)
|
17
|
+
t.string :synonyms # comma separated list of synonyms
|
17
18
|
t.timestamps
|
18
19
|
end
|
19
|
-
|
20
|
+
|
21
|
+
create_table :regions do |t|
|
22
|
+
t.string :title, :null => false
|
23
|
+
t.string :key, :null => false
|
24
|
+
t.string :synonyms # comma separated list of synonyms
|
25
|
+
t.references :country, :null => false
|
26
|
+
t.timestamps
|
27
|
+
end
|
28
|
+
|
29
|
+
create_table :cities do |t|
|
30
|
+
t.string :title, :null => false
|
31
|
+
t.string :key, :null => false
|
32
|
+
t.string :synonyms # comma separated list of synonyms
|
33
|
+
t.references :country, :null => false
|
34
|
+
t.references :region # optional for now
|
35
|
+
t.timestamps
|
36
|
+
end
|
37
|
+
|
38
|
+
create_table :props do |t|
|
39
|
+
t.string :key, :null => false
|
40
|
+
t.string :value, :null => false
|
41
|
+
t.timestamps
|
42
|
+
end
|
43
|
+
|
20
44
|
end # block Schema.define
|
21
45
|
|
22
|
-
|
46
|
+
Prop.create!( key: 'db.schema.world.version', value: WorldDB::VERSION )
|
23
47
|
|
24
48
|
end # method up
|
25
49
|
|
data/lib/worlddb/version.rb
CHANGED
data/lib/worlddb.rb
CHANGED
@@ -19,7 +19,15 @@ require 'active_record' ## todo: add sqlite3? etc.
|
|
19
19
|
|
20
20
|
# our own code
|
21
21
|
|
22
|
+
module WorldDB # forward reference; more to come later
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'worlddb/models/prop'
|
26
|
+
require 'worlddb/models/country'
|
27
|
+
require 'worlddb/models/region'
|
28
|
+
require 'worlddb/models/city'
|
22
29
|
require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
|
30
|
+
require 'worlddb/loader'
|
23
31
|
require 'worlddb/version'
|
24
32
|
require 'worlddb/cli/opts'
|
25
33
|
require 'worlddb/cli/runner'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -76,9 +76,18 @@ files:
|
|
76
76
|
- README.markdown
|
77
77
|
- Rakefile
|
78
78
|
- bin/worlddb
|
79
|
+
- db/at/cities.rb
|
80
|
+
- db/cities.rb
|
81
|
+
- db/countries.rb
|
82
|
+
- db/de/cities.rb
|
79
83
|
- lib/worlddb.rb
|
80
84
|
- lib/worlddb/cli/opts.rb
|
81
85
|
- lib/worlddb/cli/runner.rb
|
86
|
+
- lib/worlddb/loader.rb
|
87
|
+
- lib/worlddb/models/city.rb
|
88
|
+
- lib/worlddb/models/country.rb
|
89
|
+
- lib/worlddb/models/prop.rb
|
90
|
+
- lib/worlddb/models/region.rb
|
82
91
|
- lib/worlddb/schema.rb
|
83
92
|
- lib/worlddb/version.rb
|
84
93
|
homepage: http://geraldb.github.com/world.db
|