worlddb 2.0.5 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/worlddb/models/country.rb +9 -0
- data/lib/worlddb/models/country_comp.rb +6 -0
- data/lib/worlddb/reader.rb +60 -15
- data/lib/worlddb/reader_file.rb +6 -0
- data/lib/worlddb/reader_zip.rb +6 -0
- data/lib/worlddb/schema.rb +8 -4
- data/lib/worlddb/version.rb +1 -1
- metadata +72 -47
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45f7ea9e8342b1543e5b5ffc4a3248eb556f3ba2
|
4
|
+
data.tar.gz: 8e8fc8668c5ff107626dc1300212fad1cf7b84cc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fef9a54a76351aa639ce10ed5e423daec71aef3b366ec9a0b9b457751b8f12170a2fde3433f0a36bcb9996bed6959c741ed3246091f433725ac6442ac1564df5
|
7
|
+
data.tar.gz: 8e3e5f08bf075a1da28d5af49e252798dae7383a30fff7e5e5d368babb8e15736729eac3dce83245407b950127ff775c6b0d29d4ea069f0810210765ca61878c
|
@@ -42,6 +42,15 @@ class Country < ActiveRecord::Base
|
|
42
42
|
scope :by_pop, ->{ order( 'pop desc' ) } # order by pop(ulation)
|
43
43
|
scope :by_area, ->{ order( 'area desc') } # order by area (in square km)
|
44
44
|
|
45
|
+
scope :by_num, ->{ order( 'num asc' ) } # order by numeric country code
|
46
|
+
scope :by_alpha2, ->{ order( 'alpha2 asc' ) }
|
47
|
+
scope :by_alpha3, ->{ order( 'alpha2 asc' ) }
|
48
|
+
scope :by_fifa, ->{ order( 'fifa asc' ) } # football
|
49
|
+
scope :by_ioc, ->{ order( 'ioc asc' ) } # olympics
|
50
|
+
scope :by_motor, ->{ order( 'motor asc' ) } # designated signs; motor vehicle license plate
|
51
|
+
scope :by_net, ->{ order( 'net asc' ) } # internet cc top level domain; ccTLD
|
52
|
+
|
53
|
+
|
45
54
|
before_create :on_create
|
46
55
|
before_update :on_update
|
47
56
|
|
@@ -15,6 +15,12 @@ class Country
|
|
15
15
|
|
16
16
|
scope :by_title, ->{ order( 'name asc' ) } # order by title (a-z)
|
17
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
|
+
|
18
24
|
|
19
25
|
def synonyms() alt_names; end
|
20
26
|
def synonyms=(value) self.alt_names = value; end
|
data/lib/worlddb/reader.rb
CHANGED
@@ -53,14 +53,13 @@ class ReaderBase
|
|
53
53
|
## use match_usage( name ) - why? why not?? ???
|
54
54
|
r = create_usage_reader( name )
|
55
55
|
r.read()
|
56
|
-
elsif name =~ /\/fifa/
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
load_xxx( 'motor', name )
|
56
|
+
elsif name =~ /\/fifa/ ||
|
57
|
+
name =~ /\/fips/ ||
|
58
|
+
name =~ /\/internet/ ||
|
59
|
+
name =~ /\/ioc/ ||
|
60
|
+
name =~ /\/iso/ ||
|
61
|
+
name =~ /\/motor/
|
62
|
+
load_codes( name )
|
64
63
|
elsif name =~ /^tag.*\.\d$/
|
65
64
|
## todo: pass along opts too
|
66
65
|
## use match_tags( name ) - why? why not?? ???
|
@@ -163,16 +162,62 @@ class ReaderBase
|
|
163
162
|
end # each lines
|
164
163
|
end # load_continent_defs
|
165
164
|
|
166
|
-
|
167
|
-
|
168
|
-
reader = create_hash_reader( name )
|
165
|
+
def load_codes( name )
|
166
|
+
reader = create_line_reader( name )
|
169
167
|
|
170
|
-
reader.
|
171
|
-
|
172
|
-
|
173
|
-
|
168
|
+
reader.each_line do |line|
|
169
|
+
|
170
|
+
values = line.split(',')
|
171
|
+
|
172
|
+
logger.debug '[>' + values.join( '<|>' ) + '<]'
|
173
|
+
|
174
|
+
if name =~ /iso/
|
175
|
+
# special case for iso
|
176
|
+
# country ref, alpha2, alpha3, num
|
177
|
+
country_name = values[0].strip
|
178
|
+
else
|
179
|
+
# code, country ref
|
180
|
+
country_name = values[1].strip
|
181
|
+
end
|
182
|
+
|
183
|
+
## try to find country
|
184
|
+
cty = Country.find_by_name( country_name )
|
185
|
+
if cty.nil?
|
186
|
+
## retry: remove all () enclosed
|
187
|
+
cty = Country.find_by_name( country_name.gsub( /\([^)]+\)/, '' ).strip )
|
188
|
+
end
|
189
|
+
|
190
|
+
if cty.nil?
|
191
|
+
logger.warn "no country match found for >#{country_name}<; skipping line; in [#{name}]"
|
192
|
+
next
|
193
|
+
end
|
194
|
+
|
195
|
+
if name =~ /\/fifa/
|
196
|
+
cty.fifa = values[0].strip
|
197
|
+
elsif name =~ /\/fips/
|
198
|
+
cty.fips = values[0].strip
|
199
|
+
elsif name =~ /\/internet/
|
200
|
+
# NOTE: remove (optional) leading . e.g. .at becomes at
|
201
|
+
cty.net = values[0].sub( /^\s*\./,'' ).strip
|
202
|
+
elsif name =~ /\/ioc/
|
203
|
+
cty.ioc = values[0].strip
|
204
|
+
elsif name =~ /\/motor/
|
205
|
+
cty.motor = values[0].strip
|
206
|
+
elsif name =~ /\/iso/
|
207
|
+
cty.alpha2 = values[1].strip
|
208
|
+
cty.alpha3 = values[2].strip
|
209
|
+
# NOTE: num is a string!!! use (rename to) num_str - why? why not?
|
210
|
+
cty.num = values[3].strip
|
211
|
+
else
|
212
|
+
logger.warn "warn: unknown country code type; skipping line; in [#{name}]"
|
213
|
+
next
|
214
|
+
end
|
215
|
+
|
216
|
+
cty.save!
|
174
217
|
end
|
218
|
+
|
175
219
|
end
|
176
220
|
|
221
|
+
|
177
222
|
end # class ReaderBase
|
178
223
|
end # module WorldDb
|
data/lib/worlddb/reader_file.rb
CHANGED
@@ -69,6 +69,12 @@ class Reader < ReaderBase
|
|
69
69
|
ValuesReader.from_file( path, more_attribs )
|
70
70
|
end
|
71
71
|
|
72
|
+
def create_line_reader( name )
|
73
|
+
path = "#{@include_path}/#{name}.txt"
|
74
|
+
logger.info "parsing data (line) '#{name}' (#{path})..."
|
75
|
+
|
76
|
+
LineReader.from_file( path )
|
77
|
+
end
|
72
78
|
|
73
79
|
# def create_tag_reader( name )
|
74
80
|
# ## fix: change to new from_file() style
|
data/lib/worlddb/reader_zip.rb
CHANGED
@@ -114,6 +114,12 @@ class ZipReader < ReaderBase
|
|
114
114
|
ValuesReader.from_zip( @zip_file, path, more_attribs )
|
115
115
|
end
|
116
116
|
|
117
|
+
def create_line_reader( name )
|
118
|
+
path = name_to_zip_entry_path( name )
|
119
|
+
logger.info "parsing data (line) in zip '#{name}' (#{path})..."
|
120
|
+
|
121
|
+
LineReader.from_zip( @zip_file, path )
|
122
|
+
end
|
117
123
|
|
118
124
|
# def create_tag_reader( name )
|
119
125
|
# ## fix: change to new from_file() style
|
data/lib/worlddb/schema.rb
CHANGED
@@ -92,12 +92,16 @@ create_table :countries do |t|
|
|
92
92
|
t.boolean :c, null: false, default: false # country flag (is this needed?)
|
93
93
|
t.boolean :d, null: false, default: false # dependency flag
|
94
94
|
|
95
|
-
# extras
|
96
|
-
t.string :motor # optional
|
97
|
-
t.string :
|
98
|
-
t.string :
|
95
|
+
# extras - country codes
|
96
|
+
t.string :motor # optional motor (vehicle) licene plate code (bumper sticker)
|
97
|
+
t.string :alpha2 # optional iso two letter country code
|
98
|
+
t.string :alpha3 # optional iso three letter country code
|
99
|
+
t.string :num # optional iso numeric country code - NOTE: same numeric code as string!!! e.g. 043 etc.
|
99
100
|
t.string :fifa # optional fifa country code
|
101
|
+
t.string :ioc
|
102
|
+
t.string :fips
|
100
103
|
t.string :net # optional internet top level domain (tld)
|
104
|
+
|
101
105
|
t.string :wikipedia # optional wikipedia page name -- en.wikipedia.org/wiki/<name>
|
102
106
|
|
103
107
|
## timestamp at last
|
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED
@@ -1,115 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.6
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gerald Bauer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-16 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: props
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
28
|
name: logutils
|
27
|
-
requirement:
|
28
|
-
none: false
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :runtime
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: textutils
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: 0.9.9
|
44
48
|
type: :runtime
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.9
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: tagutils
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :runtime
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: gli
|
60
|
-
requirement:
|
61
|
-
none: false
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
62
72
|
requirements:
|
63
|
-
- -
|
73
|
+
- - ">="
|
64
74
|
- !ruby/object:Gem::Version
|
65
75
|
version: '2.9'
|
66
76
|
type: :runtime
|
67
77
|
prerelease: false
|
68
|
-
version_requirements:
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.9'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rubyzip
|
71
|
-
requirement:
|
72
|
-
none: false
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
73
86
|
requirements:
|
74
|
-
- -
|
87
|
+
- - ">="
|
75
88
|
- !ruby/object:Gem::Version
|
76
89
|
version: '0'
|
77
90
|
type: :runtime
|
78
91
|
prerelease: false
|
79
|
-
version_requirements:
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
80
97
|
- !ruby/object:Gem::Dependency
|
81
98
|
name: activerecord
|
82
|
-
requirement:
|
83
|
-
none: false
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
84
100
|
requirements:
|
85
|
-
- -
|
101
|
+
- - ">="
|
86
102
|
- !ruby/object:Gem::Version
|
87
103
|
version: '0'
|
88
104
|
type: :runtime
|
89
105
|
prerelease: false
|
90
|
-
version_requirements:
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
91
111
|
- !ruby/object:Gem::Dependency
|
92
112
|
name: rdoc
|
93
|
-
requirement:
|
94
|
-
none: false
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
95
114
|
requirements:
|
96
|
-
- - ~>
|
115
|
+
- - "~>"
|
97
116
|
- !ruby/object:Gem::Version
|
98
117
|
version: '4.0'
|
99
118
|
type: :development
|
100
119
|
prerelease: false
|
101
|
-
version_requirements:
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '4.0'
|
102
125
|
- !ruby/object:Gem::Dependency
|
103
126
|
name: hoe
|
104
|
-
requirement:
|
105
|
-
none: false
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
106
128
|
requirements:
|
107
|
-
- - ~>
|
129
|
+
- - "~>"
|
108
130
|
- !ruby/object:Gem::Version
|
109
131
|
version: '3.13'
|
110
132
|
type: :development
|
111
133
|
prerelease: false
|
112
|
-
version_requirements:
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.13'
|
113
139
|
description: worlddb - world.db command line tool
|
114
140
|
email: openmundi@googlegroups.com
|
115
141
|
executables:
|
@@ -120,6 +146,7 @@ extra_rdoc_files:
|
|
120
146
|
- Manifest.txt
|
121
147
|
- README.md
|
122
148
|
files:
|
149
|
+
- ".gemtest"
|
123
150
|
- HISTORY.md
|
124
151
|
- Manifest.txt
|
125
152
|
- README.md
|
@@ -167,33 +194,31 @@ files:
|
|
167
194
|
- test/test_model_country.rb
|
168
195
|
- test/test_model_region.rb
|
169
196
|
- test/test_models.rb
|
170
|
-
- .gemtest
|
171
197
|
homepage: https://github.com/worlddb/world.db.ruby
|
172
198
|
licenses:
|
173
199
|
- Public Domain
|
200
|
+
metadata: {}
|
174
201
|
post_install_message:
|
175
202
|
rdoc_options:
|
176
|
-
- --main
|
203
|
+
- "--main"
|
177
204
|
- README.md
|
178
205
|
require_paths:
|
179
206
|
- lib
|
180
207
|
required_ruby_version: !ruby/object:Gem::Requirement
|
181
|
-
none: false
|
182
208
|
requirements:
|
183
|
-
- -
|
209
|
+
- - ">="
|
184
210
|
- !ruby/object:Gem::Version
|
185
211
|
version: 1.9.2
|
186
212
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
|
-
none: false
|
188
213
|
requirements:
|
189
|
-
- -
|
214
|
+
- - ">="
|
190
215
|
- !ruby/object:Gem::Version
|
191
216
|
version: '0'
|
192
217
|
requirements: []
|
193
218
|
rubyforge_project:
|
194
|
-
rubygems_version:
|
219
|
+
rubygems_version: 2.4.2
|
195
220
|
signing_key:
|
196
|
-
specification_version:
|
221
|
+
specification_version: 4
|
197
222
|
summary: worlddb - world.db command line tool
|
198
223
|
test_files:
|
199
224
|
- test/test_model_comp.rb
|