worlddb 2.0.9 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +1 -1
  3. data/Manifest.txt +1 -38
  4. data/README.md +0 -67
  5. data/Rakefile +7 -11
  6. data/lib/worlddb.rb +8 -187
  7. data/lib/worlddb/cli/main.rb +3 -8
  8. data/lib/worlddb/{version.rb → cli/version.rb} +9 -7
  9. data/lib/worlddb/console.rb +5 -10
  10. metadata +10 -110
  11. data/.gemtest +0 -0
  12. data/lib/worlddb/deleter.rb +0 -32
  13. data/lib/worlddb/matcher.rb +0 -143
  14. data/lib/worlddb/models/city.rb +0 -240
  15. data/lib/worlddb/models/city_comp.rb +0 -27
  16. data/lib/worlddb/models/continent.rb +0 -41
  17. data/lib/worlddb/models/continent_comp.rb +0 -24
  18. data/lib/worlddb/models/country.rb +0 -328
  19. data/lib/worlddb/models/country_code.rb +0 -41
  20. data/lib/worlddb/models/country_comp.rb +0 -35
  21. data/lib/worlddb/models/forward.rb +0 -57
  22. data/lib/worlddb/models/lang.rb +0 -18
  23. data/lib/worlddb/models/lang_comp.rb +0 -23
  24. data/lib/worlddb/models/name.rb +0 -13
  25. data/lib/worlddb/models/place.rb +0 -16
  26. data/lib/worlddb/models/region.rb +0 -176
  27. data/lib/worlddb/models/region_comp.rb +0 -26
  28. data/lib/worlddb/models/tagdb/tag.rb +0 -16
  29. data/lib/worlddb/models/tagdb/tagging.rb +0 -15
  30. data/lib/worlddb/models/usage.rb +0 -17
  31. data/lib/worlddb/patterns.rb +0 -54
  32. data/lib/worlddb/reader.rb +0 -224
  33. data/lib/worlddb/reader_file.rb +0 -86
  34. data/lib/worlddb/reader_zip.rb +0 -160
  35. data/lib/worlddb/readers/city.rb +0 -81
  36. data/lib/worlddb/readers/country.rb +0 -78
  37. data/lib/worlddb/readers/lang.rb +0 -107
  38. data/lib/worlddb/readers/region.rb +0 -79
  39. data/lib/worlddb/readers/usage.rb +0 -98
  40. data/lib/worlddb/schema.rb +0 -202
  41. data/lib/worlddb/stats.rb +0 -31
  42. data/test/helper.rb +0 -29
  43. data/test/test_fixture_matchers.rb +0 -112
  44. data/test/test_model_city.rb +0 -60
  45. data/test/test_model_comp.rb +0 -48
  46. data/test/test_model_country.rb +0 -53
  47. data/test/test_model_region.rb +0 -50
  48. data/test/test_models.rb +0 -35
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
-
5
- class Stats
6
- include Models
7
-
8
- def tables
9
- puts "Stats:"
10
- puts " #{'%5d' % Continent.count} continents"
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' % Region.count} regions"
13
- puts " #{'%5d' % City.where(m: true).where(c: false).count} metros"
14
- puts " #{'%5d' % City.where(c: true).count} cities (#{City.where(c: true).where(m: true).count} metros)"
15
- puts " #{'%5d' % City.where(d: true).count} districts"
16
- puts " #{'%5d' % Place.count} places"
17
- puts " #{'%5d' % Name.count} names"
18
-
19
- puts " #{'%5d' % Lang.count} langs"
20
- puts " #{'%5d' % Usage.count} usages"
21
-
22
- puts " #{'%5d' % CountryCode.count} (country) codes"
23
-
24
- # puts " #{'%5d' % Tag.count} tags"
25
- # puts " #{'%5d' % Tagging.count} taggings"
26
- end
27
-
28
- end # class Stats
29
-
30
- end # module WorldDb
31
-
@@ -1,29 +0,0 @@
1
-
2
- ## $:.unshift(File.dirname(__FILE__))
3
-
4
- ## minitest setup
5
-
6
- # require 'minitest/unit'
7
- require 'minitest/autorun'
8
-
9
-
10
- # our own code
11
-
12
- require 'worlddb'
13
- require 'logutils/db' # NB: explict require required for LogDb (not automatic)
14
-
15
-
16
- Name = WorldDb::Model::Name
17
- Place = WorldDb::Model::Place
18
- Continent = WorldDb::Model::Continent
19
- Country = WorldDb::Model::Country
20
- Region = WorldDb::Model::Region
21
- City = WorldDb::Model::City
22
-
23
- Lang = WorldDb::Model::Lang
24
- Usage = WorldDb::Model::Usage
25
-
26
-
27
-
28
- WorldDb.setup_in_memory_db
29
-
@@ -1,112 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'helper'
4
-
5
-
6
- class TestFixtureMatchers < MiniTest::Test
7
-
8
- include WorldDb::Matcher
9
-
10
-
11
- def test_cities_for_country
12
-
13
- cities_at = [
14
- 'europe/at/cities',
15
- 'europe/at-austria/cities',
16
- 'at-austria/cities',
17
- 'at-austria!/cities',
18
- 'at-austria!/1--niederoesterreich--eastern--cities',
19
- 'at-austria!/1--niederoesterreich--eastern/cities', # region w/o code/abbrev
20
- 'at-austria!/1--niederoesterreich--eastern/1--waldviertel--cities'
21
- ]
22
-
23
- cities_at.each do |name|
24
- found = match_cities_for_country( name ) do |country_key|
25
- assert_equal country_key, 'at'
26
- end
27
- assert found
28
- end
29
- end # method test_cities_for_country
30
-
31
- def test_country
32
-
33
- beers_at = [
34
- 'europe/at/beers',
35
- 'europe/at-austria/beers',
36
- 'europe/at-austria--beers',
37
- 'at-austria/beers',
38
- 'at-austria!/beers',
39
- '1--at-austria--central/beers',
40
- '1--at-austria--central/1--niederoesterreich--eastern--beers',
41
- 'europe/1--at-austria--central/beers',
42
- 'europe/1--at-austria--central/1--niederosterreich--eastern--beers',
43
- 'at-austria!/1--niederoesterreich--eastern--beers',
44
- 'at-austria!/1--niederoesterreich--eastern/beers', # region w/o code/abbrev
45
- 'at-austria!/1--niederoesterreich--eastern/1--waldviertel--beers'
46
- ]
47
-
48
- beers_at.each do |name|
49
- found = match_xxx_for_country( name, 'beers' ) do |country_key|
50
- assert_equal country_key, 'at'
51
- end
52
- assert found, "no match found for '#{name}'"
53
- end
54
-
55
- breweries_at = [
56
- 'europe/at/breweries',
57
- 'europe/at-austria/breweries',
58
- 'at-austria/breweries',
59
- 'at-austria!/breweries'
60
- ]
61
-
62
- breweries_at.each do |name|
63
- found = match_xxx_for_country( name, 'breweries' ) do |country_key|
64
- assert_equal country_key, 'at'
65
- end
66
- assert found
67
- end
68
- end # method test_country
69
-
70
-
71
- def test_country_n_region
72
-
73
- beers_at = [
74
- 'europe/at-austria/w-wien/beers',
75
- 'at-austria/w-wien/beers',
76
- 'at-austria/w-wien/2--leopoldstadt--beers',
77
- 'at-austria!/w-wien/beers',
78
- '1--at-austria--central/1--w-wien--eastern/beers',
79
- '1--at-austria--central/1--w-wien--eastern/2--leopoldstadt--beers',
80
- 'europe/1--at-austria--central/1--w-wien--eastern/beers',
81
- 'at-austria/1--w-wien--eastern/beers',
82
- 'europe/at-austria!/1--w-wien--eastern/beers',
83
- '1--at-austria--central/w-wien/beers',
84
- 'europe/1--at-austria--central/w-wien/beers',
85
- 'europe/1--at-austria--central/w-wien/2--leopoldstadt--beers'
86
- ]
87
-
88
- beers_at.each do |name|
89
- found = match_xxx_for_country_n_region( name, 'beers' ) do |country_key,region_key|
90
- assert_equal country_key, 'at'
91
- assert_equal region_key, 'w'
92
- end
93
- assert found
94
- end
95
-
96
- breweries_at = [
97
- 'europe/at-austria/w-wien/breweries',
98
- 'at-austria/w-wien/breweries',
99
- 'at-austria!/w-wien/breweries'
100
- ]
101
-
102
- breweries_at.each do |name|
103
- found = match_xxx_for_country_n_region( name, 'breweries' ) do |country_key,region_key|
104
- assert_equal country_key, 'at'
105
- assert_equal region_key, 'w'
106
- end
107
- assert found
108
- end
109
- end # method test_country_n_region
110
-
111
-
112
- end # class TestFixtureMatchers
@@ -1,60 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- require 'helper'
5
-
6
- class TestModelCity < MiniTest::Test
7
-
8
- def setup
9
- # delete all countries, regions, cities in in-memory only db
10
- WorldDb.delete!
11
- end
12
-
13
- def test_load_values
14
-
15
- at = Country.create!( key: 'at',
16
- name: 'Austria',
17
- code: 'AUT',
18
- pop: 8_414_638,
19
- area: 83_871 )
20
-
21
- w = Region.create!( key: 'w',
22
- name: 'Wien',
23
- country_id: at.id )
24
-
25
- new_attributes = {
26
- key: 'wien',
27
- name: 'Wien',
28
- alt_names: '',
29
- country_id: at.id
30
- }
31
-
32
- values = [
33
- 'W',
34
- '1_731_236',
35
- 'm:1_724_000'
36
- ]
37
-
38
- c = City.create_or_update_from_attribs( new_attributes, values )
39
-
40
- c2 = City.find_by_key!( new_attributes[:key] )
41
- assert_equal c2.id, c.id
42
-
43
- assert_equal new_attributes[:name], c.name
44
- 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 at.id, c.country_id
49
-
50
- ### test place
51
- assert_equal new_attributes[:name], c.place.name
52
-
53
- ## test assocs
54
- assert_equal 'Wien', c.region.name
55
- assert_equal 'Austria', c.region.country.name
56
- assert_equal 'Austria', c.country.name
57
- end
58
-
59
-
60
- end # class TestModelCity
@@ -1,48 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- require 'helper'
5
-
6
- class TestModelComp < MiniTest::Test
7
-
8
- def setup
9
- # delete all countries, regions, cities in in-memory only db
10
- WorldDb.delete!
11
- end
12
-
13
-
14
- def test_title
15
- at = Country.create!( key: 'at',
16
- title: 'Austria',
17
- code: 'AUT',
18
- pop: 8_414_638,
19
- area: 83_871 )
20
-
21
- w = Region.create!( key: 'w',
22
- title: 'Wien',
23
- country_id: at.id )
24
-
25
- new_attributes = {
26
- key: 'wien',
27
- title: 'Wien'
28
- }
29
-
30
- c = City.create!( key: new_attributes[:key],
31
- title: new_attributes[:title], # note: assign "old" title attrib
32
- region_id: w.id,
33
- country_id: at.id )
34
-
35
- c2 = City.find_by_key!( new_attributes[:key] )
36
- assert_equal c2.id, c.id
37
-
38
- assert_equal new_attributes[:title], c.name
39
- assert_equal new_attributes[:title], c.title
40
- assert_equal new_attributes[:key], c.key
41
- assert_equal false, c.m
42
- assert_equal w.id, c.region_id
43
- assert_equal at.id, c.country_id
44
- end
45
-
46
-
47
- end # class TestModelComp
48
-
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'helper'
4
-
5
- class TestModelCountry < MiniTest::Test
6
-
7
- def setup
8
- # delete all countries, regions, cities in in-memory only db
9
- WorldDb.delete!
10
- end
11
-
12
- def test_to_path
13
- eu = Continent.create!( key: 'eu', name: 'Europe' )
14
- assert_equal 'europe', eu.slug
15
-
16
- at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', area: 83_871, pop: 8_414_638, continent: eu )
17
- assert_equal 'austria', at.slug
18
-
19
- assert_equal 'europe/at-austria', at.to_path
20
- end
21
-
22
- def test_load_values
23
-
24
- new_attributes = {
25
- key: 'at',
26
- name: 'Austria',
27
- alt_names: ''
28
- }
29
-
30
- values = [
31
- 'AUT',
32
- '83_871',
33
- '8_414_638',
34
- 'un|fifa|uefa|eu|euro|schengen|central_europe|western_europe'
35
- ]
36
-
37
- c = Country.create_or_update_from_attribs( new_attributes, values )
38
-
39
- c2 = Country.find_by_key!( new_attributes[:key] )
40
- assert_equal c.id, c2.id
41
-
42
- assert_equal new_attributes[:name], c.name
43
- assert_equal 8_414_638, c.pop
44
- assert_equal 83_871, c.area
45
- ## todo: assert tag count; add supra:eu etc.
46
-
47
- ### test place
48
- assert_equal new_attributes[:name], c.place.name
49
- end
50
-
51
-
52
- end # class TestModelCountry
53
-
@@ -1,50 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- require 'helper'
5
-
6
- class TestModelRegion < MiniTest::Test
7
-
8
- def setup
9
- # delete all countries, regions, cities in in-memory only db
10
- WorldDb.delete!
11
- end
12
-
13
- def test_load_values
14
-
15
- at = Country.create!( key: 'at',
16
- name: 'Austria',
17
- code: 'AUT',
18
- pop: 8_414_638,
19
- area: 83_871 )
20
-
21
- new_attributes = {
22
- key: 'w',
23
- name: 'Wien',
24
- alt_names: '',
25
- country_id: at.id
26
- }
27
-
28
- values = [
29
- '415 km²',
30
- 'eastern austria'
31
- ]
32
-
33
- r = Region.create_or_update_from_attribs( new_attributes, values )
34
-
35
- r2 = Region.find_by_key!( new_attributes[:key] )
36
- assert_equal r.id, r2.id
37
-
38
- assert_equal new_attributes[:name], r.name
39
- assert_equal 415, r.area
40
- assert_equal at.id, r.country_id
41
-
42
- ### test place
43
- assert_equal new_attributes[:name], r.place.name
44
-
45
- ## test assocs
46
- assert_equal 'Austria', r.country.name
47
- end
48
-
49
- end # class TestModelRegion
50
-
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- require 'helper'
5
-
6
- class TestModels < MiniTest::Test
7
-
8
- def setup
9
- # delete all countries, regions, cities in in-memory only db
10
- WorldDb.delete!
11
- end
12
-
13
- def test_counts
14
- assert_equal 0, Name.count
15
- assert_equal 0, Place.count
16
- assert_equal 0, Continent.count
17
- assert_equal 0, Country.count
18
- assert_equal 0, Region.count
19
- assert_equal 0, City.count
20
-
21
- assert_equal 0, Lang.count
22
- assert_equal 0, Usage.count
23
-
24
- WorldDb.tables
25
- end
26
-
27
- def test_place_assoc_counts
28
- # assert_equal 0, Continent.new.place.count
29
- # assert_equal 0, Country.new.place.count
30
- # assert_equal 0, Region.new.place.count
31
- # assert_equal 0, City.new.place.count
32
- end
33
-
34
- end # class TestModels
35
-