unlocodes 0.1.0 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b94b2f3a3a7f5b4968db10f04c5dac3c3745c318025c81a09ed5f49e82f4727e
4
- data.tar.gz: 61eeac2c2f2836b9abcd9fdce8b9142a217b0af48efe0abe4f5f374c9d2a931e
3
+ metadata.gz: a4c9de4b3b24e90847e45242a5199691e8d5284377e8f6476f6fb01b653a729d
4
+ data.tar.gz: 4903c23bdc9d3336471da5afc6ec1c0e1c711d75824ce822e6a089dbb54970b2
5
5
  SHA512:
6
- metadata.gz: 0e2e189ebbdea9c82a990961b52b952f9b31826603a9ef99e2113f81cb868dc744e21b7ac1708d65acb63c51130c361a45183fa5354b3014d9563976c3f00522
7
- data.tar.gz: 2924a2a74d14cb06dcdb5250e4adaa574812a52a16c0432cc11482519f0230e2473894f82ba879dada0f9bb69e6764d6cd85a936ce21258610938c1c10af889e
6
+ metadata.gz: 2938d6ba840b7b93731afd97081478dce93cbd5b82357eb56032a943c000728a9d484b9fec9a5deffaa30916b99ba4588d33add5ce64e9489cd671d9a2ad0994
7
+ data.tar.gz: 76333326f2218ed42eebe6c729b05609c3e14b874854c9171dac3260d022c521a52e23e4e290a26565432936a837f548b6ff1a464c064258059741ad2c9ada01
data/README.adoc CHANGED
@@ -14,21 +14,21 @@ Add to your Gemfile:
14
14
 
15
15
  [source,ruby]
16
16
  ----
17
- gem 'unlocode'
17
+ gem 'unlocodes'
18
18
  ----
19
19
 
20
20
  == Usage
21
21
 
22
22
  [source,ruby]
23
23
  ----
24
- require 'unlocode'
25
-
26
- Unlocode.find('CNSHA') # => #<Unlocode::Entry code="CNSHA" ...>
27
- Unlocode.find('NLRTM').functions.map(&:code) # => ["B", "R", "T", "A", "P"]
28
- Unlocode.where(country: 'CN').count # => 1670
29
- Unlocode.where(function: 'B').count # => 17912 (sea ports)
30
- Unlocode.where(function: 'A').count # => 9009 (airports)
31
- Unlocode.find('CNPDG').coordinates # => #<Coordinates lat=31.2333 lon=121.5000>
24
+ require 'unlocodes'
25
+
26
+ Unlocodes.find('CNSHA') # => #<Unlocodes::Entry code="CNSHA" ...>
27
+ Unlocodes.find('NLRTM').functions.map(&:code) # => ["B", "R", "T", "A", "P"]
28
+ Unlocodes.where(country: 'CN').count # => 1670
29
+ Unlocodes.where(function: 'B').count # => 17912 (sea ports)
30
+ Unlocodes.where(function: 'A').count # => 9009 (airports)
31
+ Unlocodes.find('CNPDG').coordinates # => #<Coordinates lat=31.2333 lon=121.5000>
32
32
  ----
33
33
 
34
34
  === Function codes
@@ -53,16 +53,16 @@ Use the letters in `where(function: ...)`:
53
53
 
54
54
  [source,ruby]
55
55
  ----
56
- Unlocode.where(function: 'B').count # sea ports
57
- Unlocode.where(function: %w[B A]).count # entries that are both port and airport
56
+ Unlocodes.where(function: 'B').count # sea ports
57
+ Unlocodes.where(function: %w[B A]).count # entries that are both port and airport
58
58
  ----
59
59
 
60
60
  === Distances
61
61
 
62
62
  [source,ruby]
63
63
  ----
64
- shanghai = Unlocode.find('CNPDG').coordinates
65
- rotterdam = Unlocode.find('NLRTM').coordinates
64
+ shanghai = Unlocodes.find('CNPDG').coordinates
65
+ rotterdam = Unlocodes.find('NLRTM').coordinates
66
66
  shanghai.distance_to(rotterdam) # => 8922.0 (km, great-circle)
67
67
  ----
68
68
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Unlocode
3
+ module Unlocodes
4
4
  # Geographic coordinates (WGS-84) for a LOCODE entry.
5
5
  #
6
6
  # Parsed from the LOCODE coordinate string ("DDMM[H]DDDMM[H]" where H is one
@@ -4,7 +4,7 @@ require 'net/http'
4
4
  require 'uri'
5
5
  require 'fileutils'
6
6
 
7
- module Unlocode
7
+ module Unlocodes
8
8
  module Data
9
9
  # Downloads the UNCEFACT UN/LOCODE vocabulary from the upstream GitLab
10
10
  # repository and stores it as `lib/unlocode/data/locode.jsonld`.
@@ -3,8 +3,8 @@
3
3
  # Bundled UN/LOCODE dataset.
4
4
  #
5
5
  # `locode.jsonld` is populated by `rake unlocode:fetch` and is the source
6
- # loaded by `Unlocode::Registry.load_default`.
7
- module Unlocode
6
+ # loaded by `Unlocodes::Registry.load_default`.
7
+ module Unlocodes
8
8
  module Data
9
9
  autoload :Fetcher, "#{__dir__}/data/fetcher"
10
10
  end
@@ -5,7 +5,7 @@ require_relative 'status'
5
5
  require_relative 'function'
6
6
  require_relative 'coordinates'
7
7
 
8
- module Unlocode
8
+ module Unlocodes
9
9
  # A single UN/LOCODE entry.
10
10
  #
11
11
  # Stores wire-level fields as `lutaml-model` attributes and exposes typed
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Unlocode
3
+ module Unlocodes
4
4
  # UN/LOCODE function classifier.
5
5
  #
6
6
  # Single-letter codes identifying the transport function a LOCODE serves.
@@ -3,7 +3,7 @@
3
3
  require 'json'
4
4
  require_relative 'entry'
5
5
 
6
- module Unlocode
6
+ module Unlocodes
7
7
  # Parses a UN/LOCODE JSON-LD vocabulary file into {Entry} instances.
8
8
  #
9
9
  # The UNCEFACT vocabulary (`vocab/unlocode.jsonld`) is a single JSON-LD
@@ -39,21 +39,21 @@ module Unlocode
39
39
  class << self
40
40
  # Load entries from a file path on disk.
41
41
  # @param path [String] absolute or relative path to a JSON-LD file
42
- # @return [Array<Unlocode::Entry>]
42
+ # @return [Array<Unlocodes::Entry>]
43
43
  def load_file(path)
44
44
  load_json(File.read(path))
45
45
  end
46
46
 
47
47
  # Load entries from a JSON-LD string.
48
48
  # @param json [String] a JSON-LD document
49
- # @return [Array<Unlocode::Entry>]
49
+ # @return [Array<Unlocodes::Entry>]
50
50
  def load_json(json)
51
51
  parse(JSON.parse(json, symbolize_names: false))
52
52
  end
53
53
 
54
54
  # Load entries from a pre-parsed JSON-LD hash.
55
55
  # @param data [Hash] parsed JSON-LD
56
- # @return [Array<Unlocode::Entry>]
56
+ # @return [Array<Unlocodes::Entry>]
57
57
  def parse(data)
58
58
  extract_graph(data).filter_map { |node| build_entry(node) if unlocode_node?(node) }
59
59
  end
@@ -3,7 +3,7 @@
3
3
  require 'forwardable'
4
4
  require_relative 'loader'
5
5
 
6
- module Unlocode
6
+ module Unlocodes
7
7
  # In-memory, lazily-indexed registry over a set of {Entry} instances.
8
8
  #
9
9
  # The default registry is loaded from the vendored dataset bundled with the
@@ -50,7 +50,7 @@ module Unlocode
50
50
  end
51
51
 
52
52
  # Build a registry from an existing list of entries.
53
- # @param entries [Array<Unlocode::Entry>]
53
+ # @param entries [Array<Unlocodes::Entry>]
54
54
  # @return [Registry]
55
55
  def from_entries(entries)
56
56
  new(entries)
@@ -65,7 +65,7 @@ module Unlocode
65
65
 
66
66
  # Exact-code lookup.
67
67
  # @param code [String] 5-char LOCODE (case-insensitive)
68
- # @return [Unlocode::Entry, nil]
68
+ # @return [Unlocodes::Entry, nil]
69
69
  def find(code)
70
70
  return nil if code.nil?
71
71
 
@@ -83,7 +83,7 @@ module Unlocode
83
83
  # registry.where(country: %w[CN HK], function: 'B')
84
84
  # registry.where(name: /shanghai/i)
85
85
  #
86
- # @return [Array<Unlocode::Entry>]
86
+ # @return [Array<Unlocodes::Entry>]
87
87
  def where(filters)
88
88
  filters.reduce(entries) { |scope, (key, value)| apply_filter(scope, key, value) }
89
89
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Unlocode
3
+ module Unlocodes
4
4
  # UN/LOCODE status (change indicator).
5
5
  #
6
6
  # Two-letter codes documenting how a LOCODE entry was last amended relative
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Unlocodes
4
+ VERSION = '0.1.3'
5
+ end
@@ -4,19 +4,19 @@ require 'forwardable'
4
4
  require 'lutaml/model'
5
5
  require 'json'
6
6
 
7
- require_relative 'unlocode/version'
7
+ require_relative 'unlocodes/version'
8
8
 
9
9
  # Vendored UN/LOCODE dataset as a queryable Ruby registry.
10
10
  #
11
11
  # The dataset is sourced from the UNECE/UNCEFACT LOCODE vocabulary published at
12
12
  # https://service.unece.org/trade/locode/ and distributed by this gem as a
13
13
  # bundled, offline JSON-LD representation. The registry loads once per process
14
- # and exposes a typed query API over `Unlocode::Entry` instances.
15
- module Unlocode
14
+ # and exposes a typed query API over `Unlocodes::Entry` instances.
15
+ module Unlocodes
16
16
  extend SingleForwardable
17
17
 
18
18
  class << self
19
- # @return [Unlocode::Registry] the process-wide registry, loaded lazily
19
+ # @return [Unlocodes::Registry] the process-wide registry, loaded lazily
20
20
  def registry
21
21
  @registry ||= Registry.load_default
22
22
  end
@@ -29,11 +29,11 @@ module Unlocode
29
29
 
30
30
  def_delegators :registry, :find, :where, :each, :size, :count, :countries
31
31
 
32
- autoload :Status, 'unlocode/status'
33
- autoload :Function, 'unlocode/function'
34
- autoload :Coordinates, 'unlocode/coordinates'
35
- autoload :Entry, 'unlocode/entry'
36
- autoload :Loader, 'unlocode/loader'
37
- autoload :Registry, 'unlocode/registry'
38
- autoload :Data, 'unlocode/data'
32
+ autoload :Status, 'unlocodes/status'
33
+ autoload :Function, 'unlocodes/function'
34
+ autoload :Coordinates, 'unlocodes/coordinates'
35
+ autoload :Entry, 'unlocodes/entry'
36
+ autoload :Loader, 'unlocodes/loader'
37
+ autoload :Registry, 'unlocodes/registry'
38
+ autoload :Data, 'unlocodes/data'
39
39
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unlocodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-07-01 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: json
@@ -50,18 +51,18 @@ extra_rdoc_files: []
50
51
  files:
51
52
  - LICENSE
52
53
  - README.adoc
53
- - lib/unlocode.rb
54
- - lib/unlocode/coordinates.rb
55
- - lib/unlocode/data.rb
56
- - lib/unlocode/data/README.adoc
57
- - lib/unlocode/data/fetcher.rb
58
- - lib/unlocode/data/locode.jsonld
59
- - lib/unlocode/entry.rb
60
- - lib/unlocode/function.rb
61
- - lib/unlocode/loader.rb
62
- - lib/unlocode/registry.rb
63
- - lib/unlocode/status.rb
64
- - lib/unlocode/version.rb
54
+ - lib/unlocodes.rb
55
+ - lib/unlocodes/coordinates.rb
56
+ - lib/unlocodes/data.rb
57
+ - lib/unlocodes/data/README.adoc
58
+ - lib/unlocodes/data/fetcher.rb
59
+ - lib/unlocodes/data/locode.jsonld
60
+ - lib/unlocodes/entry.rb
61
+ - lib/unlocodes/function.rb
62
+ - lib/unlocodes/loader.rb
63
+ - lib/unlocodes/registry.rb
64
+ - lib/unlocodes/status.rb
65
+ - lib/unlocodes/version.rb
65
66
  homepage: https://github.com/metanorma/unlocode
66
67
  licenses:
67
68
  - BSD-2-Clause
@@ -70,6 +71,7 @@ metadata:
70
71
  source_code_uri: https://github.com/metanorma/unlocode
71
72
  bug_tracker_uri: https://github.com/metanorma/unlocode/issues
72
73
  rubygems_mfa_required: 'true'
74
+ post_install_message:
73
75
  rdoc_options: []
74
76
  require_paths:
75
77
  - lib
@@ -84,7 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
86
  - !ruby/object:Gem::Version
85
87
  version: '0'
86
88
  requirements: []
87
- rubygems_version: 3.6.9
89
+ rubygems_version: 3.5.22
90
+ signing_key:
88
91
  specification_version: 4
89
92
  summary: UN/LOCODE dataset as a queryable Ruby registry
90
93
  test_files: []
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Unlocode
4
- VERSION = '0.1.0'
5
- end
File without changes
File without changes