postnummer_norge 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8a5bfd2544e9be22fad9cf3b68b0d6beb5d8c520336f470111bff03e7f69a6cf
4
+ data.tar.gz: dec56ecded6a1c4da553d38cbb36eacb9d78797ae4f8760965c0219579bd3b8e
5
+ SHA512:
6
+ metadata.gz: 455f85de7395d998c2fe199a01a1840ae25a220d86ae2ff85efc596b3a300da65c6e743ddb72e89e70fba22884a4b8c14cee8af0024084e7aabdc52944684d97
7
+ data.tar.gz: a9d0e13711f55d3fb2aee16ef4c3fdc69e0e2798fe0da7ec17b6d09b8c4dcb3b65f070facbf1dd07ce2bfeb118ef38496cdd07d51f7620b913f1b9035e02efeb
@@ -0,0 +1,37 @@
1
+ env:
2
+ RUBY_VERSION: 3.0
3
+
4
+ name: Build
5
+ on:
6
+ push:
7
+ branches:
8
+ - master
9
+ - develop
10
+ pull_request:
11
+ jobs:
12
+ rubocop-test:
13
+ name: Rubocop
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v1
17
+ - uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ env.RUBY_VERSION }}
20
+ bundler-cache: true
21
+ - name: Check code
22
+ run: bundle exec rubocop
23
+
24
+ rspec-test:
25
+ name: RSpec
26
+ runs-on: ubuntu-latest
27
+ strategy:
28
+ matrix:
29
+ ruby: ['3.0', '3.1', '3.2']
30
+ steps:
31
+ - uses: actions/checkout@v1
32
+ - uses: ruby/setup-ruby@v1
33
+ with:
34
+ ruby-version: ${{ matrix.ruby }}
35
+ bundler-cache: true
36
+ - name: Run tests
37
+ run: bundle exec rspec
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
3
+ coverage/
4
4
  pkg/*
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ NewCops: enable
7
+ TargetRubyVersion: 3.0
8
+
9
+ Style/StringLiterals:
10
+ EnforcedStyle: double_quotes
11
+
12
+ Style/Documentation:
13
+ Enabled: false
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "*.gemspec"
18
+ - "**/*_spec.rb"
19
+
20
+ Naming/MethodName:
21
+ Enabled: false
data/Gemfile CHANGED
@@ -1,4 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "http://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in postnummer_norge.gemspec
4
6
  gemspec
7
+
8
+ group :development, :test do
9
+ gem "rake"
10
+ gem "rspec"
11
+ gem "rubocop", require: false
12
+ gem "rubocop-rake", require: false
13
+ gem "rubocop-rspec", require: false
14
+ gem "simplecov"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ postnummer_norge (1.0.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ docile (1.4.0)
12
+ json (2.6.3)
13
+ language_server-protocol (3.17.0.3)
14
+ parallel (1.23.0)
15
+ parser (3.2.2.4)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ racc (1.7.3)
19
+ rainbow (3.1.1)
20
+ rake (13.1.0)
21
+ regexp_parser (2.8.2)
22
+ rexml (3.2.6)
23
+ rspec (3.12.0)
24
+ rspec-core (~> 3.12.0)
25
+ rspec-expectations (~> 3.12.0)
26
+ rspec-mocks (~> 3.12.0)
27
+ rspec-core (3.12.2)
28
+ rspec-support (~> 3.12.0)
29
+ rspec-expectations (3.12.3)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-mocks (3.12.6)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-support (3.12.1)
36
+ rubocop (1.57.2)
37
+ json (~> 2.3)
38
+ language_server-protocol (>= 3.17.0)
39
+ parallel (~> 1.10)
40
+ parser (>= 3.2.2.4)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ regexp_parser (>= 1.8, < 3.0)
43
+ rexml (>= 3.2.5, < 4.0)
44
+ rubocop-ast (>= 1.28.1, < 2.0)
45
+ ruby-progressbar (~> 1.7)
46
+ unicode-display_width (>= 2.4.0, < 3.0)
47
+ rubocop-ast (1.30.0)
48
+ parser (>= 3.2.1.0)
49
+ rubocop-capybara (2.19.0)
50
+ rubocop (~> 1.41)
51
+ rubocop-factory_bot (2.24.0)
52
+ rubocop (~> 1.33)
53
+ rubocop-rake (0.6.0)
54
+ rubocop (~> 1.0)
55
+ rubocop-rspec (2.25.0)
56
+ rubocop (~> 1.40)
57
+ rubocop-capybara (~> 2.17)
58
+ rubocop-factory_bot (~> 2.22)
59
+ ruby-progressbar (1.13.0)
60
+ simplecov (0.22.0)
61
+ docile (~> 1.1)
62
+ simplecov-html (~> 0.11)
63
+ simplecov_json_formatter (~> 0.1)
64
+ simplecov-html (0.12.3)
65
+ simplecov_json_formatter (0.1.4)
66
+ unicode-display_width (2.5.0)
67
+
68
+ PLATFORMS
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ postnummer_norge!
73
+ rake
74
+ rspec
75
+ rubocop
76
+ rubocop-rake
77
+ rubocop-rspec
78
+ simplecov
79
+
80
+ BUNDLED WITH
81
+ 2.4.22
data/README.md ADDED
@@ -0,0 +1,17 @@
1
+ ![Build](https://github.com/anyone-oslo/postnummer_norge/workflows/Build/badge.svg)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/37b0128a6c9ccfb78ddb/maintainability)](https://codeclimate.com/github/anyone-oslo/postnummer_norge/maintainability)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/37b0128a6c9ccfb78ddb/test_coverage)](https://codeclimate.com/github/anyone-oslo/postnummer_norge/test_coverage)
4
+
5
+ # PostnummerNorge
6
+
7
+ Ruby gem for looking up Norwegian postal codes.
8
+
9
+ ## Usage
10
+
11
+ ```ruby
12
+ include PostnummerNorge
13
+
14
+ PostalCode.exists?("0662") # => true
15
+ PostalCode.find("0662").name # => 'OSLO'
16
+ PostalCode.find_by_name("HUNDVÅG").first.code # => '4077'
17
+ ```
data/Rakefile CHANGED
@@ -1 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
4
+ require "net/http"
5
+ require "uri"
6
+
7
+ desc "Update postal codes"
8
+ task :update_codes do
9
+ url = "https://www.bring.no/postnummerregister-ansi.txt"
10
+ content = Net::HTTP.get(URI.parse(url))
11
+ File.write("./lib/postnummer_norge/postal_codes.tab",
12
+ content.force_encoding("iso-8859-1")
13
+ .encode("UTF-8", universal_newline: true))
14
+ end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module PostnummerNorge
4
4
  class PostalCode
@@ -10,27 +10,27 @@ module PostnummerNorge
10
10
  end
11
11
 
12
12
  def find(code)
13
- matches = postal_codes.select{|pc| pc.code == code.to_s}
14
- matches.length > 0 ? matches.first : nil
13
+ matches = postal_codes.select { |pc| pc.code == code.to_s }
14
+ matches.empty? ? nil : matches.first
15
15
  end
16
16
 
17
17
  def find_by_name(name)
18
- matches = postal_codes.select{|pc| pc.name.downcase == name.to_s.downcase}
19
- matches.length > 0 ? matches : nil
18
+ matches = postal_codes.select { |pc| pc.name.downcase == name.to_s.downcase }
19
+ matches.empty? ? nil : matches
20
20
  end
21
21
 
22
22
  def postal_codes
23
- @@postal_codes ||= load_postal_codes
23
+ @postal_codes ||= load_postal_codes
24
24
  end
25
25
 
26
26
  def load_postal_codes
27
- File.open(data_file, 'r'){|fh| fh.read}.split("\n").compact.map do |line|
28
- self.new *line.split("\t")
27
+ File.read(data_file).split("\n").compact.map do |line|
28
+ new(*line.split("\t"))
29
29
  end
30
30
  end
31
31
 
32
32
  def data_file
33
- File.join(File.dirname(__FILE__), 'postal_codes.tab')
33
+ File.join(File.dirname(__FILE__), "postal_codes.tab")
34
34
  end
35
35
  end
36
36
 
@@ -42,4 +42,4 @@ module PostnummerNorge
42
42
  @category = category
43
43
  end
44
44
  end
45
- end
45
+ end