swissmatch-location 0.1.1.201304 → 0.1.2.201304

Sign up to get free protection for your applications and to get access to all the features.
@@ -272,8 +272,7 @@ module SwissMatch
272
272
  raise "Must load cantons first" unless cantons
273
273
  raise "Must load communities first" unless communities
274
274
 
275
- temporary = Hash.new { |h,k| h[k] = [] }
276
- community_mapping = {}
275
+ community_mapping = Hash.new { |h,k| h[k] = [] }
277
276
  self_delivered = []
278
277
  others = []
279
278
  zip1_file = Dir.enum_for(:glob, "#{@data_directory}/plz_p1_*.txt").last
@@ -289,27 +288,26 @@ module SwissMatch
289
288
  communities_data[1].map!(&:to_i)
290
289
  communities_data[2].map!(&:to_i)
291
290
  communities_data.transpose.each do |data|
292
- temporary[data.last(2)] << data.at(0)
293
- end
294
-
295
- temporary.each do |key,coms|
296
- # compact, because some communities already no longer exist, so by_community_numbers can
297
- # contain nils which must be removed
298
- community_mapping[key] = Communities.new(communities.by_community_numbers(*coms.uniq.sort).compact)
291
+ community_mapping[data.last(2)] << data.at(0)
299
292
  end
300
293
 
301
294
  temporary = {}
302
295
  load_table(zip1_file, :zip_1).each do |row|
303
- onrp = row.at(0).to_i
304
- code = row.at(2).to_i
305
- addon = row.at(3).to_i
306
- delivery_by = row.at(10).to_i
307
- delivery_by = case delivery_by when 0 then nil; when onrp then :self; else delivery_by; end
308
- language = LanguageCodes[row.at(7).to_i]
309
- language_alternative = LanguageCodes[row.at(8).to_i]
310
- name_short = Name.new(row.at(4), language)
311
- name = Name.new(row.at(5), language)
312
- data = [
296
+ onrp = row.at(0).to_i
297
+ code = row.at(2).to_i
298
+ addon = row.at(3).to_i
299
+ delivery_by = row.at(10).to_i
300
+ delivery_by = case delivery_by when 0 then nil; when onrp then :self; else delivery_by; end
301
+ language = LanguageCodes[row.at(7).to_i]
302
+ language_alternative = LanguageCodes[row.at(8).to_i]
303
+ name_short = Name.new(row.at(4), language)
304
+ name = Name.new(row.at(5), language)
305
+ largest_community_number = row.at(11).to_i
306
+ # compact, because some communities already no longer exist, so by_community_numbers can
307
+ # contain nils which must be removed
308
+ community_numbers = (community_mapping[[code, addon]]|[largest_community_number]).sort
309
+ communities = Communities.new(communities.by_community_numbers(*community_numbers).compact)
310
+ data = [
313
311
  onrp, # ordering_number
314
312
  row.at(1).to_i, # type
315
313
  code,
@@ -325,8 +323,8 @@ module SwissMatch
325
323
  language_alternative,
326
324
  row.at(9) == "1", # sortfile_member
327
325
  delivery_by, # delivery_by
328
- communities.by_community_number(row.at(11).to_i), # community_number
329
- community_mapping[[code, addon]],
326
+ communities.by_community_number(largest_community_number), # community_number
327
+ communities,
330
328
  Date.civil(*row.at(12).match(/^(\d{4})(\d\d)(\d\d)$/).captures.map(&:to_i)) # valid_from
331
329
  ]
332
330
  temporary[onrp] = data
@@ -10,6 +10,6 @@ module SwissMatch
10
10
  module Location
11
11
 
12
12
  # The version of the swissmatch-location gem.
13
- Version = Gem::Version.new("0.1.1.201304")
13
+ Version = Gem::Version.new("0.1.2.201304")
14
14
  end
15
15
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "swissmatch-location"
5
- s.version = "0.1.1.201304"
5
+ s.version = "0.1.2.201304"
6
6
  s.authors = "Stefan Rusterholz"
7
7
  s.email = "stefan.rusterholz@gmail.com"
8
8
  s.homepage = "http://github.com/apeiros/swissmatch-location"
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: swissmatch-location
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1.201304
5
+ version: 0.1.2.201304
6
6
  platform: ruby
7
7
  authors:
8
8
  - Stefan Rusterholz
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubyzip