worlddb-models 2.2.2 → 2.3.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.
- checksums.yaml +4 -4
- data/Manifest.txt +31 -13
- data/README.md +7 -7
- data/Rakefile +1 -1
- data/lib/worlddb/deleter.rb +6 -1
- data/lib/worlddb/helpers/value_helper.rb +117 -0
- data/lib/worlddb/matcher.rb +99 -135
- data/lib/worlddb/matcher_adm.rb +82 -0
- data/lib/worlddb/models/city.rb +30 -208
- data/lib/worlddb/models/city_base.rb +220 -0
- data/lib/worlddb/models/continent.rb +9 -0
- data/lib/worlddb/models/country.rb +21 -4
- data/lib/worlddb/models/forward.rb +25 -9
- data/lib/worlddb/models/lang.rb +6 -0
- data/lib/worlddb/models/place.rb +1 -1
- data/lib/worlddb/models/state.rb +83 -0
- data/lib/worlddb/models/{region.rb → state_base.rb} +52 -36
- data/lib/worlddb/models/tagdb/tag.rb +1 -1
- data/lib/worlddb/models.rb +11 -8
- data/lib/worlddb/patterns.rb +4 -4
- data/lib/worlddb/reader.rb +68 -39
- data/lib/worlddb/reader_file.rb +36 -3
- data/lib/worlddb/reader_zip.rb +33 -3
- data/lib/worlddb/readers/base.rb +149 -0
- data/lib/worlddb/readers/city.rb +2 -65
- data/lib/worlddb/readers/country.rb +2 -63
- data/lib/worlddb/readers/lang.rb +3 -68
- data/lib/worlddb/readers/state.rb +61 -0
- data/lib/worlddb/readers/state_tree.rb +118 -0
- data/lib/worlddb/readers/usage.rb +2 -65
- data/lib/worlddb/schema.rb +142 -43
- data/lib/worlddb/stats.rb +7 -4
- data/lib/worlddb/tree_reader.rb +97 -0
- data/lib/worlddb/version.rb +2 -2
- data/test/adm/test_fixture_matcher_adm2.rb +73 -0
- data/test/{test_fixture_matcher_adm3.rb → adm/test_fixture_matcher_adm3.rb} +6 -6
- data/test/adm/test_fixture_matcher_tree.rb +52 -0
- data/test/{test_read_adm.rb → adm/test_read_adm.rb} +13 -20
- data/test/adm/test_read_tree.rb +63 -0
- data/test/data/at-austria/2--n-niederoesterreich/counties.txt +6 -4
- data/test/data/at-austria/orte.txt +23 -0
- data/test/data/at-austria/setups/tree.txt +9 -0
- data/test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt +14 -13
- data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt +104 -0
- data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte_ii.txt +17 -0
- data/test/data/de-deutschland/3--by-bayern/{districts.txt → parts.txt} +1 -1
- data/test/data/de-deutschland/orte.txt +12 -0
- data/test/data/de-deutschland/setups/adm.txt +1 -1
- data/test/data/de-deutschland/setups/tree.txt +9 -0
- data/test/helper.rb +8 -1
- data/test/test_fixture_matchers.rb +9 -10
- data/test/test_fixture_matchers_ii.rb +20 -19
- data/test/test_model_city.rb +26 -9
- data/test/{test_model_comp.rb → test_model_compat.rb} +15 -13
- data/test/test_model_country.rb +1 -1
- data/test/test_model_state.rb +54 -0
- data/test/test_model_states_at.rb +111 -0
- data/test/test_model_states_de.rb +147 -0
- data/test/test_models.rb +10 -3
- data/test/test_parse_city.rb +70 -0
- data/test/test_parse_country.rb +56 -0
- data/test/test_parse_state.rb +46 -0
- data/test/test_state_tree_reader_at.rb +54 -0
- data/test/test_state_tree_reader_de.rb +71 -0
- data/test/test_tree_reader.rb +39 -0
- metadata +50 -22
- data/lib/worlddb/models/city_compat.rb +0 -27
- data/lib/worlddb/models/continent_compat.rb +0 -24
- data/lib/worlddb/models/country_compat.rb +0 -35
- data/lib/worlddb/models/lang_compat.rb +0 -23
- data/lib/worlddb/models/region_compat.rb +0 -26
- data/lib/worlddb/readers/region.rb +0 -79
- data/test/test_fixture_matcher_adm2.rb +0 -62
- data/test/test_model_region.rb +0 -50
data/lib/worlddb/schema.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module WorldDb
|
3
3
|
|
4
|
-
class CreateDb
|
4
|
+
class CreateDb
|
5
5
|
|
6
6
|
def up
|
7
7
|
|
@@ -17,13 +17,14 @@ create_table :places do |t|
|
|
17
17
|
# SUPR - supra (e.g. European Union)
|
18
18
|
# CNTY - country
|
19
19
|
# TERR - terr
|
20
|
-
#
|
21
|
-
# ADM1 - e.g.
|
22
|
-
# ADM2 - e.g. county/
|
23
|
-
# ADM3 - e.g.
|
20
|
+
# state:
|
21
|
+
# ADM1 - e.g. state/province
|
22
|
+
# ADM2 - e.g. county/bezirk/kreis
|
23
|
+
# ADM3 - e.g. municipality/gemeinde
|
24
|
+
# ADM4
|
24
25
|
# city:
|
25
26
|
# MTRO - metro
|
26
|
-
# CITY - city/town/
|
27
|
+
# CITY - city/town/village/hamlet //(de)ort/stadt/markt
|
27
28
|
# DIST - district/
|
28
29
|
#
|
29
30
|
# add new table for zones (e.g. informal regions e.g. tourism, wine regions, etc.) ??
|
@@ -33,7 +34,8 @@ create_table :places do |t|
|
|
33
34
|
t.float :lat # optional for now (latitude)
|
34
35
|
t.float :lng # optional for now (longitude)
|
35
36
|
|
36
|
-
## todo: add parent for hierachy ?? or keep it in country/
|
37
|
+
## todo: add parent for hierachy ?? or keep it in country/state/city etc. table
|
38
|
+
## or use extra hierachy join table ??
|
37
39
|
|
38
40
|
## timestamp at last
|
39
41
|
t.timestamps
|
@@ -43,7 +45,7 @@ end
|
|
43
45
|
#############
|
44
46
|
# todo: use many-to-many assoc w/ join table for name and place ???
|
45
47
|
# why? why not?
|
46
|
-
# - wien -> city n
|
48
|
+
# - wien -> city n state n metro ? collect more samples of names used more than once
|
47
49
|
|
48
50
|
### alternative names for places
|
49
51
|
create_table :names do |t|
|
@@ -128,23 +130,10 @@ add_index :countries, :key, unique: true
|
|
128
130
|
add_index :countries, :code, unique: true
|
129
131
|
|
130
132
|
|
131
|
-
## kind of regions/states but not hierachical (used for tourist/colloquial zones etc.)
|
132
|
-
# uses many-to-many join tables w/ cities n regions
|
133
|
-
#
|
134
|
-
# examples:
|
135
|
-
# Salzkammergut (part of Salzburg and Oberoesterreich)
|
136
|
-
# others
|
137
|
-
# Oberfranken -> Fichtelgebierge/Fraenkische Schweiz/etc.
|
138
|
-
create_table :zones do |t|
|
139
|
-
# to be done
|
140
|
-
end
|
141
|
-
|
142
133
|
|
143
134
|
######
|
144
|
-
# NB: rename to adms/admins ?? or use states ???
|
145
|
-
#
|
146
135
|
# used for state/provice/land/regioni/etc.
|
147
|
-
create_table :
|
136
|
+
create_table :states do |t|
|
148
137
|
t.string :name, null: false
|
149
138
|
t.string :key, null: false
|
150
139
|
t.references :place, null: false
|
@@ -152,19 +141,18 @@ create_table :regions do |t|
|
|
152
141
|
t.string :abbr # optional conventional abbrevation (e.g. Stmk., Gto., etc.)
|
153
142
|
t.string :iso # iso code
|
154
143
|
t.string :nuts # nuts code (europe/eu only)
|
155
|
-
t.string
|
144
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
156
145
|
|
157
146
|
t.references :country, null: false
|
158
|
-
t.references :
|
147
|
+
t.references :state ## parent state (optional for now - may be null for top level e.g. state/province)
|
159
148
|
t.integer :level, null: false, default: 1 # default assumes 1 e.g. state/province/etc.
|
160
149
|
### change to l (instead of level)!!!! - shorter, why, why not???
|
161
150
|
|
162
151
|
## flags (use single int named flags - why? why not?
|
163
152
|
### fix: use a generic kind string type flag!!!!!!
|
164
|
-
t.boolean :s, null: false, default: false # state flag (use adm1? or a1)
|
165
|
-
t.boolean :
|
166
|
-
t.boolean :c, null: false, default: false # county (or bezirk etc.) (use adm3? or a3?)
|
167
|
-
|
153
|
+
## t.boolean :s, null: false, default: false # state flag (use adm1? or a1)
|
154
|
+
## t.boolean :p, null: false, default: false # governmental district falg (use adm2? or a2) - check is Oberfranken/Oberbayern admin2 in Bayern (DE) ?? - note: might be optional (than adm3 becomes adm2)
|
155
|
+
## t.boolean :c, null: false, default: false # county (or bezirk etc.) (use adm3? or a3?)
|
168
156
|
|
169
157
|
t.integer :pop # optional population count
|
170
158
|
t.integer :area # optional area in square km (sq. km)
|
@@ -172,16 +160,100 @@ create_table :regions do |t|
|
|
172
160
|
end
|
173
161
|
|
174
162
|
### fix: add kind to unique ???
|
175
|
-
add_index :
|
163
|
+
add_index :states, [:key, :country_id], unique: true
|
176
164
|
|
177
165
|
|
166
|
+
####
|
167
|
+
# todo: use a view (of states/admins) instead - why? why not??
|
168
|
+
# parts used for regierungsbezirke
|
169
|
+
create_table :parts do |t|
|
170
|
+
t.string :name, null: false
|
171
|
+
t.string :key, null: false
|
172
|
+
t.references :place, null: false
|
173
|
+
t.string :code # short two or three letter code e.g. NY, OAX, etc.
|
174
|
+
t.string :abbr # optional conventional abbrevation (e.g. Stmk., Gto., etc.)
|
175
|
+
t.string :iso # iso code -- check in use/possible - ???
|
176
|
+
t.string :nuts # nuts code (europe/eu only)
|
177
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
178
|
+
|
179
|
+
t.references :state, null: false
|
180
|
+
t.integer :level, null: false, default: 2 # default assumes 2
|
181
|
+
### change to l (instead of level)!!!! - shorter, why, why not???
|
178
182
|
|
179
|
-
|
180
|
-
t.
|
181
|
-
t.
|
182
|
-
t.references :zone ## tourist zone e.g. fraenkische schweiz, wachau, steigerwald, etc. - use own join table???
|
183
|
+
t.integer :pop # optional population count
|
184
|
+
t.integer :area # optional area in square km (sq. km)
|
185
|
+
t.timestamps
|
183
186
|
end
|
184
187
|
|
188
|
+
####
|
189
|
+
# todo: use a view (of states/admins) instead - why? why not??
|
190
|
+
# counties used for kreise, bezirke, etc.
|
191
|
+
|
192
|
+
create_table :counties do |t|
|
193
|
+
t.string :name, null: false
|
194
|
+
t.string :key, null: false
|
195
|
+
t.references :place, null: false
|
196
|
+
t.string :code # short two or three letter code e.g. NY, OAX, etc.
|
197
|
+
t.string :abbr # optional conventional abbrevation (e.g. Stmk., Gto., etc.)
|
198
|
+
t.string :iso # iso code -- check in use/possible - ???
|
199
|
+
t.string :nuts # nuts code (europe/eu only)
|
200
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
201
|
+
|
202
|
+
t.references :state, null: false
|
203
|
+
t.references :part # optional part (e.g. regierungsbezirk, etc.)
|
204
|
+
t.integer :level, null: false, default: 2 # default assumes 2 - note: is (change to) 3 if parts incl.
|
205
|
+
### change to l (instead of level)!!!! - shorter, why, why not???
|
206
|
+
|
207
|
+
t.integer :pop # optional population count
|
208
|
+
t.integer :area # optional area in square km (sq. km)
|
209
|
+
t.timestamps
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
####
|
214
|
+
# todo: use a view (of states/admins) instead - why? why not??
|
215
|
+
# counties used for kreise, bezirke, etc.
|
216
|
+
|
217
|
+
create_table :munis do |t|
|
218
|
+
t.string :name, null: false
|
219
|
+
t.string :key, null: false
|
220
|
+
t.references :place, null: false
|
221
|
+
t.string :code # short two or three letter code e.g. NY, OAX, etc.
|
222
|
+
t.string :abbr # optional conventional abbrevation (e.g. Stmk., Gto., etc.)
|
223
|
+
t.string :iso # iso code -- check in use/possible - ???
|
224
|
+
t.string :nuts # nuts code (europe/eu only)
|
225
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
226
|
+
|
227
|
+
t.references :state, null: false
|
228
|
+
t.references :county # optional county (e.g. bezirk,kreis, etc.)
|
229
|
+
t.integer :level, null: false, default: 3 # default assumes 3 - note: is (change to) 4 if parts incl.
|
230
|
+
### change to l (instead of level)!!!! - shorter, why, why not???
|
231
|
+
|
232
|
+
t.integer :pop # optional population count
|
233
|
+
t.integer :area # optional area in square km (sq. km)
|
234
|
+
t.timestamps
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
## kind of regions but not hierachical (used for tourist/colloquial zones etc.)
|
240
|
+
# uses many-to-many join tables w/ cities n states/admins
|
241
|
+
#
|
242
|
+
# examples:
|
243
|
+
# Salzkammergut (part of Salzburg and Oberoesterreich)
|
244
|
+
# others
|
245
|
+
# Oberfranken -> Fichtelgebierge/Fraenkische Schweiz/etc.
|
246
|
+
create_table :zones do |t|
|
247
|
+
# to be done
|
248
|
+
end
|
249
|
+
|
250
|
+
## create_table :city_rels do |t| ## city relationships (w/ states/admins) -- part of state/zone
|
251
|
+
## t.references :city, null: false
|
252
|
+
## t.references :state ## optional ?? either state/admin or zone ?? use polymorphic assoc or use node w/ kind for place?
|
253
|
+
## t.references :zone ## tourist zone e.g. fraenkische schweiz, wachau, steigerwald, etc. - use own join table???
|
254
|
+
## end
|
255
|
+
|
256
|
+
|
185
257
|
create_table :cities do |t|
|
186
258
|
t.string :name, null: false
|
187
259
|
t.string :key, null: false
|
@@ -189,26 +261,53 @@ create_table :cities do |t|
|
|
189
261
|
t.string :code # short three letter code (ITAT/airport code e.g. NYC or VIE)
|
190
262
|
t.string :alt_names # comma separated list of alternate names (synonyms)
|
191
263
|
t.references :country, null: false
|
192
|
-
t.references :
|
193
|
-
t.references :
|
194
|
-
t.
|
195
|
-
t.
|
264
|
+
t.references :state # optional for now (e.g. state, bundesland, etc.) -- ADM1
|
265
|
+
t.references :part # optional for now (e.g. regierungsbezirk, etc.) -- x /ADM2
|
266
|
+
t.references :county # optional for now (e.g. landkreis, bezirk, etc.) -- ADM2/ADM3
|
267
|
+
t.references :muni # optional for now (e.g. gemeinde, etc.) -- ADM3/ADM4
|
268
|
+
|
269
|
+
t.references :metro # optional for now (part of metro e.g. Ruhrgebiet or Vienna Metro(politean) Area etc.)
|
270
|
+
|
271
|
+
t.integer :pop # optional population count (city proper); see metro for metro pop
|
196
272
|
t.integer :area # optional area in square km (sq. km)
|
197
273
|
|
198
274
|
## t.float :lat # optional for now -- FIX: remove?? moved to places
|
199
275
|
## t.float :lng # optional for now -- FIX: remove?? moved to places
|
200
276
|
|
201
|
-
## flags (use single int named flags - why? why not?
|
202
|
-
### fix: use a generic kind string type flag!!!!!!
|
203
|
-
t.boolean :m, null: false, default: false # metro flag
|
204
|
-
t.boolean :c, null: false, default: false # city flag (is this needed?)
|
205
|
-
t.boolean :d, null: false, default: false # district flag
|
206
|
-
|
207
277
|
### t.boolean :capital, null: false, default: false # is national captial?
|
208
278
|
|
209
279
|
t.timestamps
|
210
280
|
end
|
211
281
|
|
282
|
+
create_table :metros do |t|
|
283
|
+
t.string :name, null: false
|
284
|
+
t.string :key, null: false
|
285
|
+
t.references :place, null: false
|
286
|
+
t.string :code # short three letter code (ITAT/airport code e.g. NYC or VIE)
|
287
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
288
|
+
t.references :country, null: false
|
289
|
+
|
290
|
+
t.integer :pop # optional population count
|
291
|
+
t.integer :area # optional area in square km (sq. km)
|
292
|
+
|
293
|
+
t.timestamps
|
294
|
+
end
|
295
|
+
|
296
|
+
create_table :districts do |t|
|
297
|
+
t.string :name, null: false
|
298
|
+
t.string :key, null: false
|
299
|
+
t.references :place, null: false
|
300
|
+
t.string :code # short three letter code (ITAT/airport code e.g. NYC or VIE)
|
301
|
+
t.string :alt_names # comma separated list of alternate names (synonyms)
|
302
|
+
t.references :city, null: false
|
303
|
+
|
304
|
+
t.integer :pop # optional population count
|
305
|
+
t.integer :area # optional area in square km (sq. km)
|
306
|
+
|
307
|
+
t.timestamps
|
308
|
+
end
|
309
|
+
|
310
|
+
|
212
311
|
|
213
312
|
create_table :langs do |t| # langs == languages (e.g. en/English, de/Deutsch, etc.)
|
214
313
|
t.string :key, null: false
|
data/lib/worlddb/stats.rb
CHANGED
@@ -9,10 +9,13 @@ module WorldDb
|
|
9
9
|
puts "Stats:"
|
10
10
|
puts " #{'%5d' % Continent.count} continents"
|
11
11
|
puts " #{'%5d' % Country.count} countries (#{Country.where(s: true).count} supras, #{Country.where(d:true).count} deps), #{Country.where(m:true).count} miscs)"
|
12
|
-
puts " #{'%5d' %
|
13
|
-
puts " #{'%5d' %
|
14
|
-
puts " #{'%5d' %
|
15
|
-
puts " #{'%5d' %
|
12
|
+
puts " #{'%5d' % State.count} states (ADM1)"
|
13
|
+
puts " #{'%5d' % Part.count} parts (x/ADM2)"
|
14
|
+
puts " #{'%5d' % County.count} counties (ADM2/ADM3)"
|
15
|
+
puts " #{'%5d' % Muni.count} munis (ADM3/ADM4)"
|
16
|
+
puts " #{'%5d' % Metro.count} metros"
|
17
|
+
puts " #{'%5d' % City.count} cities"
|
18
|
+
puts " #{'%5d' % District.count} districts"
|
16
19
|
puts " #{'%5d' % Place.count} places"
|
17
20
|
puts " #{'%5d' % Name.count} names"
|
18
21
|
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
# fix: move into TextUtils namespace/module!!
|
5
|
+
|
6
|
+
class TreeReader
|
7
|
+
|
8
|
+
include LogUtils::Logging
|
9
|
+
|
10
|
+
def self.from_file( path )
|
11
|
+
## nb: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
12
|
+
## - see textutils/utils.rb
|
13
|
+
text = File.read_utf8( path )
|
14
|
+
self.from_string( text )
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.from_string( text )
|
18
|
+
self.new( text )
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize( text )
|
22
|
+
@text = text
|
23
|
+
end
|
24
|
+
|
25
|
+
TreeItem = Struct.new( :level, :key, :value )
|
26
|
+
|
27
|
+
KEY_REGEX = /
|
28
|
+
([0-9][0-9A-Za-z]*) ## key starting with a nummer
|
29
|
+
|
|
30
|
+
([a-z]+) ## key all lowercase e.g. bt,n,etc.
|
31
|
+
|
|
32
|
+
([A-Z]+) ## key all uppercase e.g. BT,N,etc
|
33
|
+
/x
|
34
|
+
|
35
|
+
LEVEL_REGEX = /\.+/ ## e.g. .. or .... etc.
|
36
|
+
|
37
|
+
|
38
|
+
def each_line
|
39
|
+
stack = [] # note: last_level => stack.size; starts w/ 0
|
40
|
+
times = 2 # assume two indents factor (e.g. .. =2, ....=3 etc. ) for now
|
41
|
+
|
42
|
+
reader = LineReader.from_string( @text )
|
43
|
+
reader.each_line do |line|
|
44
|
+
|
45
|
+
logger.debug "[TreeReader] line (before) => >#{line}<"
|
46
|
+
|
47
|
+
s = StringScanner.new( line )
|
48
|
+
s.skip( /[ \t]+/ ) # remove whitespace
|
49
|
+
|
50
|
+
key = s.scan( KEY_REGEX )
|
51
|
+
if key
|
52
|
+
s.skip( /[ \t]+/ ) # remove whitespace
|
53
|
+
end
|
54
|
+
|
55
|
+
level_str = s.scan( LEVEL_REGEX )
|
56
|
+
if level_str
|
57
|
+
## FIX!! todo/check: make sure level_str.size is a multiple of two !! (e.g. 2,4,6,etc.)
|
58
|
+
level = (level_str.size/times)+1
|
59
|
+
s.skip( /[ \t]+/ ) # remove whitespace
|
60
|
+
else
|
61
|
+
level = 1 ## no level found; assume top level (start w/ 1)
|
62
|
+
end
|
63
|
+
|
64
|
+
## assume rest is record
|
65
|
+
rest = s.rest ## was: s.scan( /.+/ )
|
66
|
+
|
67
|
+
level_diff = level - stack.size
|
68
|
+
|
69
|
+
if level_diff > 0
|
70
|
+
logger.debug "[TreeReader] up +#{level_diff}"
|
71
|
+
## FIX!!! todo/check/verify/assert: always must be +1
|
72
|
+
elsif level_diff < 0
|
73
|
+
logger.debug "[TreeReader] down #{level_diff}"
|
74
|
+
level_diff.abs.times { stack.pop }
|
75
|
+
stack.pop
|
76
|
+
else
|
77
|
+
## same level
|
78
|
+
stack.pop
|
79
|
+
end
|
80
|
+
|
81
|
+
item = TreeItem.new
|
82
|
+
item.level = level
|
83
|
+
item.key = key
|
84
|
+
item.value = rest
|
85
|
+
|
86
|
+
stack.push( item )
|
87
|
+
|
88
|
+
## for debugging - show tree item (note) hierarchy
|
89
|
+
names = stack.map { |it| "(#{it.level}) #{it.value}" }
|
90
|
+
logger.debug "[TreeReader] #{names.join( ' › ' )} -- key: >#{key}<, level: >#{level}<, rest: >#{rest}<"
|
91
|
+
|
92
|
+
yield( stack )
|
93
|
+
end
|
94
|
+
end # method each_line
|
95
|
+
|
96
|
+
end # class TreeReader
|
97
|
+
|
data/lib/worlddb/version.rb
CHANGED
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/adm/test_fixture_matcher_adm2.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestFixtureMatcherAdm2 < MiniTest::Test
|
12
|
+
|
13
|
+
include WorldDb::Matcher
|
14
|
+
|
15
|
+
def test_de
|
16
|
+
de = [
|
17
|
+
'de-deutschland!/by-bayern/parts',
|
18
|
+
'de-deutschland/by-bayern/parts',
|
19
|
+
'de-deutschland!/3--by-bayern/parts',
|
20
|
+
'de-deutschland/3--by-bayern/parts',
|
21
|
+
'europe/de-deutschland!/3--by-bayern/parts',
|
22
|
+
'europe/de-deutschland/3--by-bayern/parts',
|
23
|
+
]
|
24
|
+
assert_match_adm2_parts_for_country( de, 'de', 'by' )
|
25
|
+
end # method test_de
|
26
|
+
|
27
|
+
|
28
|
+
def test_at
|
29
|
+
at = [
|
30
|
+
'at-austria!/n-niederoesterreich/counties',
|
31
|
+
'at-austria/n-niederoesterreich/counties',
|
32
|
+
'at-austria!/1--n-niederoesterreich/counties',
|
33
|
+
'at-austria/1--n-niederoesterreich/counties',
|
34
|
+
'at-austria!/1--n-niederoesterreich/counties',
|
35
|
+
'europe/at-austria/1--n-niederoesterreich/counties',
|
36
|
+
]
|
37
|
+
assert_match_adm2_counties_for_country( at, 'at', 'n' )
|
38
|
+
end # method test_at
|
39
|
+
|
40
|
+
|
41
|
+
def test_at_more
|
42
|
+
b = [ 'at-austria!/1--b-burgenland/counties' ]
|
43
|
+
n = [ 'at-austria!/2--n-niederoesterreich/counties' ]
|
44
|
+
w = [ 'at-austria!/3--w-wien/counties' ]
|
45
|
+
|
46
|
+
assert_match_adm2_counties_for_country( b, 'at', 'b' )
|
47
|
+
assert_match_adm2_counties_for_country( n, 'at', 'n' )
|
48
|
+
assert_match_adm2_counties_for_country( w, 'at', 'w' )
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
private
|
53
|
+
def assert_match_adm2_parts_for_country( ary, expected_country_key, expected_state_key )
|
54
|
+
ary.each do |name|
|
55
|
+
found = match_adm2_parts_for_country( name ) do |country_key,state_key|
|
56
|
+
assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
|
57
|
+
assert_equal state_key, expected_state_key, "#{expected_state_key} expected is #{state_key}"
|
58
|
+
end
|
59
|
+
assert found, "no match for '#{name}'"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def assert_match_adm2_counties_for_country( ary, expected_country_key, expected_state_key )
|
64
|
+
ary.each do |name|
|
65
|
+
found = match_adm2_counties_for_country( name ) do |country_key,state_key|
|
66
|
+
assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
|
67
|
+
assert_equal state_key, expected_state_key, "#{expected_state_key} expected is #{state_key}"
|
68
|
+
end
|
69
|
+
assert found, "no match for '#{name}'"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
end # class TestFixtureMatcherAdm2
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
###
|
4
4
|
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_fixture_matcher_adm3.rb
|
5
|
+
# ruby -I ./lib -I ./test test/adm/test_fixture_matcher_adm3.rb
|
6
6
|
|
7
7
|
|
8
8
|
require 'helper'
|
@@ -21,17 +21,17 @@ class TestFixtureMatcherAdm3 < MiniTest::Test
|
|
21
21
|
'europe/de-deutschland!/3--by-bayern/4--oberfranken/counties',
|
22
22
|
'europe/de-deutschland/3--by-bayern/4--oberfranken/counties',
|
23
23
|
]
|
24
|
-
|
24
|
+
assert_match_adm3_counties_for_country( oberfranken, 'de', 'by', 'oberfranken' )
|
25
25
|
end # method test_oberfranken
|
26
26
|
|
27
27
|
|
28
28
|
private
|
29
|
-
def
|
29
|
+
def assert_match_adm3_counties_for_country( ary, expected_country_key, expected_state_key, expected_part_name )
|
30
30
|
ary.each do |name|
|
31
|
-
found =
|
31
|
+
found = match_adm3_counties_for_country( name ) do |country_key,state_key,part_name|
|
32
32
|
assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
|
33
|
-
assert_equal
|
34
|
-
assert_equal
|
33
|
+
assert_equal state_key, expected_state_key, "#{expected_state_key} expected is #{state_key}"
|
34
|
+
assert_equal part_name, expected_part_name, "#{expected_part_name} expected is #{part_name}"
|
35
35
|
end
|
36
36
|
assert found, "no match for '#{name}'"
|
37
37
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/adm/test_fixture_matcher_tree.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
|
11
|
+
class TestFixtureMatcherTree < MiniTest::Test
|
12
|
+
|
13
|
+
include WorldDb::Matcher
|
14
|
+
|
15
|
+
def test_de
|
16
|
+
de = [
|
17
|
+
'de-deutschland!/orte',
|
18
|
+
'de-deutschland!/3--by-bayern/orte',
|
19
|
+
'de-deutschland/3--by-bayern/orte',
|
20
|
+
'de-deutschland!/3--by-bayern/4--oberfranken/orte',
|
21
|
+
'europe/de-deutschland!/3--by-bayern/orte',
|
22
|
+
'europe/de-deutschland/3--by-bayern/orte',
|
23
|
+
'europe/de-deutschland!/orte',
|
24
|
+
]
|
25
|
+
assert_match_tree_for_country( de, 'de' )
|
26
|
+
end # method test_de
|
27
|
+
|
28
|
+
|
29
|
+
def test_at
|
30
|
+
at = [
|
31
|
+
'at-austria!/n-niederoesterreich/orte',
|
32
|
+
'at-austria/n-niederoesterreich/orte',
|
33
|
+
'at-austria!/1--n-niederoesterreich/orte',
|
34
|
+
'at-austria!/orte',
|
35
|
+
'at-austria/orte',
|
36
|
+
'europe/at-austria/1--n-niederoesterreich/orte',
|
37
|
+
]
|
38
|
+
assert_match_tree_for_country( at, 'at' )
|
39
|
+
end # method test_at
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
def assert_match_tree_for_country( ary, expected_country_key )
|
44
|
+
ary.each do |name|
|
45
|
+
found = match_tree_for_country( name ) do |country_key|
|
46
|
+
assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
|
47
|
+
end
|
48
|
+
assert found, "no match for '#{name}'"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end # class TestFixtureMatcherTree
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
###
|
4
4
|
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_read_adm.rb
|
5
|
+
# ruby -I ./lib -I ./test test/adm/test_read_adm.rb
|
6
6
|
|
7
7
|
|
8
8
|
require 'helper'
|
@@ -10,7 +10,7 @@ require 'helper'
|
|
10
10
|
class TestReadAdm < MiniTest::Test
|
11
11
|
|
12
12
|
def setup
|
13
|
-
# delete all countries,
|
13
|
+
# delete all countries, states, cities in in-memory only db
|
14
14
|
WorldDb.delete!
|
15
15
|
end
|
16
16
|
|
@@ -24,9 +24,7 @@ class TestReadAdm < MiniTest::Test
|
|
24
24
|
reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/at-austria" )
|
25
25
|
reader.load_setup( 'setups/adm' )
|
26
26
|
|
27
|
-
|
28
|
-
## todo/fix: shorten level to l -- why, why not???
|
29
|
-
assert_equal 9, at.regions.where(level:1).count
|
27
|
+
assert_equal 9, at.states.count
|
30
28
|
end
|
31
29
|
|
32
30
|
|
@@ -41,27 +39,22 @@ class TestReadAdm < MiniTest::Test
|
|
41
39
|
reader.load_setup( 'setups/adm' )
|
42
40
|
|
43
41
|
|
44
|
-
|
45
|
-
## todo/fix: shorten level to l -- why, why not???
|
42
|
+
assert_equal 16, de.states.count
|
46
43
|
|
47
|
-
|
48
|
-
|
44
|
+
by = State.find_by_key!( 'by' )
|
45
|
+
assert_equal 7, by.parts.count
|
46
|
+
## assert_equal 23+, by.counties.count
|
49
47
|
|
50
|
-
|
51
|
-
assert_equal 7, by.regions.where(level:2).count
|
52
|
-
## assert_equal 7+??, by.regions.count
|
48
|
+
## pp by.parts
|
53
49
|
|
54
|
-
|
55
|
-
|
56
|
-
ob = Region.find_by_key!( 'ob' )
|
50
|
+
ob = Part.find_by_key!( 'ob' )
|
57
51
|
assert_equal 'Oberbayern', ob.name
|
58
|
-
assert_equal 23, ob.
|
59
|
-
assert_equal 23, ob.regions.count
|
52
|
+
assert_equal 23, ob.counties.count
|
60
53
|
|
61
|
-
ofr =
|
54
|
+
ofr = Part.find_by_key!( 'ofr' )
|
62
55
|
assert_equal 'Oberfranken', ofr.name
|
63
|
-
assert_equal 13, ofr.
|
64
|
-
assert_equal 13, ofr.regions.count
|
56
|
+
assert_equal 13, ofr.counties.count
|
65
57
|
end
|
66
58
|
|
67
59
|
end # class TestReadAdm
|
60
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/adm/test_read_tree.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestReadTree < MiniTest::Test
|
11
|
+
|
12
|
+
def setup
|
13
|
+
# delete all countries, states, cities in in-memory only db
|
14
|
+
WorldDb.delete!
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_at
|
18
|
+
at = Country.create!( key: 'at',
|
19
|
+
name: 'Austria',
|
20
|
+
code: 'AUT',
|
21
|
+
pop: 0,
|
22
|
+
area: 0 )
|
23
|
+
|
24
|
+
reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/at-austria" )
|
25
|
+
reader.load_setup( 'setups/tree' )
|
26
|
+
|
27
|
+
assert_equal 9, at.states.count
|
28
|
+
|
29
|
+
## todo: add more asserts
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def test_de
|
34
|
+
de = Country.create!( key: 'de',
|
35
|
+
name: 'Germany',
|
36
|
+
code: 'GER',
|
37
|
+
pop: 0,
|
38
|
+
area: 0 )
|
39
|
+
|
40
|
+
reader = WorldDb::Reader.new( "#{WorldDb.root}/test/data/de-deutschland" )
|
41
|
+
reader.load_setup( 'setups/tree' )
|
42
|
+
|
43
|
+
|
44
|
+
assert_equal 16, de.states.count
|
45
|
+
|
46
|
+
by = State.find_by_key!( 'by' )
|
47
|
+
assert_equal 7, by.parts.count
|
48
|
+
## assert_equal 23+, by.counties.count
|
49
|
+
|
50
|
+
## pp by.parts
|
51
|
+
|
52
|
+
ob = Part.find_by_key!( 'ob' )
|
53
|
+
assert_equal 'Oberbayern', ob.name
|
54
|
+
assert_equal 23, ob.counties.count
|
55
|
+
|
56
|
+
ofr = Part.find_by_key!( 'ofr' )
|
57
|
+
assert_equal 'Oberfranken', ofr.name
|
58
|
+
assert_equal 13, ofr.counties.count
|
59
|
+
|
60
|
+
## todo: add more asserts
|
61
|
+
end
|
62
|
+
|
63
|
+
end # class TestReadTree
|