worlddb 2.0.6 → 2.0.7
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.
- checksums.yaml +4 -4
- data/lib/worlddb/reader.rb +47 -9
- data/lib/worlddb/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af58d58c38775a19ef1a319c7a2964dfb38f690d
|
4
|
+
data.tar.gz: 5370d2cd74dab599b22b62413fffdb57372d259d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f59a8cf313525cb89e6d7ebfac67e6bc2329b26cc17d3ee0ecaf5e026298ab43a50c6cfb6163e88b23fabdc34a656e0c77720e90a917a1daa127b2f3183cb325
|
7
|
+
data.tar.gz: f030026f39270272136a0b68556c093c4a5264e670c088235cbfad7ac88e6fae5e5c687161654acf0c5411af3c4e19c7dc82c8bb6c1810402cf1aec0fc50f81e
|
data/lib/worlddb/reader.rb
CHANGED
@@ -154,14 +154,15 @@ class ReaderBase
|
|
154
154
|
logger.debug "create Continent:"
|
155
155
|
rec = Continent.new
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
logger.debug attribs.to_json
|
159
|
-
|
159
|
+
|
160
160
|
rec.update_attributes!( attribs )
|
161
161
|
|
162
162
|
end # each lines
|
163
163
|
end # load_continent_defs
|
164
164
|
|
165
|
+
|
165
166
|
def load_codes( name )
|
166
167
|
reader = create_line_reader( name )
|
167
168
|
|
@@ -181,12 +182,8 @@ class ReaderBase
|
|
181
182
|
end
|
182
183
|
|
183
184
|
## try to find country
|
184
|
-
cty =
|
185
|
-
|
186
|
-
## retry: remove all () enclosed
|
187
|
-
cty = Country.find_by_name( country_name.gsub( /\([^)]+\)/, '' ).strip )
|
188
|
-
end
|
189
|
-
|
185
|
+
cty = find_country( country_name )
|
186
|
+
|
190
187
|
if cty.nil?
|
191
188
|
logger.warn "no country match found for >#{country_name}<; skipping line; in [#{name}]"
|
192
189
|
next
|
@@ -215,8 +212,49 @@ class ReaderBase
|
|
215
212
|
|
216
213
|
cty.save!
|
217
214
|
end
|
215
|
+
end # method load_codes
|
216
|
+
|
217
|
+
|
218
|
+
####
|
219
|
+
# helper methods
|
220
|
+
##
|
221
|
+
## todo: move to country model !!!!!!
|
222
|
+
## find a good name Country.find not really possible
|
223
|
+
## superfind ?? use search!!! search_by_name() Country.search() or lookup?
|
224
|
+
##
|
225
|
+
## todo: also add City.search_by_name etc. !!!
|
226
|
+
|
227
|
+
def find_country( country_name )
|
228
|
+
|
229
|
+
name = country_name.strip
|
230
|
+
|
231
|
+
## 1) first try 1:1 (exact) match
|
232
|
+
cty = Country.find_by_name( name ) # NOTE: assume AR escapes quotes in name ??
|
233
|
+
if cty.nil?
|
234
|
+
## 2) retry: remove all () enclosed
|
235
|
+
name = name.gsub( /\([^)]+\)/, '' ).strip
|
236
|
+
cty = Country.find_by_name( name )
|
237
|
+
|
238
|
+
### NOTE: escape ' for sql like clause
|
239
|
+
## for now use '' for escapes, that is, double quotes
|
240
|
+
## check - working for postgresql n sqlite??
|
241
|
+
name_esc = name.gsub( /'/, "''" )
|
242
|
+
|
243
|
+
## 3) retry: use SQL like match
|
244
|
+
## % is used to match *zero* or more occurrences of any characters
|
245
|
+
## todo: check if it matches zero too
|
246
|
+
if cty.nil?
|
247
|
+
cty = Country.where( "name LIKE '%#{name_esc}%'" ).first
|
248
|
+
end
|
249
|
+
|
250
|
+
## 4) retry: use SQL like match for alternative names match
|
251
|
+
if cty.nil?
|
252
|
+
cty = Country.where( "alt_names LIKE '%#{name_esc}%'" ).first
|
253
|
+
end
|
254
|
+
end
|
255
|
+
cty # return cty (country); nil if not found
|
256
|
+
end # method find_country
|
218
257
|
|
219
|
-
end
|
220
258
|
|
221
259
|
|
222
260
|
end # class ReaderBase
|
data/lib/worlddb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: worlddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: props
|