postnummer_norge 0.0.2 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d7fcdf05ab133f2f6333b294e2b26f31a07d691bab837365284146df8ba26db0
4
+ data.tar.gz: 43d5a0c202433172d249dff7422473c92643bfa677c13b9d73c9b0acc0b8e807
5
+ SHA512:
6
+ metadata.gz: 26cffb57ae2012c2a8f624f5b82dbda87b8ef03d6ce9d9c067d4f8c1bf322cd0f4c4197252bab32865316c440600e47028be7d0d06414ce21336b71967f519e8
7
+ data.tar.gz: a939c7f725044f8e7ebe7d5f77770c40b84f0efadcceeb6f5307bb691e828106663ee8de8f224ba358981ef2f5d975b7664015fef054963172fc7a97607e2aa9
@@ -0,0 +1,63 @@
1
+ name: Build
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ - develop
7
+ pull_request:
8
+ permissions:
9
+ contents: write
10
+ issues: write
11
+ pull-requests: write
12
+ id-token: write
13
+ jobs:
14
+ rubocop-test:
15
+ name: Rubocop
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@v6
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: '4.0'
22
+ bundler-cache: true
23
+ - name: Check code
24
+ run: bundle exec rubocop
25
+
26
+ rspec-test:
27
+ name: RSpec
28
+ runs-on: ubuntu-latest
29
+ strategy:
30
+ matrix:
31
+ ruby: ['3.3', '3.4', '4.0']
32
+ steps:
33
+ - uses: actions/checkout@v6
34
+ - uses: ruby/setup-ruby@v1
35
+ with:
36
+ ruby-version: ${{ matrix.ruby }}
37
+ bundler-cache: true
38
+ - name: Run tests
39
+ run: bundle exec rspec
40
+
41
+ release-please:
42
+ needs: [rubocop-test, rspec-test]
43
+ if: github.ref == 'refs/heads/main' && github.event_name == 'push'
44
+ runs-on: ubuntu-latest
45
+ outputs:
46
+ release_created: ${{ steps.release.outputs.release_created }}
47
+ steps:
48
+ - uses: googleapis/release-please-action@v4
49
+ id: release
50
+ with:
51
+ token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
52
+
53
+ publish:
54
+ needs: release-please
55
+ if: ${{ needs.release-please.outputs.release_created }}
56
+ runs-on: ubuntu-latest
57
+ steps:
58
+ - uses: actions/checkout@v6
59
+ - uses: ruby/setup-ruby@v1
60
+ with:
61
+ ruby-version: "4.0"
62
+ bundler-cache: true
63
+ - uses: rubygems/release-gem@v1
@@ -0,0 +1,28 @@
1
+ name: Update Postal Codes
2
+ on:
3
+ schedule:
4
+ - cron: '0 8 1 * *'
5
+ workflow_dispatch:
6
+ permissions:
7
+ contents: write
8
+ pull-requests: write
9
+ jobs:
10
+ update:
11
+ name: Update postal codes
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v6
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '4.0'
18
+ bundler-cache: true
19
+ - name: Update postal codes
20
+ run: bundle exec rake update_codes
21
+ - name: Create Pull Request
22
+ uses: peter-evans/create-pull-request@v7
23
+ with:
24
+ add-paths: lib/postnummer_norge/postal_codes.tab
25
+ commit-message: 'fix: Update postal codes'
26
+ title: 'Update postal codes'
27
+ branch: update-postal-codes
28
+ delete-branch: true
data/.gitignore CHANGED
@@ -1,4 +1,4 @@
1
1
  *.gem
2
2
  .bundle
3
- Gemfile.lock
3
+ coverage/
4
4
  pkg/*
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "1.0.1"
3
+ }
data/.rubocop.yml ADDED
@@ -0,0 +1,21 @@
1
+ plugins:
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/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 4.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ ## [1.0.1](https://github.com/elektronaut/postnummer_norge/compare/postnummer_norge-v1.0.0...postnummer_norge/v1.0.1) (2026-01-22)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Add Gemfile.lock to release-please config ([d93030f](https://github.com/elektronaut/postnummer_norge/commit/d93030fbd9a7128305cd6316bc97a5ce4ceca490))
9
+ * Limit PR to postal codes file only ([d4e5f33](https://github.com/elektronaut/postnummer_norge/commit/d4e5f3398415156b75ebc18b0670b65559963bef))
10
+ * Update postal codes ([5cbac1a](https://github.com/elektronaut/postnummer_norge/commit/5cbac1a0a48f820c33f3a49917ff1ae95fad1e7f))
11
+ * Use simple release type for plain VERSION file ([d80825c](https://github.com/elektronaut/postnummer_norge/commit/d80825cdab8db38fab4c1f3457e85f5258b09982))
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.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ ast (2.4.3)
10
+ diff-lcs (1.6.2)
11
+ docile (1.4.1)
12
+ json (2.18.0)
13
+ language_server-protocol (3.17.0.5)
14
+ lint_roller (1.1.0)
15
+ parallel (1.27.0)
16
+ parser (3.3.10.1)
17
+ ast (~> 2.4.1)
18
+ racc
19
+ prism (1.8.0)
20
+ racc (1.8.1)
21
+ rainbow (3.1.1)
22
+ rake (13.3.1)
23
+ regexp_parser (2.11.3)
24
+ rspec (3.13.2)
25
+ rspec-core (~> 3.13.0)
26
+ rspec-expectations (~> 3.13.0)
27
+ rspec-mocks (~> 3.13.0)
28
+ rspec-core (3.13.6)
29
+ rspec-support (~> 3.13.0)
30
+ rspec-expectations (3.13.5)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-mocks (3.13.7)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.13.0)
36
+ rspec-support (3.13.6)
37
+ rubocop (1.82.1)
38
+ json (~> 2.3)
39
+ language_server-protocol (~> 3.17.0.2)
40
+ lint_roller (~> 1.1.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.3.0.2)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 2.9.3, < 3.0)
45
+ rubocop-ast (>= 1.48.0, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 2.4.0, < 4.0)
48
+ rubocop-ast (1.49.0)
49
+ parser (>= 3.3.7.2)
50
+ prism (~> 1.7)
51
+ rubocop-rake (0.7.1)
52
+ lint_roller (~> 1.1)
53
+ rubocop (>= 1.72.1)
54
+ rubocop-rspec (3.9.0)
55
+ lint_roller (~> 1.1)
56
+ rubocop (~> 1.81)
57
+ ruby-progressbar (1.13.0)
58
+ simplecov (0.22.0)
59
+ docile (~> 1.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov_json_formatter (~> 0.1)
62
+ simplecov-html (0.13.2)
63
+ simplecov_json_formatter (0.1.4)
64
+ unicode-display_width (3.2.0)
65
+ unicode-emoji (~> 4.1)
66
+ unicode-emoji (4.2.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
+ 4.0.4
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