worlddb-models 2.2.1 → 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7166c33111b731ecc3e9199970da99ff49b725e
4
- data.tar.gz: 230f400cbcc9d7586ffc12558aacdac894ae3947
3
+ metadata.gz: e9b1bdb5484b5c74ef690b349dfd92dbb7fbd5d2
4
+ data.tar.gz: ed1e496ec5d29624d915dd9e93559eda99ead12e
5
5
  SHA512:
6
- metadata.gz: 0e9eeaa6e6803d5ae28d531f805ba38bf93f11c614fbbbd994e2c17321ed2f442376f851277befb1a156625ca8eb33a3991083b0a1d713185ef393dfce16c972
7
- data.tar.gz: f7fb67fd482e3909c51fcd7bee5aa8f61da3dc34c270bb17021d3775ccff7518687f98a606310901d895d39626b722f6f89ede93d4c2989bbf13c33fecb7745e
6
+ metadata.gz: 9ddd1c5c80416d77525a33cf1a54a79d953c2bc4303f7d305e0790b9d578990be7cfaf76576b5e2d9fc17ebc46f2bf3d353aa25d68771a8fb13a68f074a944e4
7
+ data.tar.gz: 8098bfbbbdaf6e23f47fe26a02315747581130c97455b2521cf4264d352c0d95f435dab6d8fe128b410ec1d839e6d423e1f937effef8a42771f51d7a72cadf68
data/Manifest.txt CHANGED
@@ -34,7 +34,19 @@ lib/worlddb/readers/usage.rb
34
34
  lib/worlddb/schema.rb
35
35
  lib/worlddb/stats.rb
36
36
  lib/worlddb/version.rb
37
+ test/data/at-austria/1--b-burgenland/counties.txt
38
+ test/data/at-austria/2--n-niederoesterreich/counties.txt
39
+ test/data/at-austria/3--w-wien/counties.txt
40
+ test/data/at-austria/setups/adm.txt
41
+ test/data/at-austria/states.txt
42
+ test/data/de-deutschland/3--by-bayern/1--oberbayern/counties.txt
43
+ test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt
44
+ test/data/de-deutschland/3--by-bayern/districts.txt
45
+ test/data/de-deutschland/setups/adm.txt
46
+ test/data/de-deutschland/states.txt
37
47
  test/helper.rb
48
+ test/test_fixture_matcher_adm2.rb
49
+ test/test_fixture_matcher_adm3.rb
38
50
  test/test_fixture_matchers.rb
39
51
  test/test_fixture_matchers_ii.rb
40
52
  test/test_model_city.rb
@@ -42,3 +54,4 @@ test/test_model_comp.rb
42
54
  test/test_model_country.rb
43
55
  test/test_model_region.rb
44
56
  test/test_models.rb
57
+ test/test_read_adm.rb
@@ -4,14 +4,19 @@ module WorldDb
4
4
 
5
5
  module Matcher
6
6
 
7
+ # note: returns code as capture
7
8
  WORLD_COUNTRY_CODE_PATTERN = '([a-z]{2,3})'
8
9
  WORLD_COUNTRY_CLASSIC_PATTERN = "#{WORLD_COUNTRY_CODE_PATTERN}-[^\\/]+" ## note: if you use "" need to double escape backslash!!!
9
10
  WORLD_COUNTRY_MODERN_PATTERN = "[0-9]+--#{WORLD_COUNTRY_CODE_PATTERN}-[^\\/]+" ## note: if you use "" need to double escape backslash!!!
10
11
 
12
+ # note: returns code as capture
11
13
  WORLD_REGION_CODE_PATTERN = '([a-z]{1,3})'
12
14
  WORLD_REGION_CLASSIC_PATTERN = "#{WORLD_REGION_CODE_PATTERN}-[^\\/]+"
13
15
  WORLD_REGION_MODERN_PATTERN = "[0-9]+--#{WORLD_REGION_CODE_PATTERN}-[^\\/]+"
14
16
 
17
+ # note: returns name as capture (no code required)
18
+ WORLD_ADMIN_MODERN_PATTERN = "[0-9]+--([^\\/]+)"
19
+
15
20
  ## allow optional folders -- TODO: add restriction ?? e.g. must be 4+ alphas ???
16
21
  WORLD_OPT_FOLDERS_PATTERN = "(?:\\/[^\\/]+)*" ## check: use double \\ or just \ ??
17
22
 
@@ -100,6 +105,68 @@ module Matcher
100
105
  end
101
106
 
102
107
 
108
+
109
+ def match_xxx_for_country_n_adm1( name, xxx ) # xxx e.g. districts|counties|etc.
110
+
111
+ # auto-add required country n regions (from folder structure)
112
+ #
113
+ # e.g. de-deutschland!/3--by-bayern/districts (regierungsbezirke)
114
+ # europe/de-deutschland!/3--by-bayern/districts
115
+ #
116
+ # at-austria!/1--n-niederoesterreich/counties (bezirke)
117
+
118
+ xxx_pattern = "#{xxx}"
119
+
120
+ if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_MODERN_PATTERN}\/#{xxx_pattern}/ ||
121
+ name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_CLASSIC_PATTERN}\/#{xxx_pattern}/
122
+
123
+ country_key = $1.dup
124
+ region_key = $2.dup
125
+ yield( country_key, region_key )
126
+ true # bingo - match found
127
+ else
128
+ false # no match found
129
+ end
130
+ end
131
+
132
+
133
+ def match_xxx_for_country_n_adm1_n_adm2( name, xxx ) # xxx e.g. districts|counties|etc.
134
+
135
+ # auto-add required country n regions (from folder structure)
136
+ #
137
+ # e.g. de-deutschland!/3--by-bayern/4--oberfranken/counties (landkreise)
138
+ # europe/de-deutschland!/3--by-bayern/4--oberfranken/counties
139
+
140
+ xxx_pattern = "#{xxx}"
141
+
142
+ if name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_MODERN_PATTERN}\/#{WORLD_ADMIN_MODERN_PATTERN}\/#{xxx_pattern}/ ||
143
+ name =~ /(?:^|\/)#{WORLD_COUNTRY_CLASSIC_PATTERN}\/#{WORLD_REGION_CLASSIC_PATTERN}\/#{WORLD_ADMIN_MODERN_PATTERN}\/#{xxx_pattern}/
144
+
145
+ country_key = $1.dup
146
+ region_key = $2.dup
147
+ adm2 = $3.dup # lowercase name e.g. oberfranken, oberbayern, etc.
148
+ yield( country_key, region_key, adm2 )
149
+ true # bingo - match found
150
+ else
151
+ false # no match found
152
+ end
153
+ end
154
+
155
+
156
+ def match_adm2_for_country( name, &blk )
157
+ ## note: also try synonyms e.g. districts|counties
158
+ ## note: counties might also be an adm3 match
159
+ found = match_xxx_for_country_n_adm1( name, 'districts', &blk )
160
+ found = match_xxx_for_country_n_adm1( name, 'counties', &blk ) unless found
161
+ found
162
+ end
163
+
164
+ def match_adm3_for_country( name, &blk )
165
+ match_xxx_for_country_n_adm1_n_adm2( name, 'counties', &blk )
166
+ end
167
+
168
+
169
+
103
170
  def match_cities_for_country( name, &blk )
104
171
  ## todo: check if there's a better (more ruby way) to pass along code block ??
105
172
  ## e.g. try
@@ -29,6 +29,9 @@ class Country < ActiveRecord::Base
29
29
  ## self referencing hierachy within countries e.g. EU > GB > EN
30
30
  belongs_to :parent, class_name: 'Country', foreign_key: 'country_id'
31
31
  has_many :countries, class_name: 'Country', foreign_key: 'country_id'
32
+ ### recursive self-reference - use node??
33
+ ## has_many :nodes, class_name: 'Region', foregin_key: 'region_id'
34
+
32
35
 
33
36
  has_many_tags
34
37
 
@@ -22,6 +22,11 @@ class Region < ActiveRecord::Base
22
22
  validates :key, format: { with: /#{REGION_KEY_PATTERN}/, message: REGION_KEY_PATTERN_MESSAGE }
23
23
  validates :code, format: { with: /#{REGION_CODE_PATTERN}/, message: REGION_CODE_PATTERN_MESSAGE }, allow_nil: true
24
24
 
25
+ ### recursive self-reference - use "generic" node??
26
+ ## has_many :nodes, class_name: 'Region', foregin_key: 'region_id'
27
+ belongs_to :parent, class_name: 'Region', foreign_key: 'region_id'
28
+ has_many :regions, class_name: 'Region', foreign_key: 'region_id' ## subregions
29
+
25
30
 
26
31
  before_create :on_create
27
32
  before_update :on_update
@@ -36,8 +41,18 @@ class Region < ActiveRecord::Base
36
41
  place.update_attributes!( name: name, kind: place_kind )
37
42
  end
38
43
 
44
+ def is_district?() d? == true; end
45
+ def is_county?() c? == true; end
46
+
39
47
  def place_kind # use place_kind_of_code ??
40
- 'ADM1'
48
+ ### fix: use "generic" level counter - make it a database field (default/top level is 1)
49
+ if is_district?
50
+ 'ADM2'
51
+ elsif is_county?
52
+ 'ADM3'
53
+ else
54
+ 'ADM1'
55
+ end
41
56
  end
42
57
 
43
58
 
@@ -94,12 +94,41 @@ class ReaderBase
94
94
  elsif match_regions_nuts_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions\.nuts/
95
95
  load_regions_xxx( country_key, 'nuts', name )
96
96
  end
97
+ elsif match_adm3_for_country( name ) do |country_key,region_key,adm2_name|
98
+ ## auto-add required country code (from folder structure)
99
+ country = Country.find_by_key!( country_key )
100
+ logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
101
+ region = Region.find_by_key_and_country_id!( region_key, country.id )
102
+ logger.debug "Region (Adm1) #{region.key} >#{region.title}<"
103
+ ### todo: move find adm2 to model for (re)use !!!
104
+ adm2 = Region.where( "lower(name) = ? AND country_id = ?",
105
+ adm2_name, country.id ).first ## check - first needed? returns ary??
106
+ if adm2.nil?
107
+ puts "*** error/warn: fix - skipping adm3 - adm2 '#{adm2_name}' not found"
108
+ next
109
+ end
110
+ logger.debug "Region (Adm2) #{adm2.key} >#{adm2.title}<"
111
+
112
+ r = create_region_reader( name, country_id: country.id, region_id: adm2.id, level:3, c:true )
113
+ r.read()
114
+ end
115
+ elsif match_adm2_for_country( name ) do |country_key,region_key|
116
+ ## auto-add required country code (from folder structure)
117
+ country = Country.find_by_key!( country_key )
118
+ logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
119
+ region = Region.find_by_key_and_country_id!( region_key, country.id )
120
+ logger.debug "Region (Adm1) #{region.key} >#{region.title}<"
121
+
122
+ r = create_region_reader( name, country_id: country.id, region_id: region.id, level:2, d:true )
123
+ r.read()
124
+ end
125
+ ### fix: change to match_adm1_for_country()
97
126
  elsif match_regions_for_country( name ) do |country_key| # name =~ /\/([a-z]{2})\/regions/
98
127
  ## auto-add required country code (from folder structure)
99
128
  country = Country.find_by_key!( country_key )
100
129
  logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
101
130
 
102
- r = create_region_reader( name, country_id: country.id )
131
+ r = create_region_reader( name, country_id: country.id, region_id: nil, level:1, s:true )
103
132
  r.read()
104
133
  end
105
134
  else
@@ -19,14 +19,14 @@ class Reader < ReaderBase
19
19
  end
20
20
 
21
21
  def create_lang_reader( name )
22
- path = "#{@include_path}/#{name}.yml" ## hash reader - use .yml??
22
+ path = "#{@include_path}/#{path_to_real_path(name)}.yml" ## hash reader - use .yml??
23
23
  logger.info "parsing data (lang) '#{name}' (#{path})..."
24
24
 
25
25
  LangReader.from_file( path )
26
26
  end
27
27
 
28
28
  def create_usage_reader( name )
29
- path = "#{@include_path}/#{name}.yml" ## hash reader - use .yml??
29
+ path = "#{@include_path}/#{path_to_real_path(name)}.yml" ## hash reader - use .yml??
30
30
  logger.info "parsing data (usage) '#{name}' (#{path})..."
31
31
 
32
32
  UsageReader.from_file( path )
@@ -34,21 +34,22 @@ class Reader < ReaderBase
34
34
 
35
35
 
36
36
  def create_country_reader( name, more_attribs={} )
37
- path = "#{@include_path}/#{name}.txt"
37
+ path = "#{@include_path}/#{path_to_real_path(name)}.txt"
38
38
  logger.info "parsing data (country) '#{name}' (#{path})..."
39
39
 
40
40
  CountryReader.from_file( path, more_attribs )
41
41
  end
42
42
 
43
43
  def create_region_reader( name, more_attribs={} )
44
- path = "#{@include_path}/#{name}.txt"
44
+ path = "#{@include_path}/#{path_to_real_path(name)}.txt"
45
+
45
46
  logger.info "parsing data (region) '#{name}' (#{path})..."
46
47
 
47
48
  RegionReader.from_file( path, more_attribs )
48
49
  end
49
50
 
50
51
  def create_city_reader( name, more_attribs={} )
51
- path = "#{@include_path}/#{name}.txt"
52
+ path = "#{@include_path}/#{path_to_real_path(name)}.txt"
52
53
  logger.info "parsing data (city) '#{name}' (#{path})..."
53
54
 
54
55
  CityReader.from_file( path, more_attribs )
@@ -56,21 +57,21 @@ class Reader < ReaderBase
56
57
 
57
58
 
58
59
  def create_hash_reader( name )
59
- path = "#{@include_path}/#{name}.yml"
60
+ path = "#{@include_path}/#{path_to_real_path(name)}.yml"
60
61
  logger.info "parsing data (hash) '#{name}' (#{path})..."
61
62
 
62
63
  HashReader.from_file( path )
63
64
  end
64
65
 
65
66
  def create_values_reader( name, more_attribs={} )
66
- path = "#{@include_path}/#{name}.txt"
67
+ path = "#{@include_path}/#{path_to_real_path(name)}.txt"
67
68
  logger.info "parsing data (values) '#{name}' (#{path})..."
68
69
 
69
70
  ValuesReader.from_file( path, more_attribs )
70
71
  end
71
72
 
72
73
  def create_line_reader( name )
73
- path = "#{@include_path}/#{name}.txt"
74
+ path = "#{@include_path}/#{path_to_real_path(name)}.txt"
74
75
  logger.info "parsing data (line) '#{name}' (#{path})..."
75
76
 
76
77
  LineReader.from_file( path )
@@ -82,5 +83,22 @@ class Reader < ReaderBase
82
83
  # end
83
84
 
84
85
 
86
+ private
87
+
88
+ def path_to_real_path( path )
89
+ # map name to name_real_path
90
+ # name might include !/ for virtual path (gets cut off)
91
+ # e.g. at-austria!/w-wien/beers becomse w-wien/beers
92
+ pos = path.index( '!/')
93
+ if pos.nil?
94
+ path # not found; real path is the same as name
95
+ else
96
+ # cut off everything until !/ e.g.
97
+ # at-austria!/w-wien/beers becomes
98
+ # w-wien/beers
99
+ path[ (pos+2)..-1 ]
100
+ end
101
+ end
102
+
85
103
  end # class Reader
86
104
  end # module WorldDb
@@ -98,6 +98,7 @@ create_table :countries do |t|
98
98
  t.references :country # for supra(nationals) n depend(encies)
99
99
 
100
100
  ## flags (use single int named flags - why? why not?
101
+ ### fix: use a generic kind string type flag!!!!!!
101
102
  t.boolean :s, null: false, default: false # supra(national) flag e.g. eu
102
103
  t.boolean :c, null: false, default: false # country flag (is this needed?)
103
104
  t.boolean :d, null: false, default: false # dependency flag
@@ -127,8 +128,20 @@ add_index :countries, :key, unique: true
127
128
  add_index :countries, :code, unique: true
128
129
 
129
130
 
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
+
130
143
  ######
131
- # NB: rename to adms/admins ??
144
+ # NB: rename to adms/admins ?? or use states ???
132
145
  #
133
146
  # used for state/provice/land/regioni/etc.
134
147
  create_table :regions do |t|
@@ -140,15 +153,35 @@ create_table :regions do |t|
140
153
  t.string :iso # iso code
141
154
  t.string :nuts # nuts code (europe/eu only)
142
155
  t.string :alt_names # comma separated list of alternate names (synonyms)
156
+
143
157
  t.references :country, null: false
158
+ t.references :region ## parent region (optional for now - may be null for top level e.g. state/province)
159
+ t.integer :level, null: false, default: 1 # default assumes 1 e.g. state/province/etc.
160
+ ### change to l (instead of level)!!!! - shorter, why, why not???
161
+
162
+ ## flags (use single int named flags - why? why not?
163
+ ### 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 :d, 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)
166
+ t.boolean :c, null: false, default: false # county (or bezirk etc.) (use adm3? or a3?)
167
+
168
+
144
169
  t.integer :pop # optional population count
145
170
  t.integer :area # optional area in square km (sq. km)
146
171
  t.timestamps
147
172
  end
148
173
 
174
+ ### fix: add kind to unique ???
149
175
  add_index :regions, [:key, :country_id], unique: true
150
176
 
151
177
 
178
+
179
+ create_table :city_rels do |t| ## city relationships (w/ regions) -- part of region/zone
180
+ t.references :city, null: false
181
+ t.references :region ## optional ?? either region or zone ?? use polymorphic assoc or use node w/ kind for place?
182
+ t.references :zone ## tourist zone e.g. fraenkische schweiz, wachau, steigerwald, etc. - use own join table???
183
+ end
184
+
152
185
  create_table :cities do |t|
153
186
  t.string :name, null: false
154
187
  t.string :key, null: false
@@ -166,6 +199,7 @@ create_table :cities do |t|
166
199
  ## t.float :lng # optional for now -- FIX: remove?? moved to places
167
200
 
168
201
  ## flags (use single int named flags - why? why not?
202
+ ### fix: use a generic kind string type flag!!!!!!
169
203
  t.boolean :m, null: false, default: false # metro flag
170
204
  t.boolean :c, null: false, default: false # city flag (is this needed?)
171
205
  t.boolean :d, null: false, default: false # district flag
@@ -5,7 +5,7 @@ module WorldDb
5
5
  # sync version w/ sport.db n friends - why? why not?
6
6
  MAJOR = 2 ## todo: namespace inside version or something - why? why not??
7
7
  MINOR = 2
8
- PATCH = 1
8
+ PATCH = 2
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
@@ -0,0 +1,20 @@
1
+ ## Burgenland (B)
2
+ #
3
+ ## 2 Statutarstädte - Eisenstadt, Rust
4
+ ## 7 Bezirke
5
+ ##
6
+ ## 13 Städte
7
+ ## 171 Gemeinden
8
+ ## 328 Ortschaften
9
+
10
+
11
+ e, Eisenstadt, Eisenstadt, 43 km²
12
+ eu, Eisenstadt-Umgebung, Eisenstadt, 453 km²
13
+ gs, Güssing, Güssing, 485 km²
14
+ je, Jennersdorf, Jennersdorf, 253 km²
15
+ ma, Mattersburg, Mattersburg, 238 km²
16
+ nd, Neusiedl am See, Neusiedl am See, 1039 km²
17
+ op, Oberpullendorf, Oberpullendorf, 701 km² ## also known as => Mittelburgenland
18
+ ow, Oberwart, Oberwart, 733 km²
19
+ eii, Rust, Rust, 20 km² ## also uses E - what to do for key??
20
+
@@ -0,0 +1,35 @@
1
+ ## Niederoesterreich (N)
2
+ #
3
+ ## ?? Statutarstädte -
4
+ ## ?? Bezirke
5
+ ##
6
+ ## ?? Städte
7
+ ## ?? Gemeinden
8
+ ## ?? Ortschaften
9
+
10
+ Krems an der Donau, 52 km², 24_085 # KS
11
+ St. Pölten, 108 km², 52_145 # P
12
+ Waidhofen an der Ybbs, 132 km², 11_341 # WY
13
+ Wiener Neustadt, 61 km², 42_273 # WN
14
+ Amstetten, 1188 km², 112_944 # AM
15
+ Baden, 753 km², 140_078 # BN
16
+ Bruck an der Leitha, 495 km², 43_615 # BL
17
+ Gänserndorf, 1271 km², 97_460 # GF
18
+ Gmünd, 786 km², 37_420 # GD
19
+ Hollabrunn, 1011 km², 50_065 # HL
20
+ Horn, 784 km², 31_273 # HO
21
+ Korneuburg, 627 km², 76_370 # KO
22
+ Krems-Land (Krems an der Donau), 924 km², 55_945 # KR
23
+ Lilienfeld, 932 km², 26_040 # LF
24
+ Melk, 1014 km², 76_369 # ME
25
+ Mistelbach, 1291 km², 74_150 # MI
26
+ Mödling, 277 km², 115_677 # MD
27
+ Neunkirchen, 1146 km², 85_539 # NK
28
+ St. Pölten-Land (St. Pölten), 1122 km², 97_365 # PL
29
+ Scheibbs, 1023 km², 41_073 # SB
30
+ Tulln (Tulln an der Donau), 658 km², 72_104 # TU
31
+ Waidhofen an der Thaya, 669 km², 26_424 # WT
32
+ Wiener Neustadt-Land (Wiener Neustadt), 970 km², 75_285 # WB
33
+ Wien-Umgebung (Klosterneuburg), 484 km², 117_343 # WU, SW (f. Schwechat)
34
+ Zwettl, 1400 km², 43_102 # ZT
35
+
@@ -0,0 +1,39 @@
1
+ ###
2
+ # use district.txt for name - why, why not??
3
+ # move to wien.db - why, why not ??
4
+ #
5
+ # include command \, -- why, why not?? change to - or something ?
6
+ # use ; as separator - why, why not??
7
+
8
+
9
+ ## fix: cannot handle comma in title for autokey
10
+ ## e.g. Wien 1.\, Innere Stadt
11
+ ## becomes
12
+ ## wien1,innerestadt
13
+
14
+
15
+ Innere Stadt (Wien 1.) ### fix/use: Wien 1.\, Innere Stadt
16
+ Leopoldstadt (Wien 2.) ### fix/use: Wien 2.\, Leopoldstadt
17
+ Landstraße (Wien 3.) ### fix/use: Wien 3.\, Landstraße
18
+
19
+ ### fix/use: Wien 4.\, Wieden
20
+ ### fix/use: Wien 5.\, Margareten
21
+ ### fix/use: Wien 6.\, Mariahilf
22
+ ### fix/use: Wien 7.\, Neubau
23
+ ### fix/use: Wien 8.\, Josefstadt
24
+ ### fix/use: Wien 9.\, Alsergrund
25
+ ### fix/use: Wien 10.\, Favoriten
26
+ ### fix/use: Wien 11.\, Simmering
27
+ ### fix/use: Wien 12.\, Meidling
28
+ ### fix/use: Wien 13.\, Hietzing
29
+ ### fix/use: Wien 14.\, Penzing
30
+ ### fix/use: Wien 15.\, Rudolfsheim-Fünfhaus
31
+ ### fix/use: Wien 16.\, Ottakring
32
+ ### fix/use: Wien 17.\, Hernals
33
+ ### fix/use: Wien 18.\, Währing
34
+ ### fix/use: Wien 19.\, Döbling
35
+ ### fix/use: Wien 20.\, Brigittenau
36
+ ### fix/use: Wien 21.\, Floridsdorf
37
+ ### fix/use: Wien 22.\, Donaustadt
38
+ ### fix/use: Wien 23.\, Liesing
39
+
@@ -0,0 +1,7 @@
1
+
2
+ at-austria!/states
3
+ at-austria!/1--b-burgenland/counties
4
+ at-austria!/2--n-niederoesterreich/counties
5
+ at-austria!/3--w-wien/counties
6
+
7
+
@@ -0,0 +1,18 @@
1
+ #############################
2
+ # Austria / Österreich (at)
3
+
4
+
5
+ # -- 9 Bundesländer
6
+
7
+ b, Burgenland, Eisenstadt, 3_962 km², 284_000
8
+ n, Niederösterreich [Lower Austria], St. Pölten, 19_186 km², 1_609_800
9
+ w, Wien [Vienna], Wien, 415 km², 1_707_000
10
+
11
+ st, Steiermark [Styria], Graz, 16_401 km², 1_208_900
12
+ k, Kärnten [Carinthia], Klagenfurt, 9_538 km², 560_700
13
+
14
+ o, Oberösterreich [Upper Austria], Linz, 11_980 km², 1_412_300
15
+ s, Salzburg, Salzburg, 7_156 km², 531_800
16
+ t, Tirol [Tyrol], Innsbruck, 12_640 km², 708_900
17
+ v, Vorarlberg, Bregenz, 2_601 km², 370_200
18
+
@@ -0,0 +1,51 @@
1
+ ###
2
+ # Oberbayern > Bayern
3
+ #
4
+ # Verwaltungssitz: München
5
+ #
6
+ # Größte Städte: München (1.4m), Ingolstadt (128_300), Rosenheim (61_800),
7
+ # Freising (45_600), Dachau (44_000), Germering (38_400)
8
+ #
9
+ # Der Regierungsbezirk Oberbayern umfasst
10
+ #
11
+ # 3 kreisfreie Städte - München, Ingolstadt Rosenheim
12
+ # 20 Landkreise
13
+
14
+
15
+ m, München (Kreisefreie Stadt) ## use (Stadt) ???
16
+ in, Ingolstadt
17
+ ro, Rosenheim (Kreisefreie Stadt) ## use (Stadt) ???
18
+
19
+
20
+ aoe, Altötting
21
+ Bad Tölz-Wolfratshausen, Bad Tölz, 1_111 km²
22
+ ## Kfz-Kennzeichen: TÖL, WOR - what to use ??
23
+
24
+ bgl, Berchtesgadener Land
25
+ dah, Dachau
26
+ ebe, Ebersberg
27
+ ei, Eichstätt
28
+ ed, Erding, Erding, 870 km²
29
+ fs, Freising, Freising, 802 km²
30
+ ffb, Fürstenfeldbruck
31
+ gap, Garmisch-Partenkirchen
32
+ ll, Landsberg am Lech
33
+ mb, Miesbach
34
+ mue, Mühldorf am Inn
35
+
36
+ München (Landkreis), München, 667 km² ### todo - use different key - see kreisfrei stadt muenchen
37
+ ## Kfz-Kennzeichen: M, AIB, WOR - what to use ??
38
+
39
+ Neuburg-Schrobenhausen
40
+ ## Kfz-Kennzeichen: ND, SOB - what to use ??
41
+
42
+ paf, Pfaffenhofen an der Ilm
43
+
44
+ Rosenheim (Landkreis) ### todo - use different key - see kreisfrei stadt rosenheim
45
+ ## Kfz-Kennzeichen: RO, AIB, WS - what to use ??
46
+
47
+ sta, Starnberg ## kfz-kennzeichen: STA, WOR
48
+ ts, Traunstein
49
+ Weilheim-Schongau
50
+ ## Kfz-Kennzeichen: WM, SOG - what to use ??
51
+
@@ -0,0 +1,42 @@
1
+ ################################################
2
+ # Der Regierungsbezirk Oberfranken umfasst
3
+ #
4
+ # 4 kreisfreie Städte und
5
+ # Bamberg
6
+ # Bayreuth
7
+ # Coburg
8
+ # Hof
9
+ # 9 Landkreise
10
+ # Landkreis Bamberg
11
+ # Landkreis Bayreuth
12
+ # Landkreis Coburg
13
+ # Landkreis Forchheim
14
+ # Landkreis Hof
15
+ # Landkreis Kronach
16
+ # Landkreis Kulmbach
17
+ # Landkreis Lichtenfels
18
+ # Landkreis Wunsiedel im Fichtelgebirge
19
+
20
+
21
+ # 4 kreisfreie Städte und
22
+
23
+ Bamberg (Kreisfreie Stadt)
24
+ Bayreuth (Kreisfreie Stadt)
25
+ Coburg (Kreisfreie Stadt)
26
+ Hof (Kreisfreie Stadt)
27
+
28
+
29
+ # 9 Landkreise
30
+ ## how to deal w/ same name?? (same keys)
31
+ ## - use bambergland, bayreuthland etc. for key ??
32
+
33
+ Bamberg-Landkreis ## (Landkreis)
34
+ Bayreuth-Landkreis ## (Landkreis)
35
+ Coburg-Landkreis ## (Landkreis)
36
+ Hof-Landkreis ## (Landkreis)
37
+
38
+ Forchheim (Landkreis)
39
+ Kronach (Landkreis)
40
+ Kulmbach (Landkreis)
41
+ Lichtenfels (Landkreis)
42
+ Wunsiedel im Fichtelgebirge (Landkreis)
@@ -0,0 +1,13 @@
1
+ ########################################
2
+ # Bayern
3
+ #
4
+ # 7 Regierungsbezirke (administrative districts or governmental districts - use unit/division?)
5
+
6
+ ob, Oberbayern, München, 17_530 km² # 091 OB
7
+ nb, Niederbayern, Landshut, 10_329 km² # 092 NB
8
+ opf, Oberpfalz, Regensburg, 9_690 km² # 093 OPf
9
+ ofr, Oberfranken, Bayreuth, 7_231 km² # 094 Ofr.
10
+ mfr, Mittelfranken, Ansbach, 7_245 km² # 095 Mfr.
11
+ ufr, Unterfranken, Würzburg, 8_531 km² # 096 Ufr.
12
+ schw, Schwaben, Augsburg, 9_993 km² # 097 Schw.
13
+
@@ -0,0 +1,8 @@
1
+ ################################
2
+ # test region reader/matcher
3
+
4
+
5
+ de-deutschland!/states
6
+ de-deutschland!/3--by-bayern/districts
7
+ de-deutschland!/3--by-bayern/1--oberbayern/counties
8
+ de-deutschland!/3--by-bayern/4--oberfranken/counties
@@ -0,0 +1,23 @@
1
+ ################################
2
+ # German / Deutschland (de)
3
+
4
+ # -- 16 Länder
5
+
6
+
7
+ bw, Baden-Württemberg, Stuttgart, 35_752 km², 10_755_000
8
+ by, Bayern [Bavaria], München, 70_552 km², 12_542_000
9
+ be, Berlin, Berlin, 892 km², 3_469_000
10
+ bb, Brandenburg, Potsdam, 29_479 km², 2_500_000
11
+ hb, Bremen, Bremen, 419 km², 661_000
12
+ hh, Hamburg, Hamburg, 755 km², 1_788_000
13
+ he, Hessen [Hesse], Wiesbaden, 21_115 km², 6_066_000
14
+ mv, Mecklenburg-Vorpommern [Mecklenburg-Western Pomerania], Schwerin, 23_180 km², 1_639_000
15
+ ni, Niedersachsen [Lower Saxony], Hannover, 47_609 km², 7_914_000
16
+ nw, Nordrhein-Westfalen [North Rhine-Westphalia], Düsseldorf, 34_085 km², 17_837_000
17
+ rp, Rheinland-Pfalz [Rhineland-Palatinate], Mainz, 19_853 km², 3_999_000
18
+ sl, Saarland, Saarbrücken, 2_569 km², 1_018_000
19
+ sn, Sachsen [Saxony], Dresden, 18_416 km², 4_143_000
20
+ st, Sachsen-Anhalt [Saxony-Anhalt], Magdeburg, 20_446 km², 2_331_000
21
+ sh, Schleswig-Holstein, Kiel, 15_799 km², 2_833_000
22
+ th, Thüringen [Thuringia], Erfurt, 16_172 km², 2_231_000
23
+
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/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/districts',
18
+ 'de-deutschland/by-bayern/districts',
19
+ 'de-deutschland!/3--by-bayern/districts',
20
+ 'de-deutschland/3--by-bayern/districts',
21
+ 'europe/de-deutschland!/3--by-bayern/districts',
22
+ 'europe/de-deutschland/3--by-bayern/districts',
23
+ ]
24
+ assert_match_adm2_for_country( de, 'de', 'by' )
25
+ end # method test_de
26
+
27
+ def test_at
28
+ at = [
29
+ 'at-austria!/n-niederoesterreich/counties',
30
+ 'at-austria/n-niederoesterreich/counties',
31
+ 'at-austria!/1--n-niederoesterreich/counties',
32
+ 'at-austria/1--n-niederoesterreich/counties',
33
+ 'at-austria!/1--n-niederoesterreich/counties',
34
+ 'europe/at-austria/1--n-niederoesterreich/counties',
35
+ ]
36
+ assert_match_adm2_for_country( at, 'at', 'n' )
37
+ end # method test_at
38
+
39
+
40
+ def test_at_more
41
+ b = [ 'at-austria!/1--b-burgenland/counties' ]
42
+ n = [ 'at-austria!/2--n-niederoesterreich/counties' ]
43
+ w = [ 'at-austria!/3--w-wien/counties' ]
44
+
45
+ assert_match_adm2_for_country( b, 'at', 'b' )
46
+ assert_match_adm2_for_country( n, 'at', 'n' )
47
+ assert_match_adm2_for_country( w, 'at', 'w' )
48
+ end
49
+
50
+
51
+ private
52
+ def assert_match_adm2_for_country( ary, expected_country_key, expected_region_key )
53
+ ary.each do |name|
54
+ found = match_adm2_for_country( name ) do |country_key,region_key|
55
+ assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
56
+ assert_equal region_key, expected_region_key, "#{expected_region_key} expected is #{region_key}"
57
+ end
58
+ assert found, "no match for '#{name}'"
59
+ end
60
+ end
61
+
62
+ end # class TestFixtureMatcherAdm2
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_fixture_matcher_adm3.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestFixtureMatcherAdm3 < MiniTest::Test
12
+
13
+ include WorldDb::Matcher
14
+
15
+ def test_oberfranken
16
+ oberfranken = [
17
+ 'de-deutschland!/by-bayern/4--oberfranken/counties',
18
+ 'de-deutschland/by-bayern/4--oberfranken/counties',
19
+ 'de-deutschland!/3--by-bayern/4--oberfranken/counties',
20
+ 'de-deutschland/3--by-bayern/4--oberfranken/counties',
21
+ 'europe/de-deutschland!/3--by-bayern/4--oberfranken/counties',
22
+ 'europe/de-deutschland/3--by-bayern/4--oberfranken/counties',
23
+ ]
24
+ assert_match_adm3_for_country( oberfranken, 'de', 'by', 'oberfranken' )
25
+ end # method test_oberfranken
26
+
27
+
28
+ private
29
+ def assert_match_adm3_for_country( ary, expected_country_key, expected_region_key, expected_adm2 )
30
+ ary.each do |name|
31
+ found = match_adm3_for_country( name ) do |country_key,region_key,adm2|
32
+ assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
33
+ assert_equal region_key, expected_region_key, "#{expected_region_key} expected is #{region_key}"
34
+ assert_equal adm2, expected_adm2, "#{expected_adm2} expected is #{adm2}"
35
+ end
36
+ assert found, "no match for '#{name}'"
37
+ end
38
+ end
39
+
40
+ end # class TestFixtureMatcherAdm3
41
+
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_read_adm.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestReadAdm < MiniTest::Test
11
+
12
+ def setup
13
+ # delete all countries, regions, 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/adm' )
26
+
27
+ ###
28
+ ## todo/fix: shorten level to l -- why, why not???
29
+ assert_equal 9, at.regions.where(level:1).count
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/adm' )
42
+
43
+
44
+ ###
45
+ ## todo/fix: shorten level to l -- why, why not???
46
+
47
+ assert_equal 16, de.regions.where(level:1).count
48
+ ## assert_equal 16+??, de.regions.count
49
+
50
+ by = Region.find_by_key!( 'by' )
51
+ assert_equal 7, by.regions.where(level:2).count
52
+ ## assert_equal 7+??, by.regions.count
53
+
54
+ ## pp by.regions
55
+
56
+ ob = Region.find_by_key!( 'ob' )
57
+ assert_equal 'Oberbayern', ob.name
58
+ assert_equal 23, ob.regions.where(level:3).count
59
+ assert_equal 23, ob.regions.count
60
+
61
+ ofr = Region.find_by_key!( 'ofr' )
62
+ assert_equal 'Oberfranken', ofr.name
63
+ assert_equal 13, ofr.regions.where(level:3).count
64
+ assert_equal 13, ofr.regions.count
65
+ end
66
+
67
+ end # class TestReadAdm
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-06 00:00:00.000000000 Z
11
+ date: 2015-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -210,7 +210,19 @@ files:
210
210
  - lib/worlddb/schema.rb
211
211
  - lib/worlddb/stats.rb
212
212
  - lib/worlddb/version.rb
213
+ - test/data/at-austria/1--b-burgenland/counties.txt
214
+ - test/data/at-austria/2--n-niederoesterreich/counties.txt
215
+ - test/data/at-austria/3--w-wien/counties.txt
216
+ - test/data/at-austria/setups/adm.txt
217
+ - test/data/at-austria/states.txt
218
+ - test/data/de-deutschland/3--by-bayern/1--oberbayern/counties.txt
219
+ - test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt
220
+ - test/data/de-deutschland/3--by-bayern/districts.txt
221
+ - test/data/de-deutschland/setups/adm.txt
222
+ - test/data/de-deutschland/states.txt
213
223
  - test/helper.rb
224
+ - test/test_fixture_matcher_adm2.rb
225
+ - test/test_fixture_matcher_adm3.rb
214
226
  - test/test_fixture_matchers.rb
215
227
  - test/test_fixture_matchers_ii.rb
216
228
  - test/test_model_city.rb
@@ -218,6 +230,7 @@ files:
218
230
  - test/test_model_country.rb
219
231
  - test/test_model_region.rb
220
232
  - test/test_models.rb
233
+ - test/test_read_adm.rb
221
234
  homepage: https://github.com/worlddb/world.db.models
222
235
  licenses:
223
236
  - Public Domain
@@ -247,8 +260,11 @@ summary: worlddb - world.db schema 'n' models for easy (re)use
247
260
  test_files:
248
261
  - test/test_model_comp.rb
249
262
  - test/test_models.rb
263
+ - test/test_read_adm.rb
250
264
  - test/test_model_city.rb
251
265
  - test/test_fixture_matchers.rb
252
266
  - test/test_model_country.rb
253
267
  - test/test_model_region.rb
268
+ - test/test_fixture_matcher_adm2.rb
269
+ - test/test_fixture_matcher_adm3.rb
254
270
  - test/test_fixture_matchers_ii.rb