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
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.2
4
+ version: 2.3.0
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-09 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.10.0
47
+ version: 1.2.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.10.0
54
+ version: 1.2.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tagutils
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -179,22 +179,21 @@ files:
179
179
  - README.md
180
180
  - Rakefile
181
181
  - lib/worlddb/deleter.rb
182
+ - lib/worlddb/helpers/value_helper.rb
182
183
  - lib/worlddb/matcher.rb
184
+ - lib/worlddb/matcher_adm.rb
183
185
  - lib/worlddb/models.rb
184
186
  - lib/worlddb/models/city.rb
185
- - lib/worlddb/models/city_compat.rb
187
+ - lib/worlddb/models/city_base.rb
186
188
  - lib/worlddb/models/continent.rb
187
- - lib/worlddb/models/continent_compat.rb
188
189
  - lib/worlddb/models/country.rb
189
190
  - lib/worlddb/models/country_code.rb
190
- - lib/worlddb/models/country_compat.rb
191
191
  - lib/worlddb/models/forward.rb
192
192
  - lib/worlddb/models/lang.rb
193
- - lib/worlddb/models/lang_compat.rb
194
193
  - lib/worlddb/models/name.rb
195
194
  - lib/worlddb/models/place.rb
196
- - lib/worlddb/models/region.rb
197
- - lib/worlddb/models/region_compat.rb
195
+ - lib/worlddb/models/state.rb
196
+ - lib/worlddb/models/state_base.rb
198
197
  - lib/worlddb/models/tagdb/tag.rb
199
198
  - lib/worlddb/models/tagdb/tagging.rb
200
199
  - lib/worlddb/models/usage.rb
@@ -202,35 +201,54 @@ files:
202
201
  - lib/worlddb/reader.rb
203
202
  - lib/worlddb/reader_file.rb
204
203
  - lib/worlddb/reader_zip.rb
204
+ - lib/worlddb/readers/base.rb
205
205
  - lib/worlddb/readers/city.rb
206
206
  - lib/worlddb/readers/country.rb
207
207
  - lib/worlddb/readers/lang.rb
208
- - lib/worlddb/readers/region.rb
208
+ - lib/worlddb/readers/state.rb
209
+ - lib/worlddb/readers/state_tree.rb
209
210
  - lib/worlddb/readers/usage.rb
210
211
  - lib/worlddb/schema.rb
211
212
  - lib/worlddb/stats.rb
213
+ - lib/worlddb/tree_reader.rb
212
214
  - lib/worlddb/version.rb
215
+ - test/adm/test_fixture_matcher_adm2.rb
216
+ - test/adm/test_fixture_matcher_adm3.rb
217
+ - test/adm/test_fixture_matcher_tree.rb
218
+ - test/adm/test_read_adm.rb
219
+ - test/adm/test_read_tree.rb
213
220
  - test/data/at-austria/1--b-burgenland/counties.txt
214
221
  - test/data/at-austria/2--n-niederoesterreich/counties.txt
215
222
  - test/data/at-austria/3--w-wien/counties.txt
223
+ - test/data/at-austria/orte.txt
216
224
  - test/data/at-austria/setups/adm.txt
225
+ - test/data/at-austria/setups/tree.txt
217
226
  - test/data/at-austria/states.txt
218
227
  - test/data/de-deutschland/3--by-bayern/1--oberbayern/counties.txt
219
228
  - test/data/de-deutschland/3--by-bayern/4--oberfranken/counties.txt
220
- - test/data/de-deutschland/3--by-bayern/districts.txt
229
+ - test/data/de-deutschland/3--by-bayern/4--oberfranken/orte.txt
230
+ - test/data/de-deutschland/3--by-bayern/4--oberfranken/orte_ii.txt
231
+ - test/data/de-deutschland/3--by-bayern/parts.txt
232
+ - test/data/de-deutschland/orte.txt
221
233
  - test/data/de-deutschland/setups/adm.txt
234
+ - test/data/de-deutschland/setups/tree.txt
222
235
  - test/data/de-deutschland/states.txt
223
236
  - test/helper.rb
224
- - test/test_fixture_matcher_adm2.rb
225
- - test/test_fixture_matcher_adm3.rb
226
237
  - test/test_fixture_matchers.rb
227
238
  - test/test_fixture_matchers_ii.rb
228
239
  - test/test_model_city.rb
229
- - test/test_model_comp.rb
240
+ - test/test_model_compat.rb
230
241
  - test/test_model_country.rb
231
- - test/test_model_region.rb
242
+ - test/test_model_state.rb
243
+ - test/test_model_states_at.rb
244
+ - test/test_model_states_de.rb
232
245
  - test/test_models.rb
233
- - test/test_read_adm.rb
246
+ - test/test_parse_city.rb
247
+ - test/test_parse_country.rb
248
+ - test/test_parse_state.rb
249
+ - test/test_state_tree_reader_at.rb
250
+ - test/test_state_tree_reader_de.rb
251
+ - test/test_tree_reader.rb
234
252
  homepage: https://github.com/worlddb/world.db.models
235
253
  licenses:
236
254
  - Public Domain
@@ -258,13 +276,23 @@ signing_key:
258
276
  specification_version: 4
259
277
  summary: worlddb - world.db schema 'n' models for easy (re)use
260
278
  test_files:
261
- - test/test_model_comp.rb
262
279
  - test/test_models.rb
263
- - test/test_read_adm.rb
280
+ - test/adm/test_read_tree.rb
281
+ - test/adm/test_fixture_matcher_tree.rb
282
+ - test/adm/test_read_adm.rb
283
+ - test/adm/test_fixture_matcher_adm2.rb
284
+ - test/adm/test_fixture_matcher_adm3.rb
285
+ - test/test_parse_country.rb
286
+ - test/test_model_state.rb
287
+ - test/test_tree_reader.rb
264
288
  - test/test_model_city.rb
265
289
  - test/test_fixture_matchers.rb
266
290
  - test/test_model_country.rb
267
- - test/test_model_region.rb
268
- - test/test_fixture_matcher_adm2.rb
269
- - test/test_fixture_matcher_adm3.rb
291
+ - test/test_parse_city.rb
292
+ - test/test_model_compat.rb
293
+ - test/test_model_states_de.rb
294
+ - test/test_state_tree_reader_at.rb
295
+ - test/test_state_tree_reader_de.rb
296
+ - test/test_parse_state.rb
270
297
  - test/test_fixture_matchers_ii.rb
298
+ - test/test_model_states_at.rb
@@ -1,27 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for commpatibility (for old code)
9
-
10
- class City
11
-
12
- def title() name; end
13
- def title=(value) self.name = value; end
14
-
15
- scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
16
-
17
-
18
- def synonyms() alt_names; end
19
- def synonyms=(value) self.alt_names = value; end
20
-
21
- def title_w_synonyms( opts={} ) all_names( opts ); end # depreciated: use all_names instead
22
-
23
- end # class Cities
24
-
25
- end # module Model
26
- end # module WorldDb
27
-
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for commpatibility (for old code)
9
-
10
- class Continent
11
-
12
- def title() name; end
13
- def title=(value) self.name = value; end
14
-
15
- scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
16
-
17
- def synonyms() alt_names; end
18
- def synonyms=(value) self.alt_names = value; end
19
-
20
- end # class Continent
21
-
22
-
23
- end # module Model
24
- end # module WorldDb
@@ -1,35 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for commpatibility (for old code)
9
-
10
-
11
- class Country
12
-
13
- def title() name; end
14
- def title=(value) self.name = value; end
15
-
16
- scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
17
-
18
- def iso2() alpha2; end
19
- def iso2=(value) self.alpha2 = value; end
20
-
21
- def iso3() alpha3; end
22
- def iso3=(value) self.alpha3 = value; end
23
-
24
-
25
- def synonyms() alt_names; end
26
- def synonyms=(value) self.alt_names = value; end
27
-
28
- def title_w_synonyms( opts={} ) all_names( opts ); end # depreciated: use all_names instead
29
-
30
-
31
- end # class Country
32
-
33
- end # module Model
34
- end # module WorldDb
35
-
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for commpatibility (for old code)
9
-
10
-
11
- class Lang
12
-
13
- #####################################################
14
- # alias for name (remove! add depreciated api call ???)
15
- def title() name; end
16
- def title=(value) self.name = value; end
17
-
18
- scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
19
-
20
- end # class Lang
21
-
22
- end # module Model
23
- end # module WorldDb
@@ -1,26 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module WorldDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for commpatibility (for old code)
9
-
10
- class Region
11
-
12
- def title() name; end
13
- def title=(value) self.name = value; end
14
-
15
- scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
16
-
17
- def synonyms() alt_names; end
18
- def synonyms=(value) self.alt_names = value; end
19
-
20
- def title_w_synonyms( opts={} ) all_names( opts ); end # depreciated: use all_names instead
21
-
22
-
23
- end # class Region
24
-
25
- end # module Model
26
- end # module WorldDb
@@ -1,79 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- module WorldDb
4
-
5
- class RegionReader
6
-
7
- include LogUtils::Logging
8
-
9
- ## make models available by default with namespace
10
- # e.g. lets you use Usage instead of Model::Usage
11
- include Models
12
-
13
- ## value helpers e.g. is_year?, is_taglist? etc.
14
- include TextUtils::ValueHelper
15
-
16
-
17
- def self.from_zip( zip_file, entry_path, more_attribs={} )
18
- ## get text content from zip
19
-
20
- entry = zip_file.find_entry( entry_path )
21
-
22
- ## todo/fix: add force encoding to utf-8 ??
23
- ## check!!!
24
- ## clean/prepprocess lines
25
- ## e.g. CR/LF (/r/n) to LF (e.g. /n)
26
- text = entry.get_input_stream().read()
27
-
28
- ## NOTE: needs logger ref; only available in instance methods; use global logger for now
29
- logger = LogUtils::Logger.root
30
- logger.debug "text.encoding.name (before): #{text.encoding.name}"
31
- #####
32
- # NB: ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
33
- ## NB:
34
- # for now "hardcoded" to utf8 - what else can we do?
35
- # - note: force_encoding will NOT change the chars only change the assumed encoding w/o translation
36
- text = text.force_encoding( Encoding::UTF_8 )
37
- logger.debug "text.encoding.name (after): #{text.encoding.name}"
38
-
39
- ## todo:
40
- # NB: for convenience: convert fancy unicode dashes/hyphens to plain ascii hyphen-minus
41
- ## text = TextUtils.convert_unicode_dashes_to_plain_ascii( text, path: path )
42
-
43
- self.from_string( text, more_attribs )
44
- end
45
-
46
- def self.from_file( path, more_attribs={} )
47
- ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
48
- ## - see textutils/utils.rb
49
- text = File.read_utf8( path )
50
- self.from_string( text, more_attribs )
51
- end
52
-
53
- def self.from_string( text, more_attribs={} )
54
- RegionReader.new( text, more_attribs )
55
- end
56
-
57
-
58
- def skip_tags?() @skip_tags == true; end
59
- def strict?() @strict == true; end
60
-
61
- def initialize( text, more_attribs={} )
62
- ## todo/fix: how to add opts={} ???
63
-
64
- @text = text
65
- @more_attribs = more_attribs
66
- end
67
-
68
-
69
- def read()
70
- reader = ValuesReader.from_string( @text, @more_attribs )
71
-
72
- reader.each_line do |attribs, values|
73
- opts = { skip_tags: skip_tags? }
74
- Region.create_or_update_from_attribs( attribs, values, opts )
75
- end
76
- end
77
-
78
- end # class RegionReader
79
- end # module WorldDb
@@ -1,62 +0,0 @@
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
@@ -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
-