worlddb-models 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/HISTORY.md +4 -0
  4. data/Manifest.txt +43 -0
  5. data/README.md +85 -0
  6. data/Rakefile +44 -0
  7. data/lib/worlddb/deleter.rb +32 -0
  8. data/lib/worlddb/matcher.rb +143 -0
  9. data/lib/worlddb/models/city.rb +240 -0
  10. data/lib/worlddb/models/city_comp.rb +27 -0
  11. data/lib/worlddb/models/continent.rb +41 -0
  12. data/lib/worlddb/models/continent_comp.rb +24 -0
  13. data/lib/worlddb/models/country.rb +328 -0
  14. data/lib/worlddb/models/country_code.rb +41 -0
  15. data/lib/worlddb/models/country_comp.rb +35 -0
  16. data/lib/worlddb/models/forward.rb +57 -0
  17. data/lib/worlddb/models/lang.rb +18 -0
  18. data/lib/worlddb/models/lang_comp.rb +23 -0
  19. data/lib/worlddb/models/name.rb +13 -0
  20. data/lib/worlddb/models/place.rb +16 -0
  21. data/lib/worlddb/models/region.rb +176 -0
  22. data/lib/worlddb/models/region_comp.rb +26 -0
  23. data/lib/worlddb/models/tagdb/tag.rb +16 -0
  24. data/lib/worlddb/models/tagdb/tagging.rb +15 -0
  25. data/lib/worlddb/models/usage.rb +17 -0
  26. data/lib/worlddb/models.rb +200 -0
  27. data/lib/worlddb/patterns.rb +54 -0
  28. data/lib/worlddb/reader.rb +224 -0
  29. data/lib/worlddb/reader_file.rb +86 -0
  30. data/lib/worlddb/reader_zip.rb +160 -0
  31. data/lib/worlddb/readers/city.rb +81 -0
  32. data/lib/worlddb/readers/country.rb +78 -0
  33. data/lib/worlddb/readers/lang.rb +107 -0
  34. data/lib/worlddb/readers/region.rb +79 -0
  35. data/lib/worlddb/readers/usage.rb +98 -0
  36. data/lib/worlddb/schema.rb +202 -0
  37. data/lib/worlddb/stats.rb +31 -0
  38. data/lib/worlddb/version.rb +23 -0
  39. data/test/helper.rb +26 -0
  40. data/test/test_fixture_matchers.rb +112 -0
  41. data/test/test_model_city.rb +60 -0
  42. data/test/test_model_comp.rb +48 -0
  43. data/test/test_model_country.rb +53 -0
  44. data/test/test_model_region.rb +50 -0
  45. data/test/test_models.rb +35 -0
  46. metadata +252 -0
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,48 @@
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
+
@@ -0,0 +1,53 @@
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
+
@@ -0,0 +1,50 @@
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
+
@@ -0,0 +1,35 @@
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
+
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: worlddb-models
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 00:00:00.000000000 Z
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: textutils
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.9.9
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.9.9
55
+ - !ruby/object:Gem::Dependency
56
+ name: tagutils
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
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: activerecord-utils
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: props-activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: logutils-activerecord
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubyzip
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activerecord
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rdoc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: hoe
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '3.13'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '3.13'
167
+ description: worlddb - world.db schema & models for easy (re)use
168
+ email: openmundi@googlegroups.com
169
+ executables: []
170
+ extensions: []
171
+ extra_rdoc_files:
172
+ - HISTORY.md
173
+ - Manifest.txt
174
+ - README.md
175
+ files:
176
+ - ".gemtest"
177
+ - HISTORY.md
178
+ - Manifest.txt
179
+ - README.md
180
+ - Rakefile
181
+ - lib/worlddb/deleter.rb
182
+ - lib/worlddb/matcher.rb
183
+ - lib/worlddb/models.rb
184
+ - lib/worlddb/models/city.rb
185
+ - lib/worlddb/models/city_comp.rb
186
+ - lib/worlddb/models/continent.rb
187
+ - lib/worlddb/models/continent_comp.rb
188
+ - lib/worlddb/models/country.rb
189
+ - lib/worlddb/models/country_code.rb
190
+ - lib/worlddb/models/country_comp.rb
191
+ - lib/worlddb/models/forward.rb
192
+ - lib/worlddb/models/lang.rb
193
+ - lib/worlddb/models/lang_comp.rb
194
+ - lib/worlddb/models/name.rb
195
+ - lib/worlddb/models/place.rb
196
+ - lib/worlddb/models/region.rb
197
+ - lib/worlddb/models/region_comp.rb
198
+ - lib/worlddb/models/tagdb/tag.rb
199
+ - lib/worlddb/models/tagdb/tagging.rb
200
+ - lib/worlddb/models/usage.rb
201
+ - lib/worlddb/patterns.rb
202
+ - lib/worlddb/reader.rb
203
+ - lib/worlddb/reader_file.rb
204
+ - lib/worlddb/reader_zip.rb
205
+ - lib/worlddb/readers/city.rb
206
+ - lib/worlddb/readers/country.rb
207
+ - lib/worlddb/readers/lang.rb
208
+ - lib/worlddb/readers/region.rb
209
+ - lib/worlddb/readers/usage.rb
210
+ - lib/worlddb/schema.rb
211
+ - lib/worlddb/stats.rb
212
+ - lib/worlddb/version.rb
213
+ - test/helper.rb
214
+ - test/test_fixture_matchers.rb
215
+ - test/test_model_city.rb
216
+ - test/test_model_comp.rb
217
+ - test/test_model_country.rb
218
+ - test/test_model_region.rb
219
+ - test/test_models.rb
220
+ homepage: https://github.com/worlddb/world.db.models
221
+ licenses:
222
+ - Public Domain
223
+ metadata: {}
224
+ post_install_message:
225
+ rdoc_options:
226
+ - "--main"
227
+ - README.md
228
+ require_paths:
229
+ - lib
230
+ required_ruby_version: !ruby/object:Gem::Requirement
231
+ requirements:
232
+ - - ">="
233
+ - !ruby/object:Gem::Version
234
+ version: 1.9.2
235
+ required_rubygems_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - ">="
238
+ - !ruby/object:Gem::Version
239
+ version: '0'
240
+ requirements: []
241
+ rubyforge_project:
242
+ rubygems_version: 2.4.2
243
+ signing_key:
244
+ specification_version: 4
245
+ summary: worlddb - world.db schema & models for easy (re)use
246
+ test_files:
247
+ - test/test_model_comp.rb
248
+ - test/test_models.rb
249
+ - test/test_model_city.rb
250
+ - test/test_fixture_matchers.rb
251
+ - test/test_model_country.rb
252
+ - test/test_model_region.rb