worlddb 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +73 -73
- data/Rakefile +8 -2
- data/{db → data}/africa/countries.txt +3 -1
- data/{db → data}/africa/de.countries.yml +0 -0
- data/{db → data}/africa/en.wikipedia.yml +0 -0
- data/{db → data}/africa/fifa.yml +0 -0
- data/{db → data}/africa/iso3.yml +0 -0
- data/{db → data}/america/br/cities.txt +0 -0
- data/{db → data}/america/br/regions.txt +0 -0
- data/{db → data}/america/ca/cities.txt +0 -0
- data/{db → data}/america/ca/regions.txt +0 -0
- data/{db → data}/america/countries.motor.yml +0 -0
- data/{db → data}/america/countries.txt +0 -0
- data/{db → data}/america/de.countries.yml +0 -0
- data/{db → data}/america/en.wikipedia.yml +0 -0
- data/{db → data}/america/es.countries.yml +0 -0
- data/{db → data}/america/mx/cities.txt +0 -0
- data/{db → data}/america/mx/regions.txt +0 -0
- data/{db → data}/america/us/cities.txt +0 -0
- data/{db → data}/america/us/regions.txt +0 -0
- data/{db → data}/america/ve/cities.txt +0 -0
- data/{db → data}/america/ve/regions.txt +0 -0
- data/{db → data}/asia/countries.txt +0 -0
- data/{db → data}/asia/de.countries.yml +0 -0
- data/{db → data}/asia/en.wikipedia.yml +0 -0
- data/{db → data}/asia/jp/cities.txt +0 -0
- data/{db → data}/europe/at/cities.txt +0 -0
- data/{db → data}/europe/at/regions.txt +0 -0
- data/{db → data}/europe/be/cities.txt +0 -0
- data/{db → data}/europe/be/regions.txt +0 -0
- data/{db → data}/europe/bg/cities.txt +0 -0
- data/{db → data}/europe/by/cities.txt +0 -0
- data/{db → data}/europe/ch/cities.txt +0 -0
- data/{db → data}/europe/countries.txt +2 -3
- data/{db → data}/europe/cy/cities.txt +0 -0
- data/{db → data}/europe/cz/cities.txt +0 -0
- data/{db → data}/europe/cz/regions.txt +0 -0
- data/{db → data}/europe/de/cities.txt +0 -0
- data/{db → data}/europe/de/regions.txt +0 -0
- data/{db → data}/europe/de.countries.yml +0 -0
- data/{db → data}/europe/dk/cities.txt +0 -0
- data/{db → data}/europe/ee/cities.txt +0 -0
- data/{db → data}/europe/en/cities.txt +0 -0
- data/{db → data}/europe/en/regions.txt +0 -0
- data/{db → data}/europe/en.wikipedia.yml +0 -0
- data/{db → data}/europe/es/cities.txt +0 -0
- data/{db → data}/europe/es/regions.txt +0 -0
- data/{db → data}/europe/es.countries.yml +0 -0
- data/{db → data}/europe/fi/cities.txt +0 -0
- data/{db → data}/europe/fr/cities.txt +0 -0
- data/{db → data}/europe/fr/regions.txt +0 -0
- data/{db → data}/europe/gr/cities.txt +0 -0
- data/{db → data}/europe/hr/cities.txt +0 -0
- data/{db → data}/europe/hu/cities.txt +0 -0
- data/{db → data}/europe/ie/cities.txt +0 -0
- data/{db → data}/europe/it/cities.txt +0 -0
- data/{db → data}/europe/lt/cities.txt +0 -0
- data/{db → data}/europe/lv/cities.txt +0 -0
- data/{db → data}/europe/nl/cities.txt +0 -0
- data/{db → data}/europe/no/cities.txt +0 -0
- data/{db → data}/europe/pl/cities.txt +0 -0
- data/{db → data}/europe/pt/cities.txt +0 -0
- data/{db → data}/europe/ro/cities.txt +0 -0
- data/{db → data}/europe/rs/cities.txt +0 -0
- data/{db → data}/europe/ru/cities.txt +0 -0
- data/{db → data}/europe/sc/cities.txt +0 -0
- data/{db → data}/europe/se/cities.txt +0 -0
- data/{db → data}/europe/tr/cities.txt +0 -0
- data/{db → data}/europe/ua/cities.txt +0 -0
- data/{db → data}/europe/wa/cities.txt +0 -0
- data/{db → data}/oceania/au/cities.txt +0 -0
- data/{db → data}/oceania/countries.txt +0 -0
- data/{db → data}/oceania/de.countries.yml +0 -0
- data/{db → data}/oceania/en.wikipedia.yml +0 -0
- data/{db → data}/tags.yml +0 -0
- data/lib/worlddb/loader.rb +1 -1
- data/lib/worlddb/models/city.rb +33 -13
- data/lib/worlddb/models/country.rb +17 -10
- data/lib/worlddb/models/tag.rb +4 -9
- data/lib/worlddb/reader.rb +56 -35
- data/lib/worlddb/schema.rb +10 -3
- data/lib/worlddb/version.rb +1 -1
- metadata +82 -139
data/Manifest.txt
CHANGED
@@ -3,79 +3,79 @@ Manifest.txt
|
|
3
3
|
README.markdown
|
4
4
|
Rakefile
|
5
5
|
bin/worlddb
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
6
|
+
data/africa/countries.txt
|
7
|
+
data/africa/de.countries.yml
|
8
|
+
data/africa/en.wikipedia.yml
|
9
|
+
data/africa/fifa.yml
|
10
|
+
data/africa/iso3.yml
|
11
|
+
data/america/br/cities.txt
|
12
|
+
data/america/br/regions.txt
|
13
|
+
data/america/ca/cities.txt
|
14
|
+
data/america/ca/regions.txt
|
15
|
+
data/america/countries.motor.yml
|
16
|
+
data/america/countries.txt
|
17
|
+
data/america/de.countries.yml
|
18
|
+
data/america/en.wikipedia.yml
|
19
|
+
data/america/es.countries.yml
|
20
|
+
data/america/mx/cities.txt
|
21
|
+
data/america/mx/regions.txt
|
22
|
+
data/america/us/cities.txt
|
23
|
+
data/america/us/regions.txt
|
24
|
+
data/america/ve/cities.txt
|
25
|
+
data/america/ve/regions.txt
|
26
|
+
data/asia/countries.txt
|
27
|
+
data/asia/de.countries.yml
|
28
|
+
data/asia/en.wikipedia.yml
|
29
|
+
data/asia/jp/cities.txt
|
30
|
+
data/europe/at/cities.txt
|
31
|
+
data/europe/at/regions.txt
|
32
|
+
data/europe/be/cities.txt
|
33
|
+
data/europe/be/regions.txt
|
34
|
+
data/europe/bg/cities.txt
|
35
|
+
data/europe/by/cities.txt
|
36
|
+
data/europe/ch/cities.txt
|
37
|
+
data/europe/countries.txt
|
38
|
+
data/europe/cy/cities.txt
|
39
|
+
data/europe/cz/cities.txt
|
40
|
+
data/europe/cz/regions.txt
|
41
|
+
data/europe/de.countries.yml
|
42
|
+
data/europe/de/cities.txt
|
43
|
+
data/europe/de/regions.txt
|
44
|
+
data/europe/dk/cities.txt
|
45
|
+
data/europe/ee/cities.txt
|
46
|
+
data/europe/en.wikipedia.yml
|
47
|
+
data/europe/en/cities.txt
|
48
|
+
data/europe/en/regions.txt
|
49
|
+
data/europe/es.countries.yml
|
50
|
+
data/europe/es/cities.txt
|
51
|
+
data/europe/es/regions.txt
|
52
|
+
data/europe/fi/cities.txt
|
53
|
+
data/europe/fr/cities.txt
|
54
|
+
data/europe/fr/regions.txt
|
55
|
+
data/europe/gr/cities.txt
|
56
|
+
data/europe/hr/cities.txt
|
57
|
+
data/europe/hu/cities.txt
|
58
|
+
data/europe/ie/cities.txt
|
59
|
+
data/europe/it/cities.txt
|
60
|
+
data/europe/lt/cities.txt
|
61
|
+
data/europe/lv/cities.txt
|
62
|
+
data/europe/nl/cities.txt
|
63
|
+
data/europe/no/cities.txt
|
64
|
+
data/europe/pl/cities.txt
|
65
|
+
data/europe/pt/cities.txt
|
66
|
+
data/europe/ro/cities.txt
|
67
|
+
data/europe/rs/cities.txt
|
68
|
+
data/europe/ru/cities.txt
|
69
|
+
data/europe/sc/cities.txt
|
70
|
+
data/europe/se/cities.txt
|
71
|
+
data/europe/tr/cities.txt
|
72
|
+
data/europe/ua/cities.txt
|
73
|
+
data/europe/wa/cities.txt
|
74
|
+
data/oceania/au/cities.txt
|
75
|
+
data/oceania/countries.txt
|
76
|
+
data/oceania/de.countries.yml
|
77
|
+
data/oceania/en.wikipedia.yml
|
78
|
+
data/tags.yml
|
79
79
|
lib/worlddb.rb
|
80
80
|
lib/worlddb/cli/opts.rb
|
81
81
|
lib/worlddb/cli/runner.rb
|
data/Rakefile
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'hoe'
|
2
2
|
require './lib/worlddb/version.rb'
|
3
3
|
|
4
|
+
## NB: plugin (hoe-manifest) not required; just used for future testing/development
|
5
|
+
Hoe::plugin :manifest # more options for manifests (in the future; not yet)
|
6
|
+
|
4
7
|
Hoe.spec 'worlddb' do
|
5
8
|
|
6
9
|
self.version = WorldDB::VERSION
|
@@ -14,12 +17,15 @@ Hoe.spec 'worlddb' do
|
|
14
17
|
self.email = 'opensport@googlegroups.com'
|
15
18
|
|
16
19
|
# switch extension to .markdown for gihub formatting
|
17
|
-
|
18
|
-
self.
|
20
|
+
# - auto-added from Manifest.txt (see define_spec in class Hoe)
|
21
|
+
# self.readme_file = 'README.markdown'
|
22
|
+
# self.history_file = 'History.markdown'
|
19
23
|
|
20
24
|
self.extra_deps = [
|
21
25
|
['activerecord', '~> 3.2'] # NB: will include activesupport,etc.
|
22
26
|
### ['sqlite3', '~> 1.3'] # NB: install on your own; remove dependency
|
23
27
|
]
|
28
|
+
|
29
|
+
self.licenses = ['Public Domain']
|
24
30
|
|
25
31
|
end
|
@@ -54,7 +54,9 @@ rw, Rwanda, RWA, 26_338, 11_689_696, Kigali, un|fifa
|
|
54
54
|
st, São Tomé and Príncipe, STP, 1_001, 183_176, São Tomé, un|fifa
|
55
55
|
|
56
56
|
sn, Senegal, SEN, 196_723, 12_855_153, Dakar, un|fifa
|
57
|
-
|
57
|
+
|
58
|
+
## NB: sc renamed to ey (sc used for Scottland)
|
59
|
+
ey, Seychelles, SEY, 451, 84_000, Victoria, un|fifa
|
58
60
|
sl, Sierra Leone, SLE, 71_740, 5_485_998, Freetown, un|fifa
|
59
61
|
|
60
62
|
so, Somalia, SOM, 637_657, 10_085_638, Mogadishu, un|fifa
|
File without changes
|
File without changes
|
data/{db → data}/africa/fifa.yml
RENAMED
File without changes
|
data/{db → data}/africa/iso3.yml
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -16,7 +16,7 @@ sm, San Marino, SMR, 61, 32_404, City of San Marino, un|fifa
|
|
16
16
|
## NB:
|
17
17
|
#
|
18
18
|
# countries also include:
|
19
|
-
# england (en), scotland (
|
19
|
+
# england (en), scotland (sc) - nb: Seychellen renamed from sc to ey
|
20
20
|
# use nd for northern ireland (ni (nicaragua),no, nr (naru) taken - anything better - anything common?)
|
21
21
|
# - use ul for ulster? better?
|
22
22
|
#
|
@@ -79,8 +79,7 @@ hu, Hungary, HUN, 93_030, 9_979_000, supra:eu, un|fifa|eu|uefa|sche
|
|
79
79
|
gb, Great Britain, GBR, 243_610, 63_047_162, supra:eu, un|eu|g8|g20
|
80
80
|
en, England, ENG, 130_395, 53_013_000, country:gb, fifa # NB: FIFA (ENG); not a valid iso country n internet domain / its uk - what to use - anything better?
|
81
81
|
|
82
|
-
|
83
|
-
st, Scotland, SCO, 78_387, 5_254_800, country:gb, fifa # NB: FIFA (SCO); not a valid iso country/internet domain - its uk - what to use - anything better?
|
82
|
+
sc, Scotland, SCO, 78_387, 5_254_800, country:gb, fifa # NB: FIFA (SCO); not a valid iso country/internet domain - its uk - what to use - anything better?
|
84
83
|
wa, Wales, WAL, 20_779, 3_064_000, country:gb, fifa
|
85
84
|
nd, Northern Ireland, NIR, 13_843, 1_810_900, Belfast, country:gb, fifa
|
86
85
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/{db → data}/tags.yml
RENAMED
File without changes
|
data/lib/worlddb/loader.rb
CHANGED
data/lib/worlddb/models/city.rb
CHANGED
@@ -7,30 +7,50 @@ class City < ActiveRecord::Base
|
|
7
7
|
|
8
8
|
belongs_to :country, :class_name => 'Country', :foreign_key => 'country_id'
|
9
9
|
belongs_to :region, :class_name => 'Region', :foreign_key => 'region_id'
|
10
|
+
|
11
|
+
## self referencing hierachy within cities e.g. m|metro > c|city > d|district
|
12
|
+
|
13
|
+
## fix: use condition check for m|d|c flag?? why? why not? (NB: flags are NOT exclusive e.g. possible metro|city)
|
10
14
|
|
11
|
-
|
12
|
-
has_many
|
15
|
+
## (1) metro - level up
|
16
|
+
has_many :cities, :class_name => 'City', :foreign_key => 'city_id'
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
## (2) city
|
19
|
+
belongs_to :metro, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for parent - use parent?
|
20
|
+
has_many :districts, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for cities - use cities?
|
16
21
|
|
22
|
+
## (3) district - level down
|
23
|
+
belongs_to :city, :class_name => 'City', :foreign_key => 'city_id' ## for now alias for parent - use parent?
|
17
24
|
|
18
|
-
def self.by_key # order by key (a-z)
|
19
|
-
self.order( 'key asc' )
|
20
|
-
end
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
###
|
27
|
+
# NB: use is_ for flags to avoid conflict w/ assocs (e.g. metro?, city? etc.)
|
28
|
+
|
29
|
+
def is_metro?
|
30
|
+
m? == true
|
24
31
|
end
|
25
32
|
|
26
|
-
def
|
27
|
-
|
33
|
+
def is_city?
|
34
|
+
c? == true
|
28
35
|
end
|
29
36
|
|
30
|
-
def
|
31
|
-
|
37
|
+
def is_district?
|
38
|
+
d? == true
|
32
39
|
end
|
33
40
|
|
41
|
+
|
42
|
+
has_many :taggings, :as => :taggable
|
43
|
+
has_many :tags, :through => :taggings
|
44
|
+
|
45
|
+
validates :key, :format => { :with => /^[a-z]{3,}$/, :message => 'expected three or more lowercase letters a-z' }
|
46
|
+
validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }, :allow_nil => true
|
47
|
+
|
48
|
+
scope :by_key, order( 'key asc' ) # order by key (a-z)
|
49
|
+
scope :by_title, order( 'title asc' ) # order by title (a-z)
|
50
|
+
scope :by_pop, order( 'pop desc' ) # order by pop(ulation)
|
51
|
+
scope :by_popm, order( 'popm desc' ) # order by pop(ulation) metropolitan area
|
52
|
+
scope :by_area, order( 'area desc' ) # order by area (in square km)
|
53
|
+
|
34
54
|
def title_w_synonyms
|
35
55
|
return title if synonyms.blank?
|
36
56
|
|
@@ -18,22 +18,29 @@ class Country < ActiveRecord::Base
|
|
18
18
|
validates :key, :format => { :with => /^[a-z]{2}$/, :message => 'expected two lowercase letters a-z' }
|
19
19
|
validates :code, :format => { :with => /^[A-Z_]{3}$/, :message => 'expected three uppercase letters A-Z (and _)' }
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
scope :by_key, order( 'key asc' ) # order by key (a-z)
|
22
|
+
scope :by_title, order( 'title asc' ) # order by title (a-z)
|
23
|
+
scope :by_code, order( 'code asc' ) # order by code (a-z)
|
24
|
+
scope :by_pop, order( 'pop desc' ) # order by pop(ulation)
|
25
|
+
scope :by_area, order( 'area desc') # order by area (in square km)
|
26
|
+
|
27
|
+
###
|
28
|
+
# NB: use is_ for flags to avoid conflict w/ assocs
|
29
|
+
|
30
|
+
def is_supra?
|
31
|
+
s? == true
|
27
32
|
end
|
28
33
|
|
29
|
-
def
|
30
|
-
|
34
|
+
def is_country?
|
35
|
+
c? == true
|
31
36
|
end
|
32
37
|
|
33
|
-
def
|
34
|
-
|
38
|
+
def is_dependency?
|
39
|
+
d? == true
|
35
40
|
end
|
36
41
|
|
42
|
+
|
43
|
+
|
37
44
|
def title_w_synonyms
|
38
45
|
return title if synonyms.blank?
|
39
46
|
|
data/lib/worlddb/models/tag.rb
CHANGED
@@ -13,21 +13,16 @@ module WorldDB::Models
|
|
13
13
|
## fix/todo: improve regex use [a-z][a-z0-9] | [a-z][a-z0-9_ ]+[a-z0-9] to only allow spaces and underscore inbetween; do not allow digit as first char
|
14
14
|
validates :key, :format => { :with => /^[a-z0-9_ ]{2,}$/, :message => 'expected two or more lowercase letters a-z or 0-9 digits or space or underscore' }
|
15
15
|
|
16
|
+
scope :by_key, order( 'key desc' )
|
17
|
+
scope :by_title, order( 'title desc' )
|
18
|
+
|
16
19
|
before_save :on_before_save
|
17
20
|
|
18
21
|
def on_before_save
|
19
22
|
# replace space with underscore e.g. north america becomes north_america and so on
|
20
23
|
self.slug = key.gsub( ' ', '_' )
|
21
24
|
end
|
22
|
-
|
23
|
-
def self.by_key
|
24
|
-
self.order( 'key desc' )
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.by_title
|
28
|
-
self.order( 'title desc' )
|
29
|
-
end
|
30
|
-
|
25
|
+
|
31
26
|
end # class Tag
|
32
27
|
|
33
28
|
end # module WorldDB::Models
|
data/lib/worlddb/reader.rb
CHANGED
@@ -41,11 +41,14 @@ class Reader
|
|
41
41
|
# load from file system
|
42
42
|
|
43
43
|
def load_with_include_path( name, include_path )
|
44
|
-
if name =~
|
45
|
-
|
44
|
+
if name =~ /^([a-z]{3,})\/countries/
|
45
|
+
## auto-add continent (from folder structure) as tag
|
46
|
+
load_countries_with_include_path( name, include_path, :tags => $1 )
|
46
47
|
elsif name =~ /\/([a-z]{2})\/cities/
|
48
|
+
## auto-add required country code (from folder structure)
|
47
49
|
load_cities_with_include_path( $1, name, include_path )
|
48
50
|
elsif name =~ /\/([a-z]{2})\/regions/
|
51
|
+
## auto-add required country code (from folder structure)
|
49
52
|
load_regions_with_include_path( $1, name, include_path )
|
50
53
|
else
|
51
54
|
puts "*** error: unknown world.db fixture type >#{name}<"
|
@@ -53,8 +56,8 @@ class Reader
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
|
-
def load_countries_with_include_path( name, include_path )
|
57
|
-
load_fixtures_with_include_path_for( Country, name, include_path )
|
59
|
+
def load_countries_with_include_path( name, include_path, more_values={} )
|
60
|
+
load_fixtures_with_include_path_for( Country, name, include_path, more_values )
|
58
61
|
end
|
59
62
|
|
60
63
|
def load_regions_with_include_path( country_key, name, include_path )
|
@@ -82,8 +85,9 @@ class Reader
|
|
82
85
|
load_fifa_builtin( name )
|
83
86
|
elsif name =~ /\/iso3/
|
84
87
|
load_iso3_builtin( name )
|
85
|
-
elsif name =~
|
86
|
-
|
88
|
+
elsif name =~ /^([a-z]{3,})\/countries/ # e.g. africa/countries or america/countries
|
89
|
+
## auto-add continent (from folder structure) as tag
|
90
|
+
load_countries_builtin( name, :tags => $1 )
|
87
91
|
elsif name =~ /\/([a-z]{2})\/cities/
|
88
92
|
load_cities_builtin( $1, name )
|
89
93
|
elsif name =~ /\/([a-z]{2})\/regions/
|
@@ -94,8 +98,8 @@ class Reader
|
|
94
98
|
end
|
95
99
|
end
|
96
100
|
|
97
|
-
def load_countries_builtin( name )
|
98
|
-
load_fixtures_builtin_for( Country, name )
|
101
|
+
def load_countries_builtin( name, more_values )
|
102
|
+
load_fixtures_builtin_for( Country, name, more_values )
|
99
103
|
end
|
100
104
|
|
101
105
|
def load_regions_builtin( country_key, name )
|
@@ -114,7 +118,7 @@ class Reader
|
|
114
118
|
|
115
119
|
|
116
120
|
def load_iso3_builtin( name )
|
117
|
-
path = "#{WorldDB.root}/
|
121
|
+
path = "#{WorldDB.root}/data/#{name}.yml"
|
118
122
|
|
119
123
|
puts "*** parsing data '#{name}' (#{path})..."
|
120
124
|
|
@@ -137,11 +141,11 @@ class Reader
|
|
137
141
|
|
138
142
|
end
|
139
143
|
|
140
|
-
Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "
|
144
|
+
Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "world.yml.#{WorldDB::VERSION}" )
|
141
145
|
end
|
142
146
|
|
143
147
|
def load_fifa_builtin( name )
|
144
|
-
path = "#{WorldDB.root}/
|
148
|
+
path = "#{WorldDB.root}/data/#{name}.yml"
|
145
149
|
|
146
150
|
puts "*** parsing data '#{name}' (#{path})..."
|
147
151
|
|
@@ -161,11 +165,10 @@ class Reader
|
|
161
165
|
|
162
166
|
end
|
163
167
|
|
164
|
-
Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "
|
168
|
+
Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "world.yml.#{WorldDB::VERSION}" )
|
165
169
|
end
|
166
170
|
|
167
171
|
|
168
|
-
|
169
172
|
private
|
170
173
|
def load_fixtures_with_include_path_for( clazz, name, include_path, more_values={} ) # load from file system
|
171
174
|
path = "#{include_path}/#{name}.txt"
|
@@ -180,7 +183,7 @@ private
|
|
180
183
|
end
|
181
184
|
|
182
185
|
def load_fixtures_builtin_for( clazz, name, more_values={} ) # load from gem (built-in)
|
183
|
-
path = "#{WorldDB.root}/
|
186
|
+
path = "#{WorldDB.root}/data/#{name}.txt"
|
184
187
|
|
185
188
|
puts "*** parsing data '#{name}' (#{path})..."
|
186
189
|
|
@@ -199,12 +202,25 @@ private
|
|
199
202
|
|
200
203
|
reader.each_line do |attribs, values|
|
201
204
|
|
202
|
-
value_numbers
|
205
|
+
value_numbers = []
|
206
|
+
value_tag_keys = []
|
203
207
|
|
204
|
-
###
|
205
|
-
##
|
208
|
+
### check for "default" tags - that is, if present attribs[:tags] remove from hash
|
206
209
|
|
207
|
-
|
210
|
+
if attribs[:tags].present?
|
211
|
+
more_tag_keys = attribs[:tags].split('|')
|
212
|
+
attribs.delete(:tags)
|
213
|
+
|
214
|
+
## unify; replace _w/ space; remove leading n trailing whitespace
|
215
|
+
more_tag_keys = more_tag_keys.map do |key|
|
216
|
+
key = key.gsub( '_', ' ' )
|
217
|
+
key = key.strip
|
218
|
+
key
|
219
|
+
end
|
220
|
+
|
221
|
+
value_tag_keys += more_tag_keys
|
222
|
+
end
|
223
|
+
|
208
224
|
|
209
225
|
if clazz == City
|
210
226
|
attribs[ :c ] = true # assume city type by default (use metro,district to change in fixture)
|
@@ -256,8 +272,8 @@ private
|
|
256
272
|
value_numbers << value.gsub(/[ _]/, '').to_i
|
257
273
|
elsif (values.size==(index+1)) && value =~ /^[a-z0-9\|_ ]+$/ # tags must be last entry
|
258
274
|
|
259
|
-
puts "
|
260
|
-
|
275
|
+
puts " found tags: >>#{value}<<"
|
276
|
+
|
261
277
|
tag_keys = value.split('|')
|
262
278
|
|
263
279
|
## unify; replace _w/ space; remove leading n trailing whitespace
|
@@ -267,15 +283,7 @@ private
|
|
267
283
|
key
|
268
284
|
end
|
269
285
|
|
270
|
-
|
271
|
-
tag = Tag.find_by_key( key )
|
272
|
-
if tag.nil? # create tag if it doesn't exit
|
273
|
-
puts " creating tag >#{key}<"
|
274
|
-
tag = Tag.create!( key: key )
|
275
|
-
end
|
276
|
-
value_tags << tag
|
277
|
-
end
|
278
|
-
|
286
|
+
value_tag_keys += tag_keys
|
279
287
|
else
|
280
288
|
# issue warning: unknown type for value
|
281
289
|
puts "!!!! >>>> warning: unknown type for value >#{value}<"
|
@@ -313,13 +321,26 @@ private
|
|
313
321
|
|
314
322
|
rec.update_attributes!( attribs )
|
315
323
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
324
|
+
##################
|
325
|
+
## add taggings
|
326
|
+
|
327
|
+
if value_tag_keys.size > 0
|
328
|
+
|
329
|
+
value_tag_keys.uniq! # remove duplicates
|
330
|
+
puts " adding #{value_tag_keys.size} taggings: >>#{value_tag_keys.join('|')}<<..."
|
331
|
+
|
332
|
+
### fix/todo: check tag_ids and only update diff (add/remove ids)
|
333
|
+
|
334
|
+
value_tag_keys.each do |key|
|
335
|
+
tag = Tag.find_by_key( key )
|
336
|
+
if tag.nil? # create tag if it doesn't exit
|
337
|
+
puts " creating tag >#{key}<"
|
338
|
+
tag = Tag.create!( key: key )
|
339
|
+
end
|
340
|
+
rec.tags << tag
|
341
|
+
end
|
320
342
|
end
|
321
|
-
|
322
|
-
### fix/todo: check tag_ids and only update diff (add/remove ids)
|
343
|
+
|
323
344
|
|
324
345
|
end # each_line
|
325
346
|
|
data/lib/worlddb/schema.rb
CHANGED
@@ -18,10 +18,11 @@ create_table :countries do |t|
|
|
18
18
|
t.integer :pop, :null => false # population count
|
19
19
|
t.integer :area, :null => false # area in square km (sq. km)
|
20
20
|
t.references :country # for supra(nationals) n depend(encies)
|
21
|
+
|
22
|
+
## flags (use single int named flags - why? why not?
|
21
23
|
t.boolean :s, :null => false, :default => false # supra(national) flag e.g. eu
|
22
24
|
t.boolean :c, :null => false, :default => false # country flag (is this needed?)
|
23
25
|
t.boolean :d, :null => false, :default => false # dependency flag
|
24
|
-
t.timestamps
|
25
26
|
|
26
27
|
# extras
|
27
28
|
t.string :motor # optional auto motor (vehicle) licene plate
|
@@ -30,6 +31,9 @@ create_table :countries do |t|
|
|
30
31
|
t.string :fifa # optional fifa country code
|
31
32
|
t.string :net # optional internet top level domain (tld)
|
32
33
|
t.string :wikipedia # optional wikipedia page name -- en.wikipedia.org/wiki/<name>
|
34
|
+
|
35
|
+
## timestamp at last
|
36
|
+
t.timestamps
|
33
37
|
end
|
34
38
|
|
35
39
|
|
@@ -58,18 +62,21 @@ create_table :cities do |t|
|
|
58
62
|
t.string :synonyms # comma separated list of synonyms
|
59
63
|
t.references :country, :null => false
|
60
64
|
t.references :region # optional for now
|
65
|
+
t.references :city # optional parent (e.g. metro for city, or city for district)
|
61
66
|
t.integer :pop # optional population count (city proper)
|
62
67
|
t.integer :popm # optional population count (metropolitan/aglomeration)
|
63
68
|
t.integer :area # optional area in square km (sq. km)
|
64
69
|
t.float :lat # optional for now
|
65
70
|
t.float :lng # optional for now
|
71
|
+
|
72
|
+
## flags (use single int named flags - why? why not?
|
66
73
|
t.boolean :m, :null => false, :default => false # metro flag
|
67
74
|
t.boolean :c, :null => false, :default => false # city flag (is this needed?)
|
68
75
|
t.boolean :d, :null => false, :default => false # district flag
|
69
|
-
t.references :city # optional parent (e.g. metro for city, or city for district)
|
70
|
-
t.timestamps
|
71
76
|
|
72
77
|
### t.boolean :capital, :null => false, :default => false # is national captial?
|
78
|
+
|
79
|
+
t.timestamps
|
73
80
|
end
|
74
81
|
|
75
82
|
create_table :tags do |t|
|
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 7
|
10
|
+
version: 0.6.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gerald Bauer
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-12-02 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -55,11 +55,11 @@ dependencies:
|
|
55
55
|
requirements:
|
56
56
|
- - ~>
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
hash:
|
58
|
+
hash: 1
|
59
59
|
segments:
|
60
60
|
- 3
|
61
|
-
-
|
62
|
-
version: "3.
|
61
|
+
- 3
|
62
|
+
version: "3.3"
|
63
63
|
type: :development
|
64
64
|
version_requirements: *id003
|
65
65
|
description: worlddb - world.db command line tool
|
@@ -70,142 +70,85 @@ extensions: []
|
|
70
70
|
|
71
71
|
extra_rdoc_files:
|
72
72
|
- Manifest.txt
|
73
|
-
- db/africa/countries.txt
|
74
|
-
- db/america/br/cities.txt
|
75
|
-
- db/america/br/regions.txt
|
76
|
-
- db/america/ca/cities.txt
|
77
|
-
- db/america/ca/regions.txt
|
78
|
-
- db/america/countries.txt
|
79
|
-
- db/america/mx/cities.txt
|
80
|
-
- db/america/mx/regions.txt
|
81
|
-
- db/america/us/cities.txt
|
82
|
-
- db/america/us/regions.txt
|
83
|
-
- db/america/ve/cities.txt
|
84
|
-
- db/america/ve/regions.txt
|
85
|
-
- db/asia/countries.txt
|
86
|
-
- db/asia/jp/cities.txt
|
87
|
-
- db/europe/at/cities.txt
|
88
|
-
- db/europe/at/regions.txt
|
89
|
-
- db/europe/be/cities.txt
|
90
|
-
- db/europe/be/regions.txt
|
91
|
-
- db/europe/bg/cities.txt
|
92
|
-
- db/europe/by/cities.txt
|
93
|
-
- db/europe/ch/cities.txt
|
94
|
-
- db/europe/countries.txt
|
95
|
-
- db/europe/cy/cities.txt
|
96
|
-
- db/europe/cz/cities.txt
|
97
|
-
- db/europe/cz/regions.txt
|
98
|
-
- db/europe/de/cities.txt
|
99
|
-
- db/europe/de/regions.txt
|
100
|
-
- db/europe/dk/cities.txt
|
101
|
-
- db/europe/ee/cities.txt
|
102
|
-
- db/europe/en/cities.txt
|
103
|
-
- db/europe/en/regions.txt
|
104
|
-
- db/europe/es/cities.txt
|
105
|
-
- db/europe/es/regions.txt
|
106
|
-
- db/europe/fi/cities.txt
|
107
|
-
- db/europe/fr/cities.txt
|
108
|
-
- db/europe/fr/regions.txt
|
109
|
-
- db/europe/gr/cities.txt
|
110
|
-
- db/europe/hr/cities.txt
|
111
|
-
- db/europe/hu/cities.txt
|
112
|
-
- db/europe/ie/cities.txt
|
113
|
-
- db/europe/it/cities.txt
|
114
|
-
- db/europe/lt/cities.txt
|
115
|
-
- db/europe/lv/cities.txt
|
116
|
-
- db/europe/nl/cities.txt
|
117
|
-
- db/europe/no/cities.txt
|
118
|
-
- db/europe/pl/cities.txt
|
119
|
-
- db/europe/pt/cities.txt
|
120
|
-
- db/europe/ro/cities.txt
|
121
|
-
- db/europe/rs/cities.txt
|
122
|
-
- db/europe/ru/cities.txt
|
123
|
-
- db/europe/sc/cities.txt
|
124
|
-
- db/europe/se/cities.txt
|
125
|
-
- db/europe/tr/cities.txt
|
126
|
-
- db/europe/ua/cities.txt
|
127
|
-
- db/europe/wa/cities.txt
|
128
|
-
- db/oceania/au/cities.txt
|
129
|
-
- db/oceania/countries.txt
|
130
73
|
files:
|
131
74
|
- History.markdown
|
132
75
|
- Manifest.txt
|
133
76
|
- README.markdown
|
134
77
|
- Rakefile
|
135
78
|
- bin/worlddb
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
-
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
-
|
161
|
-
-
|
162
|
-
-
|
163
|
-
-
|
164
|
-
-
|
165
|
-
-
|
166
|
-
-
|
167
|
-
-
|
168
|
-
-
|
169
|
-
-
|
170
|
-
-
|
171
|
-
-
|
172
|
-
-
|
173
|
-
-
|
174
|
-
-
|
175
|
-
-
|
176
|
-
-
|
177
|
-
-
|
178
|
-
-
|
179
|
-
-
|
180
|
-
-
|
181
|
-
-
|
182
|
-
-
|
183
|
-
-
|
184
|
-
-
|
185
|
-
-
|
186
|
-
-
|
187
|
-
-
|
188
|
-
-
|
189
|
-
-
|
190
|
-
-
|
191
|
-
-
|
192
|
-
-
|
193
|
-
-
|
194
|
-
-
|
195
|
-
-
|
196
|
-
-
|
197
|
-
-
|
198
|
-
-
|
199
|
-
-
|
200
|
-
-
|
201
|
-
-
|
202
|
-
-
|
203
|
-
-
|
204
|
-
-
|
205
|
-
-
|
206
|
-
-
|
207
|
-
-
|
208
|
-
-
|
79
|
+
- data/africa/countries.txt
|
80
|
+
- data/africa/de.countries.yml
|
81
|
+
- data/africa/en.wikipedia.yml
|
82
|
+
- data/africa/fifa.yml
|
83
|
+
- data/africa/iso3.yml
|
84
|
+
- data/america/br/cities.txt
|
85
|
+
- data/america/br/regions.txt
|
86
|
+
- data/america/ca/cities.txt
|
87
|
+
- data/america/ca/regions.txt
|
88
|
+
- data/america/countries.motor.yml
|
89
|
+
- data/america/countries.txt
|
90
|
+
- data/america/de.countries.yml
|
91
|
+
- data/america/en.wikipedia.yml
|
92
|
+
- data/america/es.countries.yml
|
93
|
+
- data/america/mx/cities.txt
|
94
|
+
- data/america/mx/regions.txt
|
95
|
+
- data/america/us/cities.txt
|
96
|
+
- data/america/us/regions.txt
|
97
|
+
- data/america/ve/cities.txt
|
98
|
+
- data/america/ve/regions.txt
|
99
|
+
- data/asia/countries.txt
|
100
|
+
- data/asia/de.countries.yml
|
101
|
+
- data/asia/en.wikipedia.yml
|
102
|
+
- data/asia/jp/cities.txt
|
103
|
+
- data/europe/at/cities.txt
|
104
|
+
- data/europe/at/regions.txt
|
105
|
+
- data/europe/be/cities.txt
|
106
|
+
- data/europe/be/regions.txt
|
107
|
+
- data/europe/bg/cities.txt
|
108
|
+
- data/europe/by/cities.txt
|
109
|
+
- data/europe/ch/cities.txt
|
110
|
+
- data/europe/countries.txt
|
111
|
+
- data/europe/cy/cities.txt
|
112
|
+
- data/europe/cz/cities.txt
|
113
|
+
- data/europe/cz/regions.txt
|
114
|
+
- data/europe/de.countries.yml
|
115
|
+
- data/europe/de/cities.txt
|
116
|
+
- data/europe/de/regions.txt
|
117
|
+
- data/europe/dk/cities.txt
|
118
|
+
- data/europe/ee/cities.txt
|
119
|
+
- data/europe/en.wikipedia.yml
|
120
|
+
- data/europe/en/cities.txt
|
121
|
+
- data/europe/en/regions.txt
|
122
|
+
- data/europe/es.countries.yml
|
123
|
+
- data/europe/es/cities.txt
|
124
|
+
- data/europe/es/regions.txt
|
125
|
+
- data/europe/fi/cities.txt
|
126
|
+
- data/europe/fr/cities.txt
|
127
|
+
- data/europe/fr/regions.txt
|
128
|
+
- data/europe/gr/cities.txt
|
129
|
+
- data/europe/hr/cities.txt
|
130
|
+
- data/europe/hu/cities.txt
|
131
|
+
- data/europe/ie/cities.txt
|
132
|
+
- data/europe/it/cities.txt
|
133
|
+
- data/europe/lt/cities.txt
|
134
|
+
- data/europe/lv/cities.txt
|
135
|
+
- data/europe/nl/cities.txt
|
136
|
+
- data/europe/no/cities.txt
|
137
|
+
- data/europe/pl/cities.txt
|
138
|
+
- data/europe/pt/cities.txt
|
139
|
+
- data/europe/ro/cities.txt
|
140
|
+
- data/europe/rs/cities.txt
|
141
|
+
- data/europe/ru/cities.txt
|
142
|
+
- data/europe/sc/cities.txt
|
143
|
+
- data/europe/se/cities.txt
|
144
|
+
- data/europe/tr/cities.txt
|
145
|
+
- data/europe/ua/cities.txt
|
146
|
+
- data/europe/wa/cities.txt
|
147
|
+
- data/oceania/au/cities.txt
|
148
|
+
- data/oceania/countries.txt
|
149
|
+
- data/oceania/de.countries.yml
|
150
|
+
- data/oceania/en.wikipedia.yml
|
151
|
+
- data/tags.yml
|
209
152
|
- lib/worlddb.rb
|
210
153
|
- lib/worlddb/cli/opts.rb
|
211
154
|
- lib/worlddb/cli/runner.rb
|
@@ -225,8 +168,8 @@ files:
|
|
225
168
|
- lib/worlddb/utils.rb
|
226
169
|
- lib/worlddb/version.rb
|
227
170
|
homepage: http://geraldb.github.com/world.db
|
228
|
-
licenses:
|
229
|
-
|
171
|
+
licenses:
|
172
|
+
- Public Domain
|
230
173
|
post_install_message:
|
231
174
|
rdoc_options:
|
232
175
|
- --main
|