worlddb-models 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +31 -13
  3. data/README.md +7 -7
  4. data/Rakefile +1 -1
  5. data/lib/worlddb/deleter.rb +6 -1
  6. data/lib/worlddb/helpers/value_helper.rb +117 -0
  7. data/lib/worlddb/matcher.rb +99 -135
  8. data/lib/worlddb/matcher_adm.rb +82 -0
  9. data/lib/worlddb/models/city.rb +30 -208
  10. data/lib/worlddb/models/city_base.rb +220 -0
  11. data/lib/worlddb/models/continent.rb +9 -0
  12. data/lib/worlddb/models/country.rb +21 -4
  13. data/lib/worlddb/models/forward.rb +25 -9
  14. data/lib/worlddb/models/lang.rb +6 -0
  15. data/lib/worlddb/models/place.rb +1 -1
  16. data/lib/worlddb/models/state.rb +83 -0
  17. data/lib/worlddb/models/{region.rb → state_base.rb} +52 -36
  18. data/lib/worlddb/models/tagdb/tag.rb +1 -1
  19. data/lib/worlddb/models.rb +11 -8
  20. data/lib/worlddb/patterns.rb +4 -4
  21. data/lib/worlddb/reader.rb +68 -39
  22. data/lib/worlddb/reader_file.rb +36 -3
  23. data/lib/worlddb/reader_zip.rb +33 -3
  24. data/lib/worlddb/readers/base.rb +149 -0
  25. data/lib/worlddb/readers/city.rb +2 -65
  26. data/lib/worlddb/readers/country.rb +2 -63
  27. data/lib/worlddb/readers/lang.rb +3 -68
  28. data/lib/worlddb/readers/state.rb +61 -0
  29. data/lib/worlddb/readers/state_tree.rb +118 -0
  30. data/lib/worlddb/readers/usage.rb +2 -65
  31. data/lib/worlddb/schema.rb +142 -43
  32. data/lib/worlddb/stats.rb +7 -4
  33. data/lib/worlddb/tree_reader.rb +97 -0
  34. data/lib/worlddb/version.rb +2 -2
  35. data/test/adm/test_fixture_matcher_adm2.rb +73 -0
  36. data/test/{test_fixture_matcher_adm3.rb → adm/test_fixture_matcher_adm3.rb} +6 -6
  37. data/test/adm/test_fixture_matcher_tree.rb +52 -0
  38. data/test/{test_read_adm.rb → adm/test_read_adm.rb} +13 -20
  39. data/test/adm/test_read_tree.rb +63 -0
  40. data/test/data/at-austria/2--n-niederoesterreich/counties.txt +6 -4
  41. data/test/data/at-austria/orte.txt +23 -0
  42. data/test/data/at-austria/setups/tree.txt +9 -0
  43. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt +14 -13
  44. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt +104 -0
  45. data/test/data/de-deutschland/3--by-bayern/4--oberfranken/orte_ii.txt +17 -0
  46. data/test/data/de-deutschland/3--by-bayern/{districts.txt → parts.txt} +1 -1
  47. data/test/data/de-deutschland/orte.txt +12 -0
  48. data/test/data/de-deutschland/setups/adm.txt +1 -1
  49. data/test/data/de-deutschland/setups/tree.txt +9 -0
  50. data/test/helper.rb +8 -1
  51. data/test/test_fixture_matchers.rb +9 -10
  52. data/test/test_fixture_matchers_ii.rb +20 -19
  53. data/test/test_model_city.rb +26 -9
  54. data/test/{test_model_comp.rb → test_model_compat.rb} +15 -13
  55. data/test/test_model_country.rb +1 -1
  56. data/test/test_model_state.rb +54 -0
  57. data/test/test_model_states_at.rb +111 -0
  58. data/test/test_model_states_de.rb +147 -0
  59. data/test/test_models.rb +10 -3
  60. data/test/test_parse_city.rb +70 -0
  61. data/test/test_parse_country.rb +56 -0
  62. data/test/test_parse_state.rb +46 -0
  63. data/test/test_state_tree_reader_at.rb +54 -0
  64. data/test/test_state_tree_reader_de.rb +71 -0
  65. data/test/test_tree_reader.rb +39 -0
  66. metadata +50 -22
  67. data/lib/worlddb/models/city_compat.rb +0 -27
  68. data/lib/worlddb/models/continent_compat.rb +0 -24
  69. data/lib/worlddb/models/country_compat.rb +0 -35
  70. data/lib/worlddb/models/lang_compat.rb +0 -23
  71. data/lib/worlddb/models/region_compat.rb +0 -26
  72. data/lib/worlddb/readers/region.rb +0 -79
  73. data/test/test_fixture_matcher_adm2.rb +0 -62
  74. data/test/test_model_region.rb +0 -50
@@ -7,8 +7,9 @@
7
7
  ## ?? Gemeinden
8
8
  ## ?? Ortschaften
9
9
 
10
- Krems an der Donau, 52 km², 24_085 # KS
11
- St. Pölten, 108 km², 52_145 # P
10
+ ks, Krems an der Donau (Stadt), 52 km², 24_085 # KS
11
+ p, St. Pölten (Stadt), 108 km², 52_145 # P
12
+
12
13
  Waidhofen an der Ybbs, 132 km², 11_341 # WY
13
14
  Wiener Neustadt, 61 km², 42_273 # WN
14
15
  Amstetten, 1188 km², 112_944 # AM
@@ -19,13 +20,14 @@ Gmünd, 786 km², 37_420 # GD
19
20
  Hollabrunn, 1011 km², 50_065 # HL
20
21
  Horn, 784 km², 31_273 # HO
21
22
  Korneuburg, 627 km², 76_370 # KO
22
- Krems-Land (Krems an der Donau), 924 km², 55_945 # KR
23
+
24
+ kr, Krems-Land (Krems an der Donau), 924 km², 55_945 # KR
23
25
  Lilienfeld, 932 km², 26_040 # LF
24
26
  Melk, 1014 km², 76_369 # ME
25
27
  Mistelbach, 1291 km², 74_150 # MI
26
28
  Mödling, 277 km², 115_677 # MD
27
29
  Neunkirchen, 1146 km², 85_539 # NK
28
- St. Pölten-Land (St. Pölten), 1122 km², 97_365 # PL
30
+ pl, St. Pölten-Land (St. Pölten), 1122 km², 97_365 # PL
29
31
  Scheibbs, 1023 km², 41_073 # SB
30
32
  Tulln (Tulln an der Donau), 658 km², 72_104 # TU
31
33
  Waidhofen an der Thaya, 669 km², 26_424 # WT
@@ -0,0 +1,23 @@
1
+ 3 Niederösterreich
2
+ 301 .. Krems an der Donau (Stadt)
3
+ 30101 .... Krems an der Donau ## SS; 3500; 3506 3541
4
+ 03148 ...... Gneixendorf ## 3500
5
+ 03149 ...... Krems an der Donau ## 3500 3506
6
+ 03150 ...... Landersdorf ## 3500
7
+ 03151 ...... Lerchenfeld ## 3500
8
+ 03152 ...... Rehberg ## 3500 3541
9
+ 03153 ...... Stein an der Donau ## 3500
10
+ 04164 ...... Egelsee ## 3500
11
+ 04165 ...... Scheibenhof ## 3500
12
+ 04237 ...... Angern ## 3506
13
+ 04238 ...... Brunnkirchen ## 3506
14
+ 04239 ...... Hollenburg ## 3506
15
+ 04240 ...... Thallern ## 3506
16
+ 302 .. St. Pölten (Stadt)
17
+ 30201 .... St. Pölten ## SS; 3100; 3104 3105 3107 3140 3151 3385
18
+ 03154 ...... Harland ## 3100 3104
19
+ 03155 ...... Oberradlberg ## 3105
20
+ 03156 ...... Oberwagram ## 3100
21
+ 03157 ...... Ragelsdorf ## 3107
22
+ 03158 ...... St. Pölten ## 3100 3104 3107 3151
23
+ 03159 ...... Spratzern ## 3100 3151
@@ -0,0 +1,9 @@
1
+
2
+ # note: same as admin plus tree (orte.txt)
3
+
4
+ at-austria!/states
5
+ at-austria!/1--b-burgenland/counties
6
+ at-austria!/2--n-niederoesterreich/counties
7
+ at-austria!/3--w-wien/counties
8
+
9
+ at-austria!/orte
@@ -20,23 +20,24 @@
20
20
 
21
21
  # 4 kreisfreie Städte und
22
22
 
23
- Bamberg (Kreisfreie Stadt)
24
- Bayreuth (Kreisfreie Stadt)
25
- Coburg (Kreisfreie Stadt)
26
- Hof (Kreisfreie Stadt)
23
+ ba, Bamberg (Stadt)
24
+ bt, Bayreuth (Stadt)
25
+ co, Coburg (Stadt)
26
+ ho, Hof (Stadt)
27
27
 
28
28
 
29
29
  # 9 Landkreise
30
30
  ## how to deal w/ same name?? (same keys)
31
31
  ## - use bambergland, bayreuthland etc. for key ??
32
32
 
33
- Bamberg-Landkreis ## (Landkreis)
34
- Bayreuth-Landkreis ## (Landkreis)
35
- Coburg-Landkreis ## (Landkreis)
36
- Hof-Landkreis ## (Landkreis)
33
+ baland, Bamberg (Land) ## (Landkreis)
34
+ btland, Bayreuth (Land) ## (Landkreis)
35
+ coland, Coburg (Land) ## (Landkreis)
36
+ holand, Hof (Land) ## (Landkreis)
37
+
38
+ fo, Forchheim ## Landkreis
39
+ kc, Kronach ## Landkreis
40
+ ku, Kulmbach ## Landkreis
41
+ lif, Lichtenfels ## Landkreis
42
+ wun, Wunsiedel i. Fichtelgebirge ## Landkreis
37
43
 
38
- Forchheim (Landkreis)
39
- Kronach (Landkreis)
40
- Kulmbach (Landkreis)
41
- Lichtenfels (Landkreis)
42
- Wunsiedel im Fichtelgebirge (Landkreis)
@@ -0,0 +1,104 @@
1
+ 2 Bayern
2
+ 24 .. Oberfranken
3
+ 241 .... Bamberg (Stadt) ## Kreisfreie Stadt
4
+ ...... Bamberg
5
+ ........ Bamberg
6
+ 242 .... Bayreuth (Stadt) ## Kreisfreie Stadt
7
+ ...... Bayreuth
8
+ ........ Bayreuth
9
+ 243 .... Coburg (Stadt) ## Kreisfreie Stadt
10
+ ...... Coburg
11
+ ........ Coburg
12
+ 244 .... Hof (Stadt) ## Kreisfreie Stadt
13
+ ...... Hof
14
+ ........ Hof
15
+
16
+ 245 .... Bamberg (Land) ## Landkreis -- 36 Gemeinden; see de.wikipedia.org/wiki/Landkreis_Bamberg
17
+ ## 4 Städte
18
+ ...... Baunach ## (4013, 30,9 km²)
19
+ ........ Baunach
20
+ ...... Hallstadt ## (8364, 14,5 km²)
21
+ ........ Hallstadt ## (7588)
22
+ ........ Dörfleins ## (1380)
23
+ ...... Scheßlitz ## (7184, 94,9 km²)
24
+ ........ Scheßlitz
25
+ ........ Köttensdorf
26
+ ........ Würgau
27
+ ...... Schlüsselfeld ## (5712, 70,2 km²)
28
+
29
+ ## 8 Märkte
30
+ ...... Burgebrach ## (6553, 87,9 km²)
31
+ ...... Burgwindheim ## (1311, 37,4 km²)
32
+ ...... Buttenheim ## (3472, 30 km²)
33
+ ...... Ebrach ## (1830, 29,6 km²)
34
+ ...... Heiligenstadt i. OFr. ## (3525, 76,7 km²)
35
+ ........ Heiligenstadt i. OFr.
36
+ ........ Oberleinleiter
37
+ ...... Hirschaid ## (11.919, 41 km²)
38
+ ...... Rattelsdorf ## (4568, 39,6 km²)
39
+ ........ Rattelsdorf
40
+ ........ Mürsbach
41
+ ........ Freudeneck
42
+ ........ Höfen
43
+ ........ Ebing
44
+ ...... Zapfendorf ## (4954, 30,6 km²)
45
+
46
+ ## 24 Gemeinden
47
+ ...... Altendorf ## (2012, 8,6 km²)
48
+ ...... Bischberg ## (6012, 17,5 km²)
49
+ ...... Breitengüßbach ## (4586, 16,9 km²)
50
+ ........ Breitengüßbach
51
+ ...... Frensdorf ## (4865, 44 km²)
52
+ ...... Gerach ## (946, 7,8 km²)
53
+ ...... Gundelsheim ## (3378, 3,8 km²)
54
+ ...... Kemmern ## (2544, 8,3 km²)
55
+ ........ Kemmern
56
+ ...... Königsfeld ## (1335, 42,7 km²)
57
+ ........ Königsfeld
58
+ ........ Huppendorf
59
+ ...... Lauter ## (1139, 12,8 km²)
60
+ ........ Lauter ## (601)
61
+ ........ Appendorf ## (213)
62
+ ...... Lisberg ## (1813, 8,4 km²)
63
+ ...... Litzendorf ## (6057, 25,9 km²)
64
+ ........ Litzendorf
65
+ ........ Schammelsdorf
66
+ ........ Melkendorf
67
+ ........ Lohndorf
68
+ ........ Tiefenellern
69
+ ...... Memmelsdorf ## (8854, 26,2 km²)
70
+ ........ Memmelsdorf
71
+ ........ Merkendorf
72
+ ........ Drosendorf
73
+ ...... Oberhaid ## (4590, 27,2 km²)
74
+ ........ Oberhaid
75
+ ........ Staffelbach
76
+ ...... Pettstadt ## (1940, 9,9 km²)
77
+ ...... Pommersfelden ## (2851, 35,7 km²)
78
+ ...... Priesendorf ## (1470, 8,4 km²)
79
+ ...... Reckendorf ## (2033, 13,1 km²)
80
+ ........ Reckendorf
81
+ ...... Schönbrunn im Steigerwald ## (1880, 24,7 km²)
82
+ ...... Stadelhofen ## (1250, 41 km²)
83
+ ........ Stadelhofen
84
+ ........ Steinfeld
85
+ ........ Schederndorf
86
+ ...... Stegaurach ## (6842, 23,9 km²)
87
+ ...... Strullendorf ## (7807, 31,7 km²)
88
+ ........ Strullendorf
89
+ ........ Geisfeld
90
+ ........ Roßdorf am Forst
91
+ ...... Viereth-Trunstadt ## (3562, 15,8 km²)
92
+ ...... Walsdorf ## (2575, 16,2 km²)
93
+ ...... Wattendorf ## (679, 22,2 km²)
94
+ ........ Wattendorf
95
+
96
+ 246 .... Bayreuth (Land) ## Landkreis
97
+ 247 .... Coburg (Land) ## Landkreis
98
+ 248 .... Forchheim
99
+ 249 .... Hof (Land) ## Landkreis
100
+ 24A .... Kronach
101
+ 24B .... Kulmbach
102
+ 24C .... Lichtenfels
103
+ 24D .... Wunsiedel i. Fichtelgebirge
104
+
@@ -0,0 +1,17 @@
1
+ 2 Bayern
2
+ 24 .. Oberfranken
3
+ 241 .... Bamberg (Stadt) ## Kreisfreie Stadt
4
+ ...... Bamberg
5
+ ........ Bamberg
6
+ 242 .... Bayreuth (Stadt) ## Kreisfreie Stadt
7
+ ...... Bayreuth
8
+ ........ Bayreuth
9
+
10
+ 245 .... Bamberg (Land) ## Landkreis -- 36 Gemeinden; see de.wikipedia.org/wiki/Landkreis_Bamberg
11
+ ## 4 Städte
12
+ ...... Baunach ## (4013, 30,9 km²)
13
+ ........ Baunach
14
+ ...... Hallstadt ## (8364, 14,5 km²)
15
+ ........ Hallstadt ## (7588)
16
+ ........ Dörfleins ## (1380)
17
+
@@ -1,7 +1,7 @@
1
1
  ########################################
2
2
  # Bayern
3
3
  #
4
- # 7 Regierungsbezirke (administrative districts or governmental districts - use unit/division?)
4
+ # 7 Regierungsbezirke (administrative districts or governmental districts)
5
5
 
6
6
  ob, Oberbayern, München, 17_530 km² # 091 OB
7
7
  nb, Niederbayern, Landshut, 10_329 km² # 092 NB
@@ -0,0 +1,12 @@
1
+ 2 Bayern
2
+ 24 .. Oberfranken
3
+ 241 .... Bamberg (Stadt) ## Kreisfreie Stadt
4
+ ...... Bamberg
5
+ ........ Bamberg
6
+
7
+ #####
8
+ # todo: for testing add berlin and some more
9
+
10
+ 9 Berlin
11
+ 91 .. Berlin
12
+
@@ -3,6 +3,6 @@
3
3
 
4
4
 
5
5
  de-deutschland!/states
6
- de-deutschland!/3--by-bayern/districts
6
+ de-deutschland!/3--by-bayern/parts
7
7
  de-deutschland!/3--by-bayern/1--oberbayern/counties
8
8
  de-deutschland!/3--by-bayern/4--oberfranken/counties
@@ -0,0 +1,9 @@
1
+
2
+ # note: same as admin plus tree (orte.txt)
3
+
4
+ de-deutschland!/states
5
+ de-deutschland!/3--by-bayern/parts
6
+ de-deutschland!/3--by-bayern/1--oberbayern/counties
7
+ de-deutschland!/3--by-bayern/4--oberfranken/counties
8
+
9
+ de-deutschland!/3--by-bayern/4--oberfranken/orte
data/test/helper.rb CHANGED
@@ -14,8 +14,15 @@ Name = WorldDb::Model::Name
14
14
  Place = WorldDb::Model::Place
15
15
  Continent = WorldDb::Model::Continent
16
16
  Country = WorldDb::Model::Country
17
- Region = WorldDb::Model::Region
17
+
18
+ State = WorldDb::Model::State
19
+ Part = WorldDb::Model::Part
20
+ County = WorldDb::Model::County
21
+ Muni = WorldDb::Model::Muni
22
+
23
+ Metro = WorldDb::Model::Metro
18
24
  City = WorldDb::Model::City
25
+ District = WorldDb::Model::District
19
26
 
20
27
  Lang = WorldDb::Model::Lang
21
28
  Usage = WorldDb::Model::Usage
@@ -16,7 +16,7 @@ class TestFixtureMatchers < MiniTest::Test
16
16
  'at-austria/cities',
17
17
  'at-austria!/cities',
18
18
  'at-austria!/1--niederoesterreich--eastern--cities',
19
- 'at-austria!/1--niederoesterreich--eastern/cities', # region w/o code/abbrev
19
+ 'at-austria!/1--niederoesterreich--eastern/cities', # state w/o code/abbrev
20
20
  'at-austria!/1--niederoesterreich--eastern/1--waldviertel--cities'
21
21
  ]
22
22
 
@@ -41,7 +41,7 @@ class TestFixtureMatchers < MiniTest::Test
41
41
  'europe/1--at-austria--central/beers',
42
42
  'europe/1--at-austria--central/1--niederosterreich--eastern--beers',
43
43
  'at-austria!/1--niederoesterreich--eastern--beers',
44
- 'at-austria!/1--niederoesterreich--eastern/beers', # region w/o code/abbrev
44
+ 'at-austria!/1--niederoesterreich--eastern/beers', # state w/o code/abbrev
45
45
  'at-austria!/1--niederoesterreich--eastern/1--waldviertel--beers'
46
46
  ]
47
47
 
@@ -68,7 +68,7 @@ class TestFixtureMatchers < MiniTest::Test
68
68
  end # method test_country
69
69
 
70
70
 
71
- def test_country_n_region
71
+ def test_country_n_state
72
72
 
73
73
  beers_at = [
74
74
  'europe/at-austria/w-wien/beers',
@@ -86,9 +86,9 @@ class TestFixtureMatchers < MiniTest::Test
86
86
  ]
87
87
 
88
88
  beers_at.each do |name|
89
- found = match_xxx_for_country_n_region( name, 'beers' ) do |country_key,region_key|
89
+ found = match_xxx_for_country_n_state( name, 'beers' ) do |country_key,state_key|
90
90
  assert_equal country_key, 'at'
91
- assert_equal region_key, 'w'
91
+ assert_equal state_key, 'w'
92
92
  end
93
93
  assert found
94
94
  end
@@ -100,13 +100,12 @@ class TestFixtureMatchers < MiniTest::Test
100
100
  ]
101
101
 
102
102
  breweries_at.each do |name|
103
- found = match_xxx_for_country_n_region( name, 'breweries' ) do |country_key,region_key|
103
+ found = match_xxx_for_country_n_state( name, 'breweries' ) do |country_key,state_key|
104
104
  assert_equal country_key, 'at'
105
- assert_equal region_key, 'w'
105
+ assert_equal state_key, 'w'
106
106
  end
107
107
  assert found
108
108
  end
109
- end # method test_country_n_region
109
+ end # method test_country_n_state
110
110
 
111
-
112
- end # class TestFixtureMatchers
111
+ end # class TestFixtureMatchers
@@ -12,7 +12,7 @@ class TestFixtureMatchersII < MiniTest::Test
12
12
 
13
13
  include WorldDb::Matcher
14
14
 
15
- def test_country_n_region_breweries_franken
15
+ def test_country_n_state_breweries_franken
16
16
  breweries_franken = [
17
17
  'de-deutschland/by-bayern/franken!/1--oberfranken/100_000+_breweries',
18
18
  'de-deutschland/by-bayern/franken!/1--oberfranken/20_000+-breweries',
@@ -28,10 +28,10 @@ class TestFixtureMatchersII < MiniTest::Test
28
28
  'de-deutschland/by-bayern/franken!/3--unterfranken/breweries_100_000+',
29
29
  'de-deutschland/by-bayern/franken!/3--unterfranken/breweries_20_000+',
30
30
  ]
31
- assert_match_xxx_for_country_n_region( breweries_franken, 'breweries', 'de', 'by' )
32
- end # method test_country_n_region_breweries
31
+ assert_match_xxx_for_country_n_state( breweries_franken, 'breweries', 'de', 'by' )
32
+ end # method test_country_n_state_breweries
33
33
 
34
- def test_country_n_region_breweries_bayern
34
+ def test_country_n_state_breweries_bayern
35
35
  breweries_bayern = [
36
36
  'de-deutschland/3--by-bayern!/1--oberbayern/breweries_(l)',
37
37
  'de-deutschland/3--by-bayern!/1--oberbayern/breweries_(m)',
@@ -46,29 +46,29 @@ class TestFixtureMatchersII < MiniTest::Test
46
46
  'de-deutschland/3--by-bayern!/4--schwaben/breweries_100_000+',
47
47
  'de-deutschland/3--by-bayern!/4--schwaben/breweries_20_000+',
48
48
  ]
49
- assert_match_xxx_for_country_n_region( breweries_bayern, 'breweries', 'de', 'by' )
50
- end # method test_country_n_region_breweries
49
+ assert_match_xxx_for_country_n_state( breweries_bayern, 'breweries', 'de', 'by' )
50
+ end # method test_country_n_state_breweries
51
51
 
52
52
 
53
- def test_country_n_region_brewpubs_franken
53
+ def test_country_n_state_brewpubs_franken
54
54
  brewpubs_franken = [
55
55
  'de-deutschland/by-bayern/franken!/3--unterfranken/brewpubs',
56
56
  ]
57
- assert_match_xxx_for_country_n_region( brewpubs_franken, 'brewpubs', 'de', 'by' )
57
+ assert_match_xxx_for_country_n_state( brewpubs_franken, 'brewpubs', 'de', 'by' )
58
58
  end
59
59
 
60
- def test_country_n_region_brewpubs_bayern
60
+ def test_country_n_state_brewpubs_bayern
61
61
  brewpubs_bayern = [
62
62
  'de-deutschland/3--by-bayern!/1--oberbayern/brewpubs',
63
63
  'de-deutschland/3--by-bayern!/2--niederbayern/brewpubs',
64
64
  'de-deutschland/3--by-bayern!/3--oberpfalz/brewpubs',
65
65
  'de-deutschland/3--by-bayern!/4--schwaben/brewpubs',
66
66
  ]
67
- assert_match_xxx_for_country_n_region( brewpubs_bayern, 'brewpubs', 'de', 'by' )
67
+ assert_match_xxx_for_country_n_state( brewpubs_bayern, 'brewpubs', 'de', 'by' )
68
68
  end
69
69
 
70
70
 
71
- def test_country_n_region_beers_franken
71
+ def test_country_n_state_beers_franken
72
72
  beers_franken = [
73
73
  'de-deutschland/by-bayern/franken!/1--oberfranken/100_000+_beers',
74
74
  'de-deutschland/by-bayern/franken!/1--oberfranken/beers',
@@ -76,10 +76,10 @@ class TestFixtureMatchersII < MiniTest::Test
76
76
  'de-deutschland/by-bayern/franken!/1--oberfranken/steigerwald-bamberg--beers',
77
77
  'de-deutschland/by-bayern/franken!/3--unterfranken/beers_100_000+',
78
78
  ]
79
- assert_match_xxx_for_country_n_region( beers_franken, 'beers', 'de', 'by' )
80
- end # method test_country_n_region_beers
79
+ assert_match_xxx_for_country_n_state( beers_franken, 'beers', 'de', 'by' )
80
+ end # method test_country_n_state_beers
81
81
 
82
- def test_country_n_region_beers_bayern
82
+ def test_country_n_state_beers_bayern
83
83
  beers_bayern = [
84
84
  'de-deutschland/3--by-bayern!/1--oberbayern/beers--muenchen',
85
85
  'de-deutschland/3--by-bayern!/1--oberbayern/beers_l',
@@ -91,19 +91,20 @@ class TestFixtureMatchersII < MiniTest::Test
91
91
  'de-deutschland/3--by-bayern!/3--oberpfalz/beers_100_000+',
92
92
  'de-deutschland/3--by-bayern!/4--schwaben/beers_100_000+',
93
93
  ]
94
- assert_match_xxx_for_country_n_region( beers_bayern, 'beers', 'de', 'by' )
95
- end # method test_country_n_region_beers
94
+ assert_match_xxx_for_country_n_state( beers_bayern, 'beers', 'de', 'by' )
95
+ end # method test_country_n_state_beers
96
96
 
97
97
 
98
98
  private
99
- def assert_match_xxx_for_country_n_region( ary, xxx, expected_country_key, expected_region_key )
99
+ def assert_match_xxx_for_country_n_state( ary, xxx, expected_country_key, expected_state_key )
100
100
  ary.each do |name|
101
- found = match_xxx_for_country_n_region( name, xxx ) do |country_key,region_key|
101
+ found = match_xxx_for_country_n_state( name, xxx ) do |country_key,state_key|
102
102
  assert_equal country_key, expected_country_key, "#{expected_country_key} expected is #{country_key}"
103
- assert_equal region_key, expected_region_key, "#{expected_region_key} expected is #{region_key}"
103
+ assert_equal state_key, expected_state_key, "#{expected_state_key} expected is #{state_key}"
104
104
  end
105
105
  assert found, "no match for '#{name}'"
106
106
  end
107
107
  end
108
108
 
109
109
  end # class TestFixtureMatchersII
110
+
@@ -1,12 +1,15 @@
1
1
  # encoding: utf-8
2
2
 
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_model_city.rb
3
6
 
4
7
  require 'helper'
5
8
 
6
9
  class TestModelCity < MiniTest::Test
7
10
 
8
11
  def setup
9
- # delete all countries, regions, cities in in-memory only db
12
+ # delete all countries, states, cities in in-memory only db
10
13
  WorldDb.delete!
11
14
  end
12
15
 
@@ -18,7 +21,7 @@ class TestModelCity < MiniTest::Test
18
21
  pop: 8_414_638,
19
22
  area: 83_871 )
20
23
 
21
- w = Region.create!( key: 'w',
24
+ w = State.create!( key: 'w',
22
25
  name: 'Wien',
23
26
  country_id: at.id )
24
27
 
@@ -42,19 +45,33 @@ class TestModelCity < MiniTest::Test
42
45
 
43
46
  assert_equal new_attributes[:name], c.name
44
47
  assert_equal 1_731_236, c.pop
45
- assert_equal 1_724_000, c.popm
46
- assert_equal true, c.m
47
- assert_equal w.id, c.region_id
48
+ assert_equal w.id, c.state_id
48
49
  assert_equal at.id, c.country_id
49
-
50
+
50
51
  ### test place
51
52
  assert_equal new_attributes[:name], c.place.name
52
53
 
53
54
  ## test assocs
54
- assert_equal 'Wien', c.region.name
55
- assert_equal 'Austria', c.region.country.name
55
+ assert_equal 'Wien', c.state.name
56
+ assert_equal 'Austria', c.state.country.name
56
57
  assert_equal 'Austria', c.country.name
57
- end
58
58
 
59
59
 
60
+ #####
61
+ # check (auto-)added metro record
62
+
63
+ m = Metro.find_by_key!( new_attributes[:key] )
64
+ assert_equal new_attributes[:name], m.name
65
+ assert_equal 1_724_000, m.pop
66
+ assert_equal at.id, m.country_id
67
+
68
+ ## test assocs
69
+ assert_equal 1, m.cities.count
70
+ assert_equal 'Wien', m.cities.first.name
71
+ assert_equal 'Austria', m.country.name
72
+
73
+ assert_equal 'Wien', c.metro.name
74
+ assert_equal m.id, c.metro.id
75
+ end
76
+
60
77
  end # class TestModelCity
@@ -3,46 +3,48 @@
3
3
 
4
4
  require 'helper'
5
5
 
6
- class TestModelComp < MiniTest::Test
6
+ class TestModelCompat < MiniTest::Test
7
7
 
8
8
  def setup
9
- # delete all countries, regions, cities in in-memory only db
9
+ # delete all countries, states, cities in in-memory only db
10
10
  WorldDb.delete!
11
11
  end
12
12
 
13
13
 
14
14
  def test_title
15
+
16
+ ## todo: change :name to :title -- why? why not??
17
+
15
18
  at = Country.create!( key: 'at',
16
- title: 'Austria',
19
+ name: 'Austria',
17
20
  code: 'AUT',
18
21
  pop: 8_414_638,
19
22
  area: 83_871 )
20
23
 
21
- w = Region.create!( key: 'w',
22
- title: 'Wien',
24
+ w = State.create!( key: 'w',
25
+ name: 'Wien',
23
26
  country_id: at.id )
24
27
 
25
28
  new_attributes = {
26
29
  key: 'wien',
27
- title: 'Wien'
30
+ name: 'Wien'
28
31
  }
29
32
 
30
33
  c = City.create!( key: new_attributes[:key],
31
- title: new_attributes[:title], # note: assign "old" title attrib
32
- region_id: w.id,
34
+ name: new_attributes[:name], # note: assign "old" title attrib
35
+ state_id: w.id,
33
36
  country_id: at.id )
34
37
 
35
38
  c2 = City.find_by_key!( new_attributes[:key] )
36
39
  assert_equal c2.id, c.id
37
40
 
38
- assert_equal new_attributes[:title], c.name
39
- assert_equal new_attributes[:title], c.title
41
+ assert_equal new_attributes[:name], c.name
42
+ assert_equal new_attributes[:name], c.title ## todo: move to comapt
40
43
  assert_equal new_attributes[:key], c.key
41
- assert_equal false, c.m
42
- assert_equal w.id, c.region_id
44
+ assert_equal w.id, c.state_id
43
45
  assert_equal at.id, c.country_id
44
46
  end
45
47
 
46
48
 
47
- end # class TestModelComp
49
+ end # class TestModelCompat
48
50
 
@@ -5,7 +5,7 @@ require 'helper'
5
5
  class TestModelCountry < MiniTest::Test
6
6
 
7
7
  def setup
8
- # delete all countries, regions, cities in in-memory only db
8
+ # delete all countries, states, cities in in-memory only db
9
9
  WorldDb.delete!
10
10
  end
11
11
 
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_model_state.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestModelState < 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_load_values
18
+
19
+ at = Country.create!( key: 'at',
20
+ name: 'Austria',
21
+ code: 'AUT',
22
+ pop: 8_414_638,
23
+ area: 83_871 )
24
+
25
+ new_attributes = {
26
+ key: 'w',
27
+ name: 'Wien',
28
+ alt_names: '',
29
+ country_id: at.id
30
+ }
31
+
32
+ values = [
33
+ '415 km²',
34
+ 'eastern austria'
35
+ ]
36
+
37
+ st = State.create_or_update_from_attribs( new_attributes, values )
38
+
39
+ st2 = State.find_by_key!( new_attributes[:key] )
40
+ assert_equal st.id, st2.id
41
+
42
+ assert_equal new_attributes[:name], st.name
43
+ assert_equal 415, st.area
44
+ assert_equal at.id, st.country_id
45
+
46
+ ### test place
47
+ assert_equal new_attributes[:name], st.place.name
48
+
49
+ ## test assocs
50
+ assert_equal 'Austria', st.country.name
51
+ end
52
+
53
+ end # class TestModelState
54
+