worlddb 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +4 -4
- data/lib/worlddb/reader.rb +46 -10
- data/lib/worlddb/schema.rb +6 -0
- data/lib/worlddb/version.rb +1 -1
- metadata +14 -14
data/Rakefile
CHANGED
|
@@ -17,14 +17,14 @@ Hoe.spec 'worlddb' do
|
|
|
17
17
|
|
|
18
18
|
self.author = 'Gerald Bauer'
|
|
19
19
|
self.email = 'opensport@googlegroups.com'
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
self.extra_deps = [
|
|
22
|
-
['textutils', '>= 0.5.0
|
|
22
|
+
['textutils', '~> 0.5'], # e.g. >= 0.5 && <= 1.0
|
|
23
23
|
['commander', '~> 4.1.3'],
|
|
24
24
|
['activerecord', '~> 3.2'] # NB: will include activesupport,etc.
|
|
25
25
|
### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
|
|
26
26
|
]
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
self.licenses = ['Public Domain']
|
|
29
29
|
|
|
30
30
|
self.spec_extras = {
|
|
@@ -71,7 +71,7 @@ namespace :worlddb do
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
task :import => :env do
|
|
74
|
-
WorldDb.read_setup( 'setups/
|
|
74
|
+
WorldDb.read_setup( 'setups/europe.at', '../world.db', skip_tags: true ) # populate world tables
|
|
75
75
|
WorldDb.stats
|
|
76
76
|
end
|
|
77
77
|
|
data/lib/worlddb/reader.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# encoding: UTF-8
|
|
2
|
+
|
|
1
3
|
module WorldDb
|
|
2
4
|
|
|
3
5
|
class Reader
|
|
@@ -107,15 +109,18 @@ class Reader
|
|
|
107
109
|
load_xxx( 'motor', name )
|
|
108
110
|
elsif name =~ /^tag.*\.(\d)$/
|
|
109
111
|
load_tags( name, :grade => $1.to_i )
|
|
110
|
-
elsif name =~ /^([a-z][a-z\-]+[a-z])\/countries/ # e.g. africa/countries or america/countries
|
|
112
|
+
elsif name =~ /^([a-z][a-z\-_]+[a-z])\/countries/ # e.g. africa/countries or america/countries
|
|
111
113
|
### NB: continent changed to regions (e.g. middle-east, caribbean, north-america, etc.)
|
|
112
|
-
### fix/cleanup/todo:
|
|
113
114
|
## auto-add continent (from folder structure) as tag
|
|
114
|
-
##
|
|
115
|
-
load_countries( name )
|
|
115
|
+
## fix: allow dash/hyphen/minus in tag
|
|
116
|
+
load_countries( name, :tags => $1.tr('-', '_') )
|
|
116
117
|
elsif name =~ /\/([a-z]{2})\/cities/
|
|
117
118
|
## auto-add required country code (from folder structure)
|
|
118
119
|
load_cities( $1, name )
|
|
120
|
+
elsif name =~ /\/([a-z]{2})\/regions\.abbr/
|
|
121
|
+
load_regions_xxx( $1, 'abbr', name )
|
|
122
|
+
elsif name =~ /\/([a-z]{2})\/regions\.iso/
|
|
123
|
+
load_regions_xxx( $1, 'iso', name )
|
|
119
124
|
elsif name =~ /\/([a-z]{2})\/regions/
|
|
120
125
|
## auto-add required country code (from folder structure)
|
|
121
126
|
load_regions( $1, name )
|
|
@@ -139,6 +144,26 @@ class Reader
|
|
|
139
144
|
end
|
|
140
145
|
|
|
141
146
|
|
|
147
|
+
def load_regions_xxx( country_key, xxx, name )
|
|
148
|
+
path = "#{include_path}/#{name}.yml"
|
|
149
|
+
|
|
150
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
|
151
|
+
|
|
152
|
+
country = Country.find_by_key!( country_key )
|
|
153
|
+
logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
|
|
154
|
+
|
|
155
|
+
reader = HashReader.new( path )
|
|
156
|
+
|
|
157
|
+
reader.each do |key, value|
|
|
158
|
+
region = Region.find_by_country_id_and_key!( country.id, key )
|
|
159
|
+
region.send( "#{xxx}=", value )
|
|
160
|
+
region.save!
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
Prop.create_from_fixture!( name, path )
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
142
167
|
def load_cities( country_key, name )
|
|
143
168
|
country = Country.find_by_key!( country_key )
|
|
144
169
|
logger.debug "Country #{country.key} >#{country.title} (#{country.code})<"
|
|
@@ -307,7 +332,7 @@ class Reader
|
|
|
307
332
|
def load_usages( name )
|
|
308
333
|
path = "#{include_path}/#{name}.yml"
|
|
309
334
|
|
|
310
|
-
|
|
335
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
|
311
336
|
|
|
312
337
|
reader = HashReader.new( path )
|
|
313
338
|
|
|
@@ -336,7 +361,7 @@ class Reader
|
|
|
336
361
|
def load_xxx( xxx, name )
|
|
337
362
|
path = "#{include_path}/#{name}.yml"
|
|
338
363
|
|
|
339
|
-
|
|
364
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
|
340
365
|
|
|
341
366
|
reader = HashReader.new( path )
|
|
342
367
|
|
|
@@ -354,7 +379,7 @@ private
|
|
|
354
379
|
def load_fixtures_for( clazz, name, more_values={} ) # load from file system
|
|
355
380
|
path = "#{include_path}/#{name}.txt"
|
|
356
381
|
|
|
357
|
-
|
|
382
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
|
358
383
|
|
|
359
384
|
reader = ValuesReader.new( path, more_values )
|
|
360
385
|
|
|
@@ -440,9 +465,15 @@ private
|
|
|
440
465
|
value_popm = value_popm_str.gsub(/[ _]/, '').to_i
|
|
441
466
|
attribs[ :popm ] = value_popm
|
|
442
467
|
attribs[ :m ] = true # auto-mark city as m|metro too
|
|
468
|
+
elsif value =~ /^[A-Z]{2}$/ && clazz == City ## assume region code e.g. TX for city
|
|
469
|
+
value_region = Region.find_by_key_and_country_id!( value.downcase, attribs[:country_id] )
|
|
470
|
+
attribs[ :region_id ] = value_region.id
|
|
443
471
|
elsif value =~ /^[A-Z]{2,3}$/ ## assume two or three-letter code
|
|
444
472
|
attribs[ :code ] = value
|
|
445
|
-
elsif value =~
|
|
473
|
+
elsif value =~ /^([0-9][0-9 _]+[0-9]|[0-9]{1,2})(?:\s*(?:km2|km²)\s*)$/
|
|
474
|
+
## allow numbers like 453 km²
|
|
475
|
+
value_numbers << value.gsub( 'km2', '').gsub( 'km²', '' ).gsub(/[ _]/, '').to_i
|
|
476
|
+
elsif value =~ /^([0-9][0-9 _]+[0-9])|([0-9]{1,2})$/ ## numeric (nb: can use any _ or spaces inside digits e.g. 1_000_000 or 1 000 000)
|
|
446
477
|
value_numbers << value.gsub(/[ _]/, '').to_i
|
|
447
478
|
elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
|
|
448
479
|
|
|
@@ -479,7 +510,9 @@ private
|
|
|
479
510
|
else # countries,regions
|
|
480
511
|
attribs[ :area ] = value_numbers[0]
|
|
481
512
|
attribs[ :pop ] = value_numbers[1]
|
|
482
|
-
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
=begin
|
|
483
516
|
if clazz == Country
|
|
484
517
|
# auto-add tags
|
|
485
518
|
area = value_numbers[0]
|
|
@@ -516,8 +549,11 @@ private
|
|
|
516
549
|
value_tag_keys << 'pop_10m_n_up' if pop >= 10_000_000
|
|
517
550
|
value_tag_keys << 'pop_1m_n_up' if pop >= 1_000_000
|
|
518
551
|
end
|
|
552
|
+
=end
|
|
553
|
+
|
|
554
|
+
|
|
519
555
|
end
|
|
520
|
-
end
|
|
556
|
+
end # if value_numbers.size > 0
|
|
521
557
|
|
|
522
558
|
rec = nil
|
|
523
559
|
|
data/lib/worlddb/schema.rb
CHANGED
|
@@ -49,10 +49,16 @@ add_index :countries, :key, :unique => true
|
|
|
49
49
|
add_index :countries, :code, :unique => true
|
|
50
50
|
|
|
51
51
|
|
|
52
|
+
######
|
|
53
|
+
# NB: rename to adms/admins ??
|
|
54
|
+
#
|
|
55
|
+
# used for state/provice/land/regioni/etc.
|
|
52
56
|
create_table :regions do |t|
|
|
53
57
|
t.string :title, :null => false
|
|
54
58
|
t.string :key, :null => false
|
|
55
59
|
t.string :code # short two or three letter code e.g. NY, OAX, etc.
|
|
60
|
+
t.string :abbr # optional conventional abbrevation (e.g. Stmk., Gto., etc.)
|
|
61
|
+
t.string :iso # iso code
|
|
56
62
|
t.string :synonyms # comma separated list of synonyms
|
|
57
63
|
t.references :country, :null => false
|
|
58
64
|
t.integer :pop # optional population count
|
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: worlddb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.6.
|
|
4
|
+
version: 1.6.2
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,22 +9,22 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-03-
|
|
12
|
+
date: 2013-03-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: textutils
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &77745350 !ruby/object:Gem::Requirement
|
|
17
17
|
none: false
|
|
18
18
|
requirements:
|
|
19
|
-
- -
|
|
19
|
+
- - ~>
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 0.5
|
|
21
|
+
version: '0.5'
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
|
-
version_requirements: *
|
|
24
|
+
version_requirements: *77745350
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: commander
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &77745130 !ruby/object:Gem::Requirement
|
|
28
28
|
none: false
|
|
29
29
|
requirements:
|
|
30
30
|
- - ~>
|
|
@@ -32,10 +32,10 @@ dependencies:
|
|
|
32
32
|
version: 4.1.3
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
|
-
version_requirements: *
|
|
35
|
+
version_requirements: *77745130
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: activerecord
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &77744920 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ~>
|
|
@@ -43,10 +43,10 @@ dependencies:
|
|
|
43
43
|
version: '3.2'
|
|
44
44
|
type: :runtime
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *77744920
|
|
47
47
|
- !ruby/object:Gem::Dependency
|
|
48
48
|
name: rdoc
|
|
49
|
-
requirement: &
|
|
49
|
+
requirement: &77744700 !ruby/object:Gem::Requirement
|
|
50
50
|
none: false
|
|
51
51
|
requirements:
|
|
52
52
|
- - ~>
|
|
@@ -54,10 +54,10 @@ dependencies:
|
|
|
54
54
|
version: '3.10'
|
|
55
55
|
type: :development
|
|
56
56
|
prerelease: false
|
|
57
|
-
version_requirements: *
|
|
57
|
+
version_requirements: *77744700
|
|
58
58
|
- !ruby/object:Gem::Dependency
|
|
59
59
|
name: hoe
|
|
60
|
-
requirement: &
|
|
60
|
+
requirement: &77744480 !ruby/object:Gem::Requirement
|
|
61
61
|
none: false
|
|
62
62
|
requirements:
|
|
63
63
|
- - ~>
|
|
@@ -65,7 +65,7 @@ dependencies:
|
|
|
65
65
|
version: '3.3'
|
|
66
66
|
type: :development
|
|
67
67
|
prerelease: false
|
|
68
|
-
version_requirements: *
|
|
68
|
+
version_requirements: *77744480
|
|
69
69
|
description: worlddb - world.db command line tool
|
|
70
70
|
email: opensport@googlegroups.com
|
|
71
71
|
executables:
|