locality 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/locality/postnummerservice.rb +17 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 124e11f6e775a6936ac6a7e6e001b0d3d98fb8b0
|
4
|
+
data.tar.gz: 6ce1ad7059a54b413101f404ec8f4abd7d6542c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1604d0de6d74ba547d50df7d0dce5bcf7d3fb7782b01ae1273ff77e6d35eecf8c70e725f9fb69210fcd6f75f7a0a931abee280fddf56de033c7c3ef70ca0524e
|
7
|
+
data.tar.gz: a5d2266556e1b0e2038f81b2729242e48b3fac6d13bf580d626ed8543861cc6ba3e56eb8716097083df99839740ecdcbb87638bd3759df05aaf557d07df0bdf5
|
@@ -32,11 +32,16 @@ module Locality
|
|
32
32
|
!!@loaded
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
# Useful for testing
|
36
|
+
def self.reset!
|
37
|
+
@loaded = false
|
36
38
|
@aregions = {}
|
37
39
|
@states = {}
|
38
40
|
@provinces = {}
|
41
|
+
end
|
39
42
|
|
43
|
+
def self.load!
|
44
|
+
reset!
|
40
45
|
entries do |entry|
|
41
46
|
@aregions[entry.aregion_code] ||= []
|
42
47
|
@aregions[entry.aregion_code] << entry
|
@@ -50,15 +55,25 @@ module Locality
|
|
50
55
|
end
|
51
56
|
|
52
57
|
def self.entries(&block)
|
53
|
-
|
58
|
+
return [] unless path
|
59
|
+
|
60
|
+
::CSV.foreach(path, encoding: encoding) do |row|
|
54
61
|
next if row.blank?
|
55
62
|
yield Entry.new(row)
|
56
63
|
end
|
64
|
+
|
65
|
+
rescue => exception
|
66
|
+
Trouble.notify exception
|
67
|
+
[]
|
57
68
|
end
|
58
69
|
|
59
70
|
def self.encoding
|
60
71
|
'ISO-8859-1:UTF-8' # from:to
|
61
72
|
end
|
62
73
|
|
74
|
+
def self.path
|
75
|
+
::Locality.config.postnummerfilen_path
|
76
|
+
end
|
77
|
+
|
63
78
|
end
|
64
79
|
end
|