worlddb 0.8.0 → 1.0.0
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/Manifest.txt +4 -98
- data/Rakefile +1 -6
- data/lib/worlddb/cli/main.rb +170 -0
- data/lib/worlddb/cli/opts.rb +24 -50
- data/lib/worlddb/data/fixtures.rb +168 -0
- data/lib/worlddb/deleter.rb +26 -0
- data/lib/worlddb/reader.rb +8 -61
- data/lib/worlddb/stats.rb +30 -0
- data/lib/worlddb/utils.rb +0 -60
- data/lib/worlddb/version.rb +1 -2
- data/lib/worlddb.rb +24 -184
- metadata +30 -108
- data/data/africa/1_codes/fifa.yml +0 -59
- data/data/africa/1_codes/internet.yml +0 -64
- data/data/africa/1_codes/iso3.yml +0 -57
- data/data/africa/2_names/de.yml +0 -10
- data/data/africa/3_more/en.wikipedia.yml +0 -30
- data/data/africa/3_more/lang.yml +0 -63
- data/data/africa/countries.txt +0 -92
- data/data/america/1_codes/fifa.yml +0 -41
- data/data/america/1_codes/internet.yml +0 -39
- data/data/america/1_codes/iso3.yml +0 -39
- data/data/america/1_codes/motor.yml +0 -26
- data/data/america/2_names/de.yml +0 -31
- data/data/america/2_names/es.yml +0 -30
- data/data/america/3_more/en.wikipedia.yml +0 -9
- data/data/america/3_more/lang.yml +0 -60
- data/data/america/br/regions.txt +0 -27
- data/data/america/ca/cities.txt +0 -48
- data/data/america/ca/regions.txt +0 -28
- data/data/america/countries.txt +0 -70
- data/data/america/mx/cities.txt +0 -32
- data/data/america/mx/regions.txt +0 -54
- data/data/america/us/cities.txt +0 -46
- data/data/america/us/regions.txt +0 -64
- data/data/america/ve/cities.txt +0 -358
- data/data/america/ve/regions.txt +0 -46
- data/data/asia/1_codes/fifa.yml +0 -53
- data/data/asia/1_codes/internet.yml +0 -51
- data/data/asia/1_codes/iso3.yml +0 -51
- data/data/asia/2_names/de.yml +0 -9
- data/data/asia/3_more/en.wikipedia.yml +0 -26
- data/data/asia/3_more/lang.yml +0 -55
- data/data/asia/countries.txt +0 -126
- data/data/asia/jp/cities.txt +0 -3
- data/data/europe/1_codes/fifa.yml +0 -60
- data/data/europe/1_codes/internet.yml +0 -59
- data/data/europe/1_codes/iso3.yml +0 -59
- data/data/europe/1_codes/motor.yml +0 -60
- data/data/europe/2_names/de.yml +0 -42
- data/data/europe/2_names/es.yml +0 -43
- data/data/europe/3_more/en.wikipedia.yml +0 -12
- data/data/europe/3_more/lang.yml +0 -47
- data/data/europe/at/cities.txt +0 -45
- data/data/europe/at/regions.txt +0 -26
- data/data/europe/be/cities.txt +0 -19
- data/data/europe/be/regions.txt +0 -23
- data/data/europe/bg/cities.txt +0 -4
- data/data/europe/by/cities.txt +0 -4
- data/data/europe/ch/cities.txt +0 -4
- data/data/europe/countries.txt +0 -123
- data/data/europe/cy/cities.txt +0 -1
- data/data/europe/cz/cities.txt +0 -26
- data/data/europe/cz/regions.txt +0 -32
- data/data/europe/de/cities.txt +0 -44
- data/data/europe/de/regions.txt +0 -16
- data/data/europe/dk/cities.txt +0 -6
- data/data/europe/ee/cities.txt +0 -2
- data/data/europe/en/cities.txt +0 -32
- data/data/europe/en/regions.txt +0 -21
- data/data/europe/es/cities.txt +0 -17
- data/data/europe/es/regions.txt +0 -26
- data/data/europe/fi/cities.txt +0 -2
- data/data/europe/fr/cities.txt +0 -15
- data/data/europe/fr/regions.txt +0 -32
- data/data/europe/gr/cities.txt +0 -6
- data/data/europe/hr/cities.txt +0 -1
- data/data/europe/hu/cities.txt +0 -2
- data/data/europe/ie/cities.txt +0 -3
- data/data/europe/it/cities.txt +0 -17
- data/data/europe/lt/cities.txt +0 -3
- data/data/europe/lv/cities.txt +0 -4
- data/data/europe/nl/cities.txt +0 -11
- data/data/europe/no/cities.txt +0 -3
- data/data/europe/pl/cities.txt +0 -12
- data/data/europe/pt/cities.txt +0 -6
- data/data/europe/ro/cities.txt +0 -4
- data/data/europe/rs/cities.txt +0 -3
- data/data/europe/ru/cities.txt +0 -14
- data/data/europe/sc/cities.txt +0 -3
- data/data/europe/se/cities.txt +0 -3
- data/data/europe/tr/cities.txt +0 -3
- data/data/europe/ua/cities.txt +0 -9
- data/data/europe/wa/cities.txt +0 -3
- data/data/langs.yml +0 -210
- data/data/oceania/1_codes/fifa.yml +0 -21
- data/data/oceania/1_codes/internet.yml +0 -17
- data/data/oceania/1_codes/iso3.yml +0 -17
- data/data/oceania/2_names/de.yml +0 -7
- data/data/oceania/3_more/en.wikipedia.yml +0 -11
- data/data/oceania/3_more/lang.yml +0 -17
- data/data/oceania/au/cities.txt +0 -2
- data/data/oceania/countries.txt +0 -40
- data/data/tags.1.yml +0 -40
- data/data/tags.3.yml +0 -23
- data/lib/worlddb/cli/runner.rb +0 -113
- data/lib/worlddb/readers/code_reader.rb +0 -34
- data/lib/worlddb/readers/hash_reader.rb +0 -81
- data/lib/worlddb/readers/line_reader.rb +0 -45
- data/lib/worlddb/readers/values_reader.rb +0 -171
data/lib/worlddb/reader.rb
CHANGED
|
@@ -9,8 +9,7 @@ class Reader
|
|
|
9
9
|
|
|
10
10
|
def initialize( logger=nil )
|
|
11
11
|
if logger.nil?
|
|
12
|
-
@logger = Logger.new
|
|
13
|
-
@logger.level = Logger::INFO
|
|
12
|
+
@logger = LogUtils::Logger.new
|
|
14
13
|
else
|
|
15
14
|
@logger = logger
|
|
16
15
|
end
|
|
@@ -18,26 +17,6 @@ class Reader
|
|
|
18
17
|
|
|
19
18
|
attr_reader :logger
|
|
20
19
|
|
|
21
|
-
def run( opts, args )
|
|
22
|
-
|
|
23
|
-
args.each do |arg|
|
|
24
|
-
name = arg # File.basename( arg, '.*' )
|
|
25
|
-
|
|
26
|
-
data_path = opts.load? ? WorldDB.data_path : opts.data_path
|
|
27
|
-
|
|
28
|
-
if opts.countries?
|
|
29
|
-
load_countries_with_include_path( name, data_path )
|
|
30
|
-
elsif opts.regions?
|
|
31
|
-
load_regions_with_include_path( opts.country, name, data_path )
|
|
32
|
-
elsif opts.cities?
|
|
33
|
-
load_cities_with_include_path( opts.country, name, data_path )
|
|
34
|
-
else
|
|
35
|
-
## todo: issue a warning here; no fixture type specified; assume country?
|
|
36
|
-
end
|
|
37
|
-
end # each arg
|
|
38
|
-
|
|
39
|
-
end
|
|
40
|
-
|
|
41
20
|
|
|
42
21
|
def load_with_include_path( name, include_path )
|
|
43
22
|
|
|
@@ -65,60 +44,43 @@ class Reader
|
|
|
65
44
|
## auto-add required country code (from folder structure)
|
|
66
45
|
load_regions_with_include_path( $1, name, include_path )
|
|
67
46
|
else
|
|
68
|
-
|
|
47
|
+
logger.error "unknown world.db fixture type >#{name}<"
|
|
69
48
|
# todo/fix: exit w/ error
|
|
70
49
|
end
|
|
71
50
|
end
|
|
72
51
|
|
|
73
52
|
|
|
74
|
-
def load_builtin( name ) ## convenience helper (requires proper named files w/ convention)
|
|
75
|
-
load_with_include_path( name, WorldDB.data_path )
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
|
|
79
53
|
def load_countries_with_include_path( name, include_path, more_values={} )
|
|
80
54
|
load_fixtures_with_include_path_for( Country, name, include_path, more_values )
|
|
81
55
|
end
|
|
82
56
|
|
|
83
|
-
def load_countries_builtin( name, more_values={} )
|
|
84
|
-
load_countries_with_include_path( name, WorldDB.data_path, more_values )
|
|
85
|
-
end
|
|
86
|
-
|
|
87
57
|
|
|
88
58
|
def load_regions_with_include_path( country_key, name, include_path )
|
|
89
59
|
country = Country.find_by_key!( country_key )
|
|
90
|
-
|
|
60
|
+
logger.info "Country #{country.key} >#{country.title} (#{country.code})<"
|
|
91
61
|
|
|
92
62
|
load_fixtures_with_include_path_for( Region, name, include_path, country_id: country.id )
|
|
93
63
|
end
|
|
94
64
|
|
|
95
|
-
def load_regions_builtin( country_key, name )
|
|
96
|
-
load_regions_with_include_path( country_key, name, WorldDB.data_path )
|
|
97
|
-
end
|
|
98
|
-
|
|
99
65
|
|
|
100
66
|
def load_cities_with_include_path( country_key, name, include_path )
|
|
101
67
|
country = Country.find_by_key!( country_key )
|
|
102
|
-
|
|
68
|
+
logger.info "Country #{country.key} >#{country.title} (#{country.code})<"
|
|
103
69
|
|
|
104
70
|
load_fixtures_with_include_path_for( City, name, include_path, country_id: country.id )
|
|
105
71
|
end
|
|
106
72
|
|
|
107
|
-
def load_cities_builtin( country_key, name )
|
|
108
|
-
load_cities_with_include_path( country_key, name, WorldDB.data_path )
|
|
109
|
-
end
|
|
110
|
-
|
|
111
73
|
|
|
112
74
|
def load_langs_with_include_path( name, include_path )
|
|
113
75
|
path = "#{include_path}/#{name}.yml"
|
|
114
76
|
|
|
115
|
-
|
|
77
|
+
logger.info "*** parsing data '#{name}' (#{path})..."
|
|
116
78
|
|
|
117
79
|
reader = HashReader.new( logger, path )
|
|
118
80
|
|
|
119
81
|
reader.each do |key, value|
|
|
120
82
|
|
|
121
|
-
|
|
83
|
+
logger.debug "adding lang >>#{key}<< >>#{value}<<..."
|
|
122
84
|
|
|
123
85
|
lang_key = key.strip
|
|
124
86
|
lang_title = value.strip
|
|
@@ -144,10 +106,6 @@ class Reader
|
|
|
144
106
|
|
|
145
107
|
Prop.create_from_worlddb_fixture!( name, path )
|
|
146
108
|
end
|
|
147
|
-
|
|
148
|
-
def load_langs_builtin( name )
|
|
149
|
-
load_langs_with_include_path( name, WorldDB.data_path )
|
|
150
|
-
end
|
|
151
109
|
|
|
152
110
|
|
|
153
111
|
def load_tags_with_include_path( name, include_path, more_values={} )
|
|
@@ -205,10 +163,6 @@ class Reader
|
|
|
205
163
|
Prop.create_from_worlddb_fixture!( name, path )
|
|
206
164
|
end # method load_tags_with_include_path
|
|
207
165
|
|
|
208
|
-
def load_tags_builtin( name, include_path, more_values={} )
|
|
209
|
-
load_tags_with_include_path( name, WorldDB.data_path, more_values )
|
|
210
|
-
end
|
|
211
|
-
|
|
212
166
|
|
|
213
167
|
def load_usages_with_include_path( name, include_path )
|
|
214
168
|
path = "#{include_path}/#{name}.yml"
|
|
@@ -237,10 +191,7 @@ class Reader
|
|
|
237
191
|
|
|
238
192
|
Prop.create_from_worlddb_fixture!( name, path )
|
|
239
193
|
end
|
|
240
|
-
|
|
241
|
-
def load_usages_builtin( name )
|
|
242
|
-
load_usages_with_include_path( name, WorldDB.data_path )
|
|
243
|
-
end
|
|
194
|
+
|
|
244
195
|
|
|
245
196
|
def load_xxx_with_include_path( xxx, name, include_path )
|
|
246
197
|
path = "#{include_path}/#{name}.yml"
|
|
@@ -258,10 +209,6 @@ class Reader
|
|
|
258
209
|
Prop.create_from_worlddb_fixture!( name, path )
|
|
259
210
|
end
|
|
260
211
|
|
|
261
|
-
def load_xxx_builtin( xxx, name )
|
|
262
|
-
load_xxx_with_include_path( xxx, name, WorldDB.data_path )
|
|
263
|
-
end
|
|
264
|
-
|
|
265
212
|
|
|
266
213
|
private
|
|
267
214
|
def load_fixtures_with_include_path_for( clazz, name, include_path, more_values={} ) # load from file system
|
|
@@ -380,7 +327,7 @@ private
|
|
|
380
327
|
end
|
|
381
328
|
|
|
382
329
|
# issue warning: unknown type for value
|
|
383
|
-
|
|
330
|
+
logger.warn "unknown type for value >#{value}<"
|
|
384
331
|
end
|
|
385
332
|
end # each value
|
|
386
333
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module WorldDB
|
|
4
|
+
|
|
5
|
+
class Stats
|
|
6
|
+
include WorldDB::Models
|
|
7
|
+
|
|
8
|
+
def tables
|
|
9
|
+
puts "Stats:"
|
|
10
|
+
puts " #{'%5d' % Country.count} countries (#{Country.where(s: true).count} supras, #{Country.where(d:true).count} deps)"
|
|
11
|
+
puts " #{'%5d' % Region.count} regions"
|
|
12
|
+
puts " #{'%5d' % City.where(m: true).where(c: false).count} metros"
|
|
13
|
+
puts " #{'%5d' % City.where(c: true).count} cities (#{City.where(c: true).where(m: true).count} metros)"
|
|
14
|
+
puts " #{'%5d' % City.where(d: true).count} districts"
|
|
15
|
+
puts " #{'%5d' % Tag.count} tags"
|
|
16
|
+
puts " #{'%5d' % Tagging.count} taggings"
|
|
17
|
+
puts " #{'%5d' % Lang.count} langs"
|
|
18
|
+
puts " #{'%5d' % Usage.count} usages"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def props
|
|
22
|
+
puts "Props:"
|
|
23
|
+
Prop.order( 'created_at asc' ).all.each do |prop|
|
|
24
|
+
puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end # class Stats
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
end # module WorldDB
|
data/lib/worlddb/utils.rb
CHANGED
|
@@ -16,63 +16,3 @@ class Time
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
end # class Time
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class File
|
|
22
|
-
def self.read_utf8( path )
|
|
23
|
-
open( path, 'r:bom|utf-8' ) do |file|
|
|
24
|
-
file.read
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end # class File
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
############
|
|
31
|
-
### fix/todo: share helper for all text readers/parsers- where to put it?
|
|
32
|
-
###
|
|
33
|
-
|
|
34
|
-
def title_esc_regex( title_unescaped )
|
|
35
|
-
|
|
36
|
-
## escape regex special chars e.g. . to \. and ( to \( etc.
|
|
37
|
-
# e.g. Benfica Lis.
|
|
38
|
-
# e.g. Club Atlético Colón (Santa Fe)
|
|
39
|
-
|
|
40
|
-
## NB: cannot use Regexp.escape! will escape space '' to '\ '
|
|
41
|
-
## title = Regexp.escape( title_unescaped )
|
|
42
|
-
title = title_unescaped.gsub( '.', '\.' )
|
|
43
|
-
title = title.gsub( '(', '\(' )
|
|
44
|
-
title = title.gsub( ')', '\)' )
|
|
45
|
-
|
|
46
|
-
## match accented char with or without accents
|
|
47
|
-
## add (ü|ue) etc.
|
|
48
|
-
## also make - optional change to (-| ) e.g. Blau-Weiss == Blau Weiss
|
|
49
|
-
|
|
50
|
-
## todo: add some more
|
|
51
|
-
## see http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references for more
|
|
52
|
-
##
|
|
53
|
-
## reuse for all readers!
|
|
54
|
-
|
|
55
|
-
alternatives = [
|
|
56
|
-
['-', '(-| )'],
|
|
57
|
-
['ß', '(ß|ss)'],
|
|
58
|
-
['æ', '(æ|ae)'],
|
|
59
|
-
['á', '(á|a)'], ## e.g. Bogotá
|
|
60
|
-
['ã', '(ã|a)'], ## e.g São Paulo
|
|
61
|
-
['ä', '(ä|ae)'], ## add a ?
|
|
62
|
-
['Ö', '(Ö|Oe)'], ## e.g. Österreich
|
|
63
|
-
['ö', '(ö|oe)'], ## add o ?
|
|
64
|
-
['ó', '(ó|o)'], ## e.g. Colón
|
|
65
|
-
['ü', '(ü|ue)'], ## add u ?
|
|
66
|
-
['é', '(é|e)'], ## e.g. Vélez
|
|
67
|
-
['ê', '(ê|e)'], ## e.g. Grêmio
|
|
68
|
-
['ñ', '(ñ|n)'], ## e.g. Porteño
|
|
69
|
-
['ú', '(ú|u)'] ## e.g. Fútbol
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
alternatives.each do |alt|
|
|
73
|
-
title = title.gsub( alt[0], alt[1] )
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
title
|
|
77
|
-
end
|
|
78
|
-
|
data/lib/worlddb/version.rb
CHANGED
data/lib/worlddb.rb
CHANGED
|
@@ -12,13 +12,15 @@ require 'optparse'
|
|
|
12
12
|
require 'fileutils'
|
|
13
13
|
require 'erb'
|
|
14
14
|
|
|
15
|
-
#
|
|
15
|
+
# 3rd party gems / libs
|
|
16
16
|
|
|
17
17
|
require 'active_record' ## todo: add sqlite3? etc.
|
|
18
18
|
|
|
19
|
+
require 'logutils'
|
|
20
|
+
require 'textutils'
|
|
19
21
|
|
|
20
|
-
# our own code
|
|
21
22
|
|
|
23
|
+
# our own code
|
|
22
24
|
|
|
23
25
|
require 'worlddb/version'
|
|
24
26
|
|
|
@@ -32,13 +34,13 @@ require 'worlddb/models/lang'
|
|
|
32
34
|
require 'worlddb/models/usage'
|
|
33
35
|
require 'worlddb/schema' # NB: requires worlddb/models (include WorldDB::Models)
|
|
34
36
|
require 'worlddb/utils'
|
|
35
|
-
require 'worlddb/readers/code_reader'
|
|
36
|
-
require 'worlddb/readers/line_reader'
|
|
37
|
-
require 'worlddb/readers/values_reader'
|
|
38
|
-
require 'worlddb/readers/hash_reader'
|
|
39
37
|
require 'worlddb/reader'
|
|
40
|
-
require 'worlddb/
|
|
41
|
-
require 'worlddb/
|
|
38
|
+
require 'worlddb/deleter'
|
|
39
|
+
require 'worlddb/stats'
|
|
40
|
+
|
|
41
|
+
require 'worlddb/data/fixtures'
|
|
42
|
+
|
|
43
|
+
|
|
42
44
|
|
|
43
45
|
module WorldDB
|
|
44
46
|
|
|
@@ -49,147 +51,25 @@ module WorldDB
|
|
|
49
51
|
def self.root
|
|
50
52
|
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
|
51
53
|
end
|
|
52
|
-
|
|
53
|
-
# builtin path to fixture data
|
|
54
|
-
def self.data_path
|
|
55
|
-
"#{root}/data"
|
|
56
|
-
end
|
|
57
54
|
|
|
58
55
|
def self.main
|
|
59
|
-
|
|
56
|
+
require 'worlddb/cli/main'
|
|
57
|
+
## Runner.new.run(ARGV) - old code
|
|
60
58
|
end
|
|
61
59
|
|
|
62
60
|
def self.create
|
|
63
61
|
CreateDB.up
|
|
64
62
|
end
|
|
65
63
|
|
|
66
|
-
def self.fixtures # all builtin fixtures; helper for covenience
|
|
67
|
-
tag_fixtures +
|
|
68
|
-
country_fixtures +
|
|
69
|
-
lang_fixtures +
|
|
70
|
-
africa_fixtures +
|
|
71
|
-
america_fixtures +
|
|
72
|
-
europe_fixtures +
|
|
73
|
-
asia_fixtures +
|
|
74
|
-
oceania_fixtures
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def self.tag_fixtures
|
|
79
|
-
['tags.1', 'tags.3']
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
def self.country_fixtures
|
|
83
|
-
['africa/countries',
|
|
84
|
-
'america/countries',
|
|
85
|
-
'asia/countries',
|
|
86
|
-
'europe/countries',
|
|
87
|
-
'oceania/countries']
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
def self.lang_fixtures
|
|
91
|
-
['langs',
|
|
92
|
-
'africa/3_more/lang',
|
|
93
|
-
'america/3_more/lang',
|
|
94
|
-
'asia/3_more/lang',
|
|
95
|
-
'europe/3_more/lang',
|
|
96
|
-
'oceania/3_more/lang'
|
|
97
|
-
]
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
def self.africa_fixtures
|
|
101
|
-
['1_codes/fifa',
|
|
102
|
-
'1_codes/internet',
|
|
103
|
-
'1_codes/iso3'].map { |path| "africa/#{path}" }
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
def self.america_fixtures
|
|
107
|
-
['1_codes/fifa',
|
|
108
|
-
'1_codes/internet',
|
|
109
|
-
'1_codes/iso3',
|
|
110
|
-
'1_codes/motor',
|
|
111
|
-
'br/regions',
|
|
112
|
-
'ca/regions',
|
|
113
|
-
'ca/cities',
|
|
114
|
-
'mx/regions',
|
|
115
|
-
'mx/cities',
|
|
116
|
-
'us/regions',
|
|
117
|
-
'us/cities',
|
|
118
|
-
've/regions',
|
|
119
|
-
've/cities'].map { |path| "america/#{path}" }
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def self.asia_fixtures
|
|
123
|
-
['1_codes/fifa',
|
|
124
|
-
'1_codes/internet',
|
|
125
|
-
'1_codes/iso3',
|
|
126
|
-
'jp/cities'].map { |path| "asia/#{path}" }
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def self.europe_fixtures
|
|
130
|
-
['1_codes/fifa',
|
|
131
|
-
'1_codes/internet',
|
|
132
|
-
'1_codes/iso3',
|
|
133
|
-
'1_codes/motor',
|
|
134
|
-
'at/regions',
|
|
135
|
-
'at/cities',
|
|
136
|
-
'be/regions',
|
|
137
|
-
'be/cities',
|
|
138
|
-
'bg/cities',
|
|
139
|
-
'by/cities',
|
|
140
|
-
'ch/cities',
|
|
141
|
-
'cy/cities',
|
|
142
|
-
'cz/regions',
|
|
143
|
-
'cz/cities',
|
|
144
|
-
'de/regions',
|
|
145
|
-
'de/cities',
|
|
146
|
-
'dk/cities',
|
|
147
|
-
'ee/cities',
|
|
148
|
-
'en/regions',
|
|
149
|
-
'en/cities',
|
|
150
|
-
'es/regions',
|
|
151
|
-
'es/cities',
|
|
152
|
-
'fi/cities',
|
|
153
|
-
'fr/regions',
|
|
154
|
-
'fr/cities',
|
|
155
|
-
'gr/cities',
|
|
156
|
-
'hr/cities',
|
|
157
|
-
'hu/cities',
|
|
158
|
-
'ie/cities',
|
|
159
|
-
'it/cities',
|
|
160
|
-
'lt/cities',
|
|
161
|
-
'lv/cities',
|
|
162
|
-
'nl/cities',
|
|
163
|
-
'no/cities',
|
|
164
|
-
'pl/cities',
|
|
165
|
-
'pt/cities',
|
|
166
|
-
'ro/cities',
|
|
167
|
-
'rs/cities',
|
|
168
|
-
'ru/cities',
|
|
169
|
-
'sc/cities',
|
|
170
|
-
'se/cities',
|
|
171
|
-
'tr/cities',
|
|
172
|
-
'ua/cities',
|
|
173
|
-
'wa/cities'].map { |path| "europe/#{path}" }
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
def self.oceania_fixtures
|
|
177
|
-
['1_codes/fifa',
|
|
178
|
-
'1_codes/internet',
|
|
179
|
-
'1_codes/iso3',
|
|
180
|
-
'au/cities'].map { |path| "oceania/#{path}" }
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
## todo/fix: rename to load/load_all - why? why not?? or just add an alias?
|
|
184
64
|
|
|
185
|
-
def self.read( ary )
|
|
65
|
+
def self.read( ary, include_path )
|
|
186
66
|
reader = Reader.new
|
|
187
67
|
ary.each do |name|
|
|
188
|
-
reader.
|
|
68
|
+
reader.load_with_include_path( name, include_path )
|
|
189
69
|
end
|
|
190
70
|
end
|
|
191
71
|
|
|
192
|
-
def self.read_all # load all builtins (using plain text reader); helper for convenience
|
|
72
|
+
def self.read_all( include_path ) # load all builtins (using plain text reader); helper for convenience
|
|
193
73
|
reader = Reader.new
|
|
194
74
|
|
|
195
75
|
# too big for heroku free db plan (10,000 record limit)
|
|
@@ -198,35 +78,18 @@ module WorldDB
|
|
|
198
78
|
'america/ve/cities'
|
|
199
79
|
]
|
|
200
80
|
|
|
201
|
-
ary =
|
|
81
|
+
ary = Fixtures.all - fixture_excludes
|
|
202
82
|
|
|
203
83
|
ary.each do |name|
|
|
204
|
-
reader.
|
|
84
|
+
reader.load_with_include_path( name, include_path )
|
|
205
85
|
end # each name
|
|
206
|
-
end # method
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
##
|
|
211
|
-
|
|
212
|
-
## make models available in worlddb module by default with namespace
|
|
213
|
-
# e.g. lets you use City instead of Models::City
|
|
214
|
-
include WorldDB::Models
|
|
215
|
-
|
|
216
|
-
def run( args=[] )
|
|
217
|
-
# for now delete all tables
|
|
218
|
-
|
|
219
|
-
Tagging.delete_all
|
|
220
|
-
Tag.delete_all
|
|
221
|
-
City.delete_all
|
|
222
|
-
Region.delete_all
|
|
223
|
-
Country.delete_all
|
|
224
|
-
Usage.delete_all
|
|
225
|
-
Lang.delete_all
|
|
226
|
-
Prop.delete_all
|
|
227
|
-
end
|
|
228
|
-
|
|
86
|
+
end # method read_all
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def self.read_setup( setup, include_path )
|
|
90
|
+
## fix: to be done (see sport.db.ruby)
|
|
229
91
|
end
|
|
92
|
+
|
|
230
93
|
|
|
231
94
|
# delete ALL records (use with care!)
|
|
232
95
|
def self.delete!
|
|
@@ -234,30 +97,7 @@ module WorldDB
|
|
|
234
97
|
Deleter.new.run
|
|
235
98
|
end # method delete!
|
|
236
99
|
|
|
237
|
-
|
|
238
|
-
include WorldDB::Models
|
|
239
|
-
|
|
240
|
-
def tables
|
|
241
|
-
puts "Stats:"
|
|
242
|
-
puts " #{'%5d' % Country.count} countries (#{Country.where(s: true).count} supras, #{Country.where(d:true).count} deps)"
|
|
243
|
-
puts " #{'%5d' % Region.count} regions"
|
|
244
|
-
puts " #{'%5d' % City.where(m: true).where(c: false).count} metros"
|
|
245
|
-
puts " #{'%5d' % City.where(c: true).count} cities (#{City.where(c: true).where(m: true).count} metros)"
|
|
246
|
-
puts " #{'%5d' % City.where(d: true).count} districts"
|
|
247
|
-
puts " #{'%5d' % Tag.count} tags"
|
|
248
|
-
puts " #{'%5d' % Tagging.count} taggings"
|
|
249
|
-
puts " #{'%5d' % Lang.count} langs"
|
|
250
|
-
puts " #{'%5d' % Usage.count} usages"
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
def props
|
|
254
|
-
puts "Props:"
|
|
255
|
-
Prop.order( 'created_at asc' ).all.each do |prop|
|
|
256
|
-
puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
|
|
257
|
-
end
|
|
258
|
-
end
|
|
259
|
-
end
|
|
260
|
-
|
|
100
|
+
|
|
261
101
|
def self.stats
|
|
262
102
|
stats = Stats.new
|
|
263
103
|
stats.tables
|