locality 0.0.3 → 0.1.0

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: 87a063187c95946e77731cd381e1e196949c0d35
4
- data.tar.gz: d74e6d3a5e2b944300e0b544fcac90c545be590d
3
+ metadata.gz: 077ebf8169cc453fe48969651bf6d44a768c03a7
4
+ data.tar.gz: c2d9bc0b1be7aea098354a617936ea1daa2e0a8f
5
5
  SHA512:
6
- metadata.gz: fe91e20cf92950d82ea82692d0ed76aa89c44f368ae74ebf404ca5e0945f8ebd6dd9c8e4aa15eb4dfb2172a98044ef8f4dec3d54d6ecc58778a2bc61c5999b15
7
- data.tar.gz: d02ca7ca25fd003eb0419c3d745e2674096bb3516e8f4a938139dfb60ae3f281aa6809a4c26866039ea2fea4c84ac7d0baae1e5b0fcccef1b15754ddec796983
6
+ metadata.gz: a98c24bb1cd79948676672a1c9cf17497e898dda753a68bd8c7ea79824c205528da8286ed9e50f65ddd4d2c33a88df1b7d8205e2491b2a1ec38580fed7a11c4e
7
+ data.tar.gz: eae62edc70069c41d951a3d998ab4ce191f67f2101ab7c688617d737c5c438fdc1cd586a266a014f15238db978b058caadf68e4345d3a271c7fc920f04b416c3
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Locality
2
2
 
3
- ## Swedish A-Region
4
-
5
- See https://sv.wikipedia.org/wiki/A-region
3
+ ## Postnummerservice
6
4
 
7
5
  ### Installation
8
6
 
@@ -27,9 +25,32 @@ end
27
25
  ### Usage
28
26
 
29
27
  ```ruby
30
- lookup = Locality::Aregion.new 21 # Gotland
28
+ # A-Regions
29
+ # See https://sv.wikipedia.org/wiki/A-region
30
+ available_codes = Locality::Postnummerservice::Aregion.codes
31
+ lookup = Locality::Postnummerservice::Aregion.new 21 # Gotland
32
+
33
+ # States
34
+ # See https://sv.wikipedia.org/wiki/Sveriges_l%C3%A4n
35
+ available_codes = Locality::Postnummerservice::State.codes
36
+ lookup = Locality::Postnummerservice::State.new 7 # Kronoberg
37
+
38
+ # Provinces
39
+ # See https://sv.wikipedia.org/wiki/Sveriges_l%C3%A4n
40
+ available_codes = Locality::Postnummerservice::Province.codes
41
+ lookup = Locality::Postnummerservice::Province.new '0182' # Nacka
42
+
43
+ # On all of the above lookups you have the following attributes
44
+ lookup.code
45
+ lookup.name
46
+ lookup.zip_codes
47
+ lookup.city_names
48
+ lookup.state_codes
49
+ lookup.state_names
50
+ lookup.province_code
51
+ lookup.province_names
52
+ lookup.aregion_codes
31
53
 
32
- lookup.zip_codes # => Array of Integers
33
54
  # More to come...
34
55
  ```
35
56
 
@@ -52,7 +73,7 @@ curl http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz -o
52
73
  Locality.configure do |config|
53
74
 
54
75
  # By default, locality will look for the maxmind database in
55
- # these locations: `Locality.config.maxmind_geoip2_path`
76
+ # these locations: `Locality.config.maxmind_geoip2_paths`
56
77
  # You can add a custom location like so:
57
78
  config.maxmind_geoip2_path = '/some/custom/maxmind_geolite2.mmdb'
58
79
 
@@ -0,0 +1,101 @@
1
+ require 'locality/postnummerservice'
2
+ require 'locality/postnummerservice/collection'
3
+
4
+ module Locality
5
+ module Postnummerservice
6
+ class Aregion
7
+ include Postnummerservice::Collection
8
+
9
+ # See https://sv.wikipedia.org/wiki/A-region
10
+ def self.codes
11
+ {
12
+ 1 => 'Stockholm/Södertälje',
13
+ 2 => 'Norrtälje',
14
+ 3 => 'Enköping',
15
+ 4 => 'Uppsala',
16
+ 5 => 'Nyköping',
17
+ 6 => 'Katrineholm',
18
+ 7 => 'Eskilstuna',
19
+ 8 => 'Mjölby/Motala',
20
+ 9 => 'Linköping',
21
+ 10 => 'Norrköping',
22
+ 11 => 'Jönköping',
23
+ 12 => 'Tranås',
24
+ 13 => 'Eksjö/Nässjö/Vetlanda',
25
+ 14 => 'Värnamo',
26
+ 15 => 'Ljungby',
27
+ 16 => 'Växjö',
28
+ 17 => 'Västervik',
29
+ 18 => 'Hultsfred/Vimmerby',
30
+ 19 => 'Oskarshamn',
31
+ 20 => 'Kalmar/Nybro',
32
+ 21 => 'Visby',
33
+ 22 => 'Karlskrona',
34
+ 23 => 'Karlshamn',
35
+ 24 => 'Kristianstad',
36
+ 25 => 'Hässleholm',
37
+ 26 => 'Ängelholm',
38
+ 27 => 'Helsingborg/Landskrona',
39
+ 28 => 'Malmö/Lund/Trelleborg',
40
+ 29 => 'Ystad/Simrishamn',
41
+ 30 => 'Eslöv',
42
+ 31 => 'Halmstad',
43
+ 32 => 'Falkenberg/Varberg',
44
+ 33 => 'Göteborg/Alingsås',
45
+ 34 => 'Uddevalla',
46
+ 35 => 'Trollhättan/Vänersborg',
47
+ 36 => 'Borås',
48
+ 37 => 'Lidköping/Skara',
49
+ 38 => 'Falköping',
50
+ 39 => 'Skövde',
51
+ 40 => 'Mariestad',
52
+ 41 => 'Kristinehamn/Filipstad',
53
+ 42 => 'Karlstad',
54
+ 43 => 'Säffle/Åmål',
55
+ 44 => 'Arvika',
56
+ 45 => 'Örebro',
57
+ 46 => 'Karlskoga',
58
+ 47 => 'Lindesberg',
59
+ 48 => 'Västerås',
60
+ 49 => 'Köping',
61
+ 50 => 'Fagersta',
62
+ 51 => 'Sala',
63
+ 52 => 'Borlänge/Falun',
64
+ 53 => 'Avesta/Hedemora',
65
+ 54 => 'Ludvika',
66
+ 55 => 'Mora',
67
+ 56 => 'Gävle/Sandviken',
68
+ 57 => 'Bollnäs/Söderhamn',
69
+ 58 => 'Hudiksvall/Ljusdal',
70
+ 59 => 'Sundsvall',
71
+ 60 => 'Härnösand/Kramfors',
72
+ 61 => 'Sollefteå',
73
+ 62 => 'Örnsköldsvik',
74
+ 63 => 'Östersund',
75
+ 64 => 'Umeå',
76
+ 65 => 'Skellefteå',
77
+ 66 => 'Lycksele',
78
+ 67 => 'Piteå',
79
+ 68 => 'Luleå/Boden',
80
+ 69 => 'Haparanda/Kalix',
81
+ 70 => 'Kiruna/Gällivare',
82
+ }
83
+ end
84
+
85
+ def code
86
+ raw_code.to_i
87
+ end
88
+
89
+ def name
90
+ self.class.codes[code]
91
+ end
92
+
93
+ private
94
+
95
+ def self.backend
96
+ Postnummerservice.aregions
97
+ end
98
+
99
+ end
100
+ end
101
+ end
@@ -5,6 +5,12 @@ module Locality
5
5
  module Collection
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ module ClassMethods
9
+ def backend
10
+ fail NotImplementedError
11
+ end
12
+ end
13
+
8
14
  def initialize(raw_code)
9
15
  @raw_code = raw_code
10
16
  end
@@ -38,8 +44,8 @@ module Locality
38
44
  @province_codes ||= entities.map(&:province_code).uniq.sort
39
45
  end
40
46
 
41
- def aregions
42
- @aregions ||= entities.map(&:aregion).uniq.sort
47
+ def aregion_codes
48
+ @aregions ||= entities.map(&:aregion_code).uniq.sort
43
49
  end
44
50
 
45
51
  private
@@ -51,7 +57,7 @@ module Locality
51
57
  end
52
58
 
53
59
  def backend
54
- fail NotImplementedError
60
+ self.class.backend
55
61
  end
56
62
 
57
63
  end
@@ -9,7 +9,7 @@ module Locality
9
9
  end
10
10
 
11
11
  def city_name
12
- self[1]
12
+ self[1].to_s.mb_chars.downcase.titleize.to_s
13
13
  end
14
14
 
15
15
  def state_code
@@ -17,18 +17,18 @@ module Locality
17
17
  end
18
18
 
19
19
  def state_name
20
- self[3].humanize
20
+ self[3].to_s.mb_chars.downcase.titleize.to_s
21
21
  end
22
22
 
23
- def province_name
23
+ def province_code
24
24
  self[4]
25
25
  end
26
26
 
27
- def province_code
28
- self[5]
27
+ def province_name
28
+ self[5].to_s.mb_chars.downcase.titleize.to_s
29
29
  end
30
30
 
31
- def aregion
31
+ def aregion_code
32
32
  self[6].to_i
33
33
  end
34
34
 
@@ -0,0 +1,30 @@
1
+ require 'locality/postnummerservice'
2
+ require 'locality/postnummerservice/collection'
3
+
4
+ module Locality
5
+ module Postnummerservice
6
+ class Province
7
+ include Postnummerservice::Collection
8
+
9
+ # See http://www.scb.se/Pages/List____257281.aspx
10
+ def self.codes
11
+ Hash[backend.map { |code, entries| [code, entries.first.province_name] }]
12
+ end
13
+
14
+ def code
15
+ raw_code.to_s.strip
16
+ end
17
+
18
+ def name
19
+ province_names.first
20
+ end
21
+
22
+ private
23
+
24
+ def self.backend
25
+ Postnummerservice.provinces
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ require 'locality/postnummerservice'
2
+ require 'locality/postnummerservice/collection'
3
+
4
+ module Locality
5
+ module Postnummerservice
6
+ class State
7
+ include Postnummerservice::Collection
8
+
9
+ # See http://www.scb.se/Pages/List____257281.aspx
10
+ def self.codes
11
+ Hash[backend.map { |code, entries| [code, entries.first.state_name] }]
12
+ end
13
+
14
+ def code
15
+ raw_code.to_i
16
+ end
17
+
18
+ def name
19
+ state_names.first
20
+ end
21
+
22
+ private
23
+
24
+ def self.backend
25
+ Postnummerservice.states
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,8 @@
1
1
  require 'csv'
2
2
  require 'locality/postnummerservice/entry'
3
+ require 'locality/postnummerservice/aregion'
4
+ require 'locality/postnummerservice/province'
5
+ require 'locality/postnummerservice/state'
3
6
 
4
7
  module Locality
5
8
  module Postnummerservice
@@ -9,6 +12,16 @@ module Locality
9
12
  @aregions
10
13
  end
11
14
 
15
+ def self.states
16
+ load
17
+ @states
18
+ end
19
+
20
+ def self.provinces
21
+ load
22
+ @provinces
23
+ end
24
+
12
25
  private
13
26
 
14
27
  def self.load
@@ -21,10 +34,16 @@ module Locality
21
34
 
22
35
  def self.load!
23
36
  @aregions = {}
37
+ @states = {}
38
+ @provinces = {}
24
39
 
25
40
  entries do |entry|
26
- @aregions[entry.aregion] ||= []
27
- @aregions[entry.aregion] << entry
41
+ @aregions[entry.aregion_code] ||= []
42
+ @aregions[entry.aregion_code] << entry
43
+ @states[entry.state_code] ||= []
44
+ @states[entry.state_code] << entry
45
+ @provinces[entry.province_code] ||= []
46
+ @provinces[entry.province_code] << entry
28
47
  end
29
48
 
30
49
  @loaded = true
data/lib/locality.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'locality/aregion'
2
1
  require 'locality/configurable'
3
2
  require 'locality/ip'
4
- require 'locality/aregion'
3
+ require 'locality/postnummerservice'
5
4
 
6
5
  module Locality
7
6
  extend Configurable
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: locality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bukowskis
@@ -172,13 +172,15 @@ extra_rdoc_files: []
172
172
  files:
173
173
  - README.md
174
174
  - lib/locality.rb
175
- - lib/locality/aregion.rb
176
175
  - lib/locality/configurable.rb
177
176
  - lib/locality/configuration.rb
178
177
  - lib/locality/ip.rb
179
178
  - lib/locality/postnummerservice.rb
179
+ - lib/locality/postnummerservice/aregion.rb
180
180
  - lib/locality/postnummerservice/collection.rb
181
181
  - lib/locality/postnummerservice/entry.rb
182
+ - lib/locality/postnummerservice/province.rb
183
+ - lib/locality/postnummerservice/state.rb
182
184
  homepage: https://github.com/bukowskis/locality
183
185
  licenses: []
184
186
  metadata: {}
@@ -1,24 +0,0 @@
1
- require 'locality/postnummerservice'
2
- require 'locality/postnummerservice/collection'
3
-
4
- module Locality
5
- # See https://sv.wikipedia.org/wiki/A-region
6
- class Aregion
7
- include Postnummerservice::Collection
8
-
9
- def code
10
- raw_code.to_i
11
- end
12
-
13
- def state_name
14
- state_names.first
15
- end
16
-
17
- private
18
-
19
- def backend
20
- Locality::Postnummerservice.aregions
21
- end
22
-
23
- end
24
- end