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 +4 -4
- data/README.adoc +13 -13
- data/lib/{unlocode → unlocodes}/coordinates.rb +1 -1
- data/lib/{unlocode → unlocodes}/data/fetcher.rb +1 -1
- data/lib/{unlocode → unlocodes}/data.rb +2 -2
- data/lib/{unlocode → unlocodes}/entry.rb +1 -1
- data/lib/{unlocode → unlocodes}/function.rb +1 -1
- data/lib/{unlocode → unlocodes}/loader.rb +4 -4
- data/lib/{unlocode → unlocodes}/registry.rb +4 -4
- data/lib/{unlocode → unlocodes}/status.rb +1 -1
- data/lib/unlocodes/version.rb +5 -0
- data/lib/{unlocode.rb → unlocodes.rb} +11 -11
- metadata +18 -15
- data/lib/unlocode/version.rb +0 -5
- /data/lib/{unlocode → unlocodes}/data/README.adoc +0 -0
- /data/lib/{unlocode → unlocodes}/data/locode.jsonld +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a4c9de4b3b24e90847e45242a5199691e8d5284377e8f6476f6fb01b653a729d
|
|
4
|
+
data.tar.gz: 4903c23bdc9d3336471da5afc6ec1c0e1c711d75824ce822e6a089dbb54970b2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 '
|
|
17
|
+
gem 'unlocodes'
|
|
18
18
|
----
|
|
19
19
|
|
|
20
20
|
== Usage
|
|
21
21
|
|
|
22
22
|
[source,ruby]
|
|
23
23
|
----
|
|
24
|
-
require '
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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 =
|
|
65
|
-
rotterdam =
|
|
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
|
|
|
@@ -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 `
|
|
7
|
-
module
|
|
6
|
+
# loaded by `Unlocodes::Registry.load_default`.
|
|
7
|
+
module Unlocodes
|
|
8
8
|
module Data
|
|
9
9
|
autoload :Fetcher, "#{__dir__}/data/fetcher"
|
|
10
10
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require_relative 'entry'
|
|
5
5
|
|
|
6
|
-
module
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
|
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<
|
|
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 [
|
|
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<
|
|
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
|
|
@@ -4,19 +4,19 @@ require 'forwardable'
|
|
|
4
4
|
require 'lutaml/model'
|
|
5
5
|
require 'json'
|
|
6
6
|
|
|
7
|
-
require_relative '
|
|
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 `
|
|
15
|
-
module
|
|
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 [
|
|
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, '
|
|
33
|
-
autoload :Function, '
|
|
34
|
-
autoload :Coordinates, '
|
|
35
|
-
autoload :Entry, '
|
|
36
|
-
autoload :Loader, '
|
|
37
|
-
autoload :Registry, '
|
|
38
|
-
autoload :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.
|
|
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:
|
|
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/
|
|
54
|
-
- lib/
|
|
55
|
-
- lib/
|
|
56
|
-
- lib/
|
|
57
|
-
- lib/
|
|
58
|
-
- lib/
|
|
59
|
-
- lib/
|
|
60
|
-
- lib/
|
|
61
|
-
- lib/
|
|
62
|
-
- lib/
|
|
63
|
-
- lib/
|
|
64
|
-
- lib/
|
|
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.
|
|
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: []
|
data/lib/unlocode/version.rb
DELETED
|
File without changes
|
|
File without changes
|