worlddb 2.0.6 → 2.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45f7ea9e8342b1543e5b5ffc4a3248eb556f3ba2
4
- data.tar.gz: 8e8fc8668c5ff107626dc1300212fad1cf7b84cc
3
+ metadata.gz: af58d58c38775a19ef1a319c7a2964dfb38f690d
4
+ data.tar.gz: 5370d2cd74dab599b22b62413fffdb57372d259d
5
5
  SHA512:
6
- metadata.gz: fef9a54a76351aa639ce10ed5e423daec71aef3b366ec9a0b9b457751b8f12170a2fde3433f0a36bcb9996bed6959c741ed3246091f433725ac6442ac1564df5
7
- data.tar.gz: 8e3e5f08bf075a1da28d5af49e252798dae7383a30fff7e5e5d368babb8e15736729eac3dce83245407b950127ff775c6b0d29d4ea069f0810210765ca61878c
6
+ metadata.gz: f59a8cf313525cb89e6d7ebfac67e6bc2329b26cc17d3ee0ecaf5e026298ab43a50c6cfb6163e88b23fabdc34a656e0c77720e90a917a1daa127b2f3183cb325
7
+ data.tar.gz: f030026f39270272136a0b68556c093c4a5264e670c088235cbfad7ac88e6fae5e5c687161654acf0c5411af3c4e19c7dc82c8bb6c1810402cf1aec0fc50f81e
@@ -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 = 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
-
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
@@ -4,7 +4,7 @@ module WorldDb
4
4
  # sync version w/ sport.db n friends - why? why not?
5
5
  MAJOR = 2 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 0
7
- PATCH = 6
7
+ PATCH = 7
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
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.6
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-16 00:00:00.000000000 Z
11
+ date: 2014-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: props