worlddb 1.8.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/{History.md → HISTORY.md} +0 -0
  3. data/Manifest.txt +22 -5
  4. data/README.md +62 -2
  5. data/Rakefile +14 -6
  6. data/lib/worlddb.rb +34 -12
  7. data/lib/worlddb/cli/main.rb +159 -111
  8. data/lib/worlddb/cli/opts.rb +15 -48
  9. data/lib/worlddb/console.rb +6 -5
  10. data/lib/worlddb/deleter.rb +5 -3
  11. data/lib/worlddb/matcher.rb +16 -5
  12. data/lib/worlddb/models/city.rb +66 -30
  13. data/lib/worlddb/models/city_comp.rb +27 -0
  14. data/lib/worlddb/models/continent.rb +30 -8
  15. data/lib/worlddb/models/continent_comp.rb +24 -0
  16. data/lib/worlddb/models/country.rb +60 -36
  17. data/lib/worlddb/models/country_comp.rb +29 -0
  18. data/lib/worlddb/models/forward.rb +53 -0
  19. data/lib/worlddb/models/lang.rb +9 -7
  20. data/lib/worlddb/models/lang_comp.rb +23 -0
  21. data/lib/worlddb/models/name.rb +13 -0
  22. data/lib/worlddb/models/place.rb +16 -0
  23. data/lib/worlddb/models/region.rb +34 -12
  24. data/lib/worlddb/models/region_comp.rb +26 -0
  25. data/lib/worlddb/models/tagdb/tag.rb +16 -0
  26. data/lib/worlddb/models/tagdb/tagging.rb +15 -0
  27. data/lib/worlddb/models/usage.rb +10 -6
  28. data/lib/worlddb/reader.rb +31 -158
  29. data/lib/worlddb/readers/base.rb +41 -0
  30. data/lib/worlddb/readers/city.rb +18 -0
  31. data/lib/worlddb/readers/country.rb +17 -0
  32. data/lib/worlddb/readers/lang.rb +43 -0
  33. data/lib/worlddb/readers/region.rb +17 -0
  34. data/lib/worlddb/readers/usage.rb +35 -0
  35. data/lib/worlddb/schema.rb +100 -65
  36. data/lib/worlddb/stats.rb +9 -3
  37. data/lib/worlddb/utils.rb +3 -0
  38. data/lib/worlddb/version.rb +1 -6
  39. data/test/helper.rb +13 -3
  40. data/test/test_model_city.rb +60 -0
  41. data/test/test_model_comp.rb +48 -0
  42. data/test/test_model_country.rb +43 -0
  43. data/test/test_model_region.rb +50 -0
  44. data/test/test_models.rb +35 -0
  45. metadata +113 -37
  46. data/lib/worlddb/models/prop.rb +0 -32
  47. data/lib/worlddb/models/tag.rb +0 -33
  48. data/lib/worlddb/models/tagging.rb +0 -13
  49. data/test/test_values.rb +0 -114
@@ -24,9 +24,16 @@ require 'active_record'
24
24
  require 'worlddb'
25
25
  require 'logutils/db' # NB: explict require required for LogDb (not automatic)
26
26
 
27
- Country = WorldDb::Model::Country
28
- Region = WorldDb::Model::Region
29
- City = WorldDb::Model::City
27
+
28
+ Name = WorldDb::Model::Name
29
+ Place = WorldDb::Model::Place
30
+ Continent = WorldDb::Model::Continent
31
+ Country = WorldDb::Model::Country
32
+ Region = WorldDb::Model::Region
33
+ City = WorldDb::Model::City
34
+
35
+ Lang = WorldDb::Model::Lang
36
+ Usage = WorldDb::Model::Usage
30
37
 
31
38
 
32
39
  def setup_in_memory_db
@@ -49,6 +56,9 @@ def setup_in_memory_db
49
56
  ## build schema
50
57
 
51
58
  LogDb.create
59
+ ConfDb.create
60
+
61
+ TagDb.create
52
62
  WorldDb.create
53
63
  end
54
64
 
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+ class TestModelCity < MiniTest::Unit::TestCase
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
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+ class TestModelComp < MiniTest::Unit::TestCase
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
+
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ require 'helper'
4
+
5
+ class TestModelCountry < MiniTest::Unit::TestCase
6
+
7
+ def setup
8
+ # delete all countries, regions, cities in in-memory only db
9
+ WorldDb.delete!
10
+ end
11
+
12
+ def test_load_values
13
+
14
+ new_attributes = {
15
+ key: 'at',
16
+ name: 'Austria',
17
+ alt_names: ''
18
+ }
19
+
20
+ values = [
21
+ 'AUT',
22
+ '83_871',
23
+ '8_414_638',
24
+ 'un|fifa|uefa|eu|euro|schengen|central_europe|western_europe'
25
+ ]
26
+
27
+ c = Country.create_or_update_from_attribs( new_attributes, values )
28
+
29
+ c2 = Country.find_by_key!( new_attributes[:key] )
30
+ assert_equal c.id, c2.id
31
+
32
+ assert_equal new_attributes[:name], c.name
33
+ assert_equal 8_414_638, c.pop
34
+ assert_equal 83_871, c.area
35
+ ## todo: assert tag count; add supra:eu etc.
36
+
37
+ ### test place
38
+ assert_equal new_attributes[:name], c.place.name
39
+ end
40
+
41
+
42
+ end # class TestModelCountry
43
+
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+ class TestModelRegion < MiniTest::Unit::TestCase
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
+
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'helper'
5
+
6
+ class TestModels < MiniTest::Unit::TestCase
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
+
metadata CHANGED
@@ -1,82 +1,138 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worlddb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gerald Bauer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-01-18 00:00:00.000000000 Z
11
+ date: 2014-03-22 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: props
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logutils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: textutils
16
- requirement: &21659688 !ruby/object:Gem::Requirement
17
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
18
44
  requirements:
19
- - - ~>
45
+ - - ! '>='
20
46
  - !ruby/object:Gem::Version
21
- version: '0.6'
47
+ version: 0.8.7
22
48
  type: :runtime
23
49
  prerelease: false
24
- version_requirements: *21659688
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.7
25
55
  - !ruby/object:Gem::Dependency
26
- name: commander
27
- requirement: &21659316 !ruby/object:Gem::Requirement
28
- none: false
56
+ name: tagutils
57
+ requirement: !ruby/object:Gem::Requirement
29
58
  requirements:
30
- - - ~>
59
+ - - ! '>='
31
60
  - !ruby/object:Gem::Version
32
- version: 4.1.3
61
+ version: '0'
33
62
  type: :runtime
34
63
  prerelease: false
35
- version_requirements: *21659316
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gli
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '2.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '2.9'
36
83
  - !ruby/object:Gem::Dependency
37
84
  name: activerecord
38
- requirement: &21658944 !ruby/object:Gem::Requirement
39
- none: false
85
+ requirement: !ruby/object:Gem::Requirement
40
86
  requirements:
41
- - - ~>
87
+ - - ! '>='
42
88
  - !ruby/object:Gem::Version
43
- version: '3.2'
89
+ version: '0'
44
90
  type: :runtime
45
91
  prerelease: false
46
- version_requirements: *21658944
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
47
97
  - !ruby/object:Gem::Dependency
48
98
  name: rdoc
49
- requirement: &21658572 !ruby/object:Gem::Requirement
50
- none: false
99
+ requirement: !ruby/object:Gem::Requirement
51
100
  requirements:
52
101
  - - ~>
53
102
  - !ruby/object:Gem::Version
54
103
  version: '4.0'
55
104
  type: :development
56
105
  prerelease: false
57
- version_requirements: *21658572
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '4.0'
58
111
  - !ruby/object:Gem::Dependency
59
112
  name: hoe
60
- requirement: &21658176 !ruby/object:Gem::Requirement
61
- none: false
113
+ requirement: !ruby/object:Gem::Requirement
62
114
  requirements:
63
115
  - - ~>
64
116
  - !ruby/object:Gem::Version
65
- version: '3.7'
117
+ version: '3.6'
66
118
  type: :development
67
119
  prerelease: false
68
- version_requirements: *21658176
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '3.6'
69
125
  description: worlddb - world.db command line tool
70
126
  email: openmundi@googlegroups.com
71
127
  executables:
72
128
  - worlddb
73
129
  extensions: []
74
130
  extra_rdoc_files:
75
- - History.md
131
+ - HISTORY.md
76
132
  - Manifest.txt
77
133
  - README.md
78
134
  files:
79
- - History.md
135
+ - HISTORY.md
80
136
  - Manifest.txt
81
137
  - README.md
82
138
  - Rakefile
@@ -88,26 +144,44 @@ files:
88
144
  - lib/worlddb/deleter.rb
89
145
  - lib/worlddb/matcher.rb
90
146
  - lib/worlddb/models/city.rb
147
+ - lib/worlddb/models/city_comp.rb
91
148
  - lib/worlddb/models/continent.rb
149
+ - lib/worlddb/models/continent_comp.rb
92
150
  - lib/worlddb/models/country.rb
151
+ - lib/worlddb/models/country_comp.rb
152
+ - lib/worlddb/models/forward.rb
93
153
  - lib/worlddb/models/lang.rb
94
- - lib/worlddb/models/prop.rb
154
+ - lib/worlddb/models/lang_comp.rb
155
+ - lib/worlddb/models/name.rb
156
+ - lib/worlddb/models/place.rb
95
157
  - lib/worlddb/models/region.rb
96
- - lib/worlddb/models/tag.rb
97
- - lib/worlddb/models/tagging.rb
158
+ - lib/worlddb/models/region_comp.rb
159
+ - lib/worlddb/models/tagdb/tag.rb
160
+ - lib/worlddb/models/tagdb/tagging.rb
98
161
  - lib/worlddb/models/usage.rb
99
162
  - lib/worlddb/reader.rb
163
+ - lib/worlddb/readers/base.rb
164
+ - lib/worlddb/readers/city.rb
165
+ - lib/worlddb/readers/country.rb
166
+ - lib/worlddb/readers/lang.rb
167
+ - lib/worlddb/readers/region.rb
168
+ - lib/worlddb/readers/usage.rb
100
169
  - lib/worlddb/schema.rb
101
170
  - lib/worlddb/stats.rb
102
171
  - lib/worlddb/utils.rb
103
172
  - lib/worlddb/version.rb
104
173
  - test/helper.rb
105
174
  - test/test_fixture_matchers.rb
106
- - test/test_values.rb
175
+ - test/test_model_city.rb
176
+ - test/test_model_comp.rb
177
+ - test/test_model_country.rb
178
+ - test/test_model_region.rb
179
+ - test/test_models.rb
107
180
  - .gemtest
108
181
  homepage: https://github.com/geraldb/world.db.ruby
109
182
  licenses:
110
183
  - Public Domain
184
+ metadata: {}
111
185
  post_install_message:
112
186
  rdoc_options:
113
187
  - --main
@@ -115,23 +189,25 @@ rdoc_options:
115
189
  require_paths:
116
190
  - lib
117
191
  required_ruby_version: !ruby/object:Gem::Requirement
118
- none: false
119
192
  requirements:
120
193
  - - ! '>='
121
194
  - !ruby/object:Gem::Version
122
195
  version: 1.9.2
123
196
  required_rubygems_version: !ruby/object:Gem::Requirement
124
- none: false
125
197
  requirements:
126
198
  - - ! '>='
127
199
  - !ruby/object:Gem::Version
128
200
  version: '0'
129
201
  requirements: []
130
202
  rubyforge_project: worlddb
131
- rubygems_version: 1.8.16
203
+ rubygems_version: 2.1.10
132
204
  signing_key:
133
- specification_version: 3
205
+ specification_version: 4
134
206
  summary: worlddb - world.db command line tool
135
207
  test_files:
136
208
  - test/test_fixture_matchers.rb
137
- - test/test_values.rb
209
+ - test/test_models.rb
210
+ - test/test_model_city.rb
211
+ - test/test_model_comp.rb
212
+ - test/test_model_country.rb
213
+ - test/test_model_region.rb