pubid 2.0.46 → 2.0.48
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/conformance/pending.yaml +173 -0
- data/data/parg/ansi.json +1 -1
- data/data/parg/wmo.json +1 -0
- data/data/parg/wmo.parg +108 -0
- data/lib/pubid/ansi/CLAUDE.md +81 -0
- data/lib/pubid/ansi/builder.rb +32 -8
- data/lib/pubid/ansi/identifier.rb +33 -0
- data/lib/pubid/ansi/identifiers/american_national_standard.rb +2 -1
- data/lib/pubid/ansi/pubid_urn_schema.rb +6 -3
- data/lib/pubid/ansi/renderer.rb +15 -5
- data/lib/pubid/ansi/urn_generator.rb +2 -0
- data/lib/pubid/ansi.rb +8 -2
- data/lib/pubid/prefixes_support.rb +11 -0
- data/lib/pubid/version.rb +1 -1
- data/lib/pubid/wmo/CLAUDE.md +114 -0
- data/lib/pubid/wmo/builder.rb +53 -0
- data/lib/pubid/wmo/identifier.rb +88 -0
- data/lib/pubid/wmo/identifiers/annex.rb +43 -0
- data/lib/pubid/wmo/identifiers/publication.rb +17 -0
- data/lib/pubid/wmo/identifiers/standard.rb +18 -0
- data/lib/pubid/wmo/identifiers.rb +11 -0
- data/lib/pubid/wmo/parser.rb +20 -0
- data/lib/pubid/wmo/pubid_urn_schema.rb +24 -0
- data/lib/pubid/wmo/renderer.rb +44 -0
- data/lib/pubid/wmo/urn_generator.rb +67 -0
- data/lib/pubid/wmo/urn_parser.rb +117 -0
- data/lib/pubid/wmo.rb +92 -0
- data/lib/pubid.rb +19 -1
- metadata +18 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pubid
|
|
4
|
+
module Wmo
|
|
5
|
+
# Generates URN strings for WMO identifiers under the WMO assigning
|
|
6
|
+
# authority of the IANA-registered `mrn` namespace, following the
|
|
7
|
+
# IALA pattern (pubid#763 proposed form; no authoritative WMO
|
|
8
|
+
# urn:mrn:wmo: rule is published — the S-411 repository carries none
|
|
9
|
+
# — so this shape is the fleet's extension until one exists):
|
|
10
|
+
#
|
|
11
|
+
# urn:mrn:wmo:pub:wmo-<number>[:ed<year>] the WMO-No. series
|
|
12
|
+
# urn:mrn:wmo:pub:s-<number>[:ed<x.y.z>] the S-100 specs
|
|
13
|
+
# urn:mrn:wmo:pub:s-<number>:annex[-<letter>][:ed<x.y.z>]
|
|
14
|
+
#
|
|
15
|
+
# Examples:
|
|
16
|
+
# urn:mrn:wmo:pub:wmo-1364:ed2025
|
|
17
|
+
# urn:mrn:wmo:pub:s-411:ed1.2.1
|
|
18
|
+
# urn:mrn:wmo:pub:s-411:annex-a
|
|
19
|
+
class UrnGenerator
|
|
20
|
+
attr_reader :identifier
|
|
21
|
+
|
|
22
|
+
def initialize(identifier)
|
|
23
|
+
@identifier = identifier
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def generate
|
|
27
|
+
return generate_annex if identifier.is_a?(Identifiers::Annex)
|
|
28
|
+
|
|
29
|
+
parts = ["urn:mrn:wmo:pub", code_segment]
|
|
30
|
+
parts << "ed#{identifier.edition}" if identifier.edition
|
|
31
|
+
parts.join(":")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
# The WMO-No. series codes as "wmo-<number>" (the proposed MRN
|
|
37
|
+
# form "urn:mrn:wmo:pub:wmo-1364:ed2025"); the S-100 specs keep
|
|
38
|
+
# their lexical form lowercased ("s-411").
|
|
39
|
+
def code_segment
|
|
40
|
+
if identifier.is_a?(Identifiers::Publication)
|
|
41
|
+
"wmo-#{identifier.number}"
|
|
42
|
+
else
|
|
43
|
+
"s-#{identifier.number}"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# URN for an annex: the base specification's code, then an "annex"
|
|
48
|
+
# segment (lettered form for the "ANNEX A" style, bare for "Annex"
|
|
49
|
+
# without a letter), then the annex's own edition.
|
|
50
|
+
def generate_annex
|
|
51
|
+
base = identifier.base
|
|
52
|
+
parts = ["urn:mrn:wmo:pub", "s-#{base.number}"]
|
|
53
|
+
parts << annex_segment
|
|
54
|
+
parts << "ed#{identifier.edition}" if identifier.edition
|
|
55
|
+
parts.join(":")
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def annex_segment
|
|
59
|
+
if identifier.letter
|
|
60
|
+
"annex-#{identifier.letter.downcase}"
|
|
61
|
+
else
|
|
62
|
+
"annex"
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Pubid
|
|
4
|
+
module Wmo
|
|
5
|
+
# Parses WMO MRN URNs back into identifiers.
|
|
6
|
+
#
|
|
7
|
+
# UrnGenerator emits:
|
|
8
|
+
# urn:mrn:wmo:pub:wmo-<number>[:ed<year>]
|
|
9
|
+
# urn:mrn:wmo:pub:s-<number>[:ed<x.y.z>]
|
|
10
|
+
# urn:mrn:wmo:pub:s-<number>:annex[-<letter>][:ed<x.y.z>]
|
|
11
|
+
#
|
|
12
|
+
# Examples:
|
|
13
|
+
# urn:mrn:wmo:pub:wmo-1364:ed2025 → WMO-No. 1364, 2025 edition
|
|
14
|
+
# urn:mrn:wmo:pub:s-411:ed1.2.1 → S-411 1.2.1
|
|
15
|
+
# urn:mrn:wmo:pub:s-411:annex-a → S-411 Annex A
|
|
16
|
+
class UrnParser < Pubid::UrnParser::Base
|
|
17
|
+
PREFIX = "urn:mrn:wmo:pub:"
|
|
18
|
+
|
|
19
|
+
def parse_urn(urn)
|
|
20
|
+
body = strip_mrn_namespace(urn)
|
|
21
|
+
parts = split_parts(body)
|
|
22
|
+
code = parts.fetch(0)
|
|
23
|
+
segments = parts.drop(1)
|
|
24
|
+
|
|
25
|
+
if (publication = code.match(/\Awmo-(\d+)\z/i))
|
|
26
|
+
parse_publication(publication[1], segments)
|
|
27
|
+
elsif (standard = code.match(/\As-(\d+)\z/i))
|
|
28
|
+
parse_standard(standard[1], segments)
|
|
29
|
+
else
|
|
30
|
+
raise ::Pubid::Errors::UrnParseError,
|
|
31
|
+
"Invalid WMO URN code segment: #{code.inspect}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def strip_mrn_namespace(urn)
|
|
38
|
+
unless urn.downcase.start_with?(PREFIX)
|
|
39
|
+
raise ::Pubid::Errors::UrnParseError,
|
|
40
|
+
"Invalid WMO URN: #{urn.inspect}"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
urn[PREFIX.length..]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Publication segments: the single ed<year> edition. Rebuilt as the
|
|
47
|
+
# compact year form, which the text parser normalizes to the
|
|
48
|
+
# canonical comma face.
|
|
49
|
+
def parse_publication(number, segments)
|
|
50
|
+
edition = nil
|
|
51
|
+
|
|
52
|
+
segments.each do |seg|
|
|
53
|
+
raise_segment!(seg, "duplicate edition") if edition
|
|
54
|
+
edition = edition_value(seg, /\A\d{4}\z/)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
text = "WMO-No. #{number}"
|
|
58
|
+
text += ":ed#{edition}" if edition
|
|
59
|
+
flavor_parse(text)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Standard and annex segments: an optional annex segment (at most
|
|
63
|
+
# one), then the optional dotted edition. Rebuilt as the human
|
|
64
|
+
# forms.
|
|
65
|
+
#
|
|
66
|
+
# The annex segment is caseless in the MRN ("annex" / "annex-a"),
|
|
67
|
+
# so the rebuild picks the attested WMO face "Annex" (the DCEG
|
|
68
|
+
# docidentifier). The uppercase "ANNEX" form stays a parse-only
|
|
69
|
+
# human alias; its URN re-renders to the attested face.
|
|
70
|
+
def parse_standard(number, segments)
|
|
71
|
+
annex_letter = nil
|
|
72
|
+
edition = nil
|
|
73
|
+
has_annex = false
|
|
74
|
+
|
|
75
|
+
segments.each do |seg|
|
|
76
|
+
case seg
|
|
77
|
+
when /\Aannex(-([a-z]))?\z/i
|
|
78
|
+
raise_segment!(seg, "duplicate annex") if has_annex
|
|
79
|
+
|
|
80
|
+
has_annex = true
|
|
81
|
+
annex_letter = Regexp.last_match(2)&.upcase
|
|
82
|
+
else
|
|
83
|
+
raise_segment!(seg) if edition
|
|
84
|
+
|
|
85
|
+
edition = edition_value(seg, /\A\d+(\.\d+)+\z/)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
text = "S-#{number}"
|
|
90
|
+
text += " Annex" if has_annex
|
|
91
|
+
text += " #{annex_letter}" if annex_letter
|
|
92
|
+
text += " #{edition}" if edition
|
|
93
|
+
flavor_parse(text)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# The value of an "ed<value>" segment, validated against +shape+
|
|
97
|
+
# (a year for a publication, dotted for a standard or annex). Any
|
|
98
|
+
# other segment is a parse error, per the ISO urn_parser strictness.
|
|
99
|
+
def edition_value(seg, shape)
|
|
100
|
+
unless seg.match?(/\Aed/i)
|
|
101
|
+
raise_segment!(seg)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
edition = seg.sub(/\Aed/i, "")
|
|
105
|
+
return edition if edition.match?(shape)
|
|
106
|
+
|
|
107
|
+
raise_segment!(seg)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def raise_segment!(seg, reason = nil)
|
|
111
|
+
detail = reason ? " (#{reason})" : ""
|
|
112
|
+
raise ::Pubid::Errors::UrnParseError,
|
|
113
|
+
"Invalid WMO URN segment#{detail}: #{seg.inspect}"
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
end
|
data/lib/pubid/wmo.rb
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "pubid"
|
|
4
|
+
module Pubid
|
|
5
|
+
# WMO (World Meteorological Organization) document identifiers
|
|
6
|
+
# (pubid#763): the WMO-No. publication series and, since the JCOMM
|
|
7
|
+
# dissolution, the WMO-published S-100-family product specifications.
|
|
8
|
+
#
|
|
9
|
+
# WMO-No. 1364 the WMO-No. series, bare
|
|
10
|
+
# WMO-No. 1364, 2025 edition year edition (calendar years)
|
|
11
|
+
# S-411 WMO-published S-100 spec, bare
|
|
12
|
+
# S-411 1.2.1 dotted edition (the S-411 repo form)
|
|
13
|
+
# S-411 Annex A annex wrapper (the DCEG docidentifier)
|
|
14
|
+
#
|
|
15
|
+
# The S-lexical type assignment is the #763 ruling: the lexical shape is
|
|
16
|
+
# the IHO S-100 form, but the flavor owns the WMO-published documents —
|
|
17
|
+
# the same publisher-parameterised split as IALA's S-201 (Pubid::Iala,
|
|
18
|
+
# urn:mrn:iala:pub:s-201:ed2.0.0). See lib/pubid/wmo/CLAUDE.md.
|
|
19
|
+
module Wmo
|
|
20
|
+
extend Pubid::PrefixesSupport
|
|
21
|
+
|
|
22
|
+
# The leading series token of the WMO-No. publication series. The
|
|
23
|
+
# S-100 lexical form ("S-411") deliberately leads NO prefix: a bare
|
|
24
|
+
# S-number is the shared S-100 shape of two assigning authorities
|
|
25
|
+
# (IHO and WMO), so each flavor parses it and neither owns the
|
|
26
|
+
# routing (the pubid#469 dual-perspective policy).
|
|
27
|
+
PREFIXES = ["WMO-No."].freeze
|
|
28
|
+
|
|
29
|
+
autoload :Builder, "#{__dir__}/wmo/builder"
|
|
30
|
+
autoload :Identifier, "#{__dir__}/wmo/identifier"
|
|
31
|
+
autoload :Identifiers, "#{__dir__}/wmo/identifiers"
|
|
32
|
+
autoload :Parser, "#{__dir__}/wmo/parser"
|
|
33
|
+
autoload :Renderer, "#{__dir__}/wmo/renderer"
|
|
34
|
+
autoload :UrnGenerator, "#{__dir__}/wmo/urn_generator"
|
|
35
|
+
autoload :UrnParser, "#{__dir__}/wmo/urn_parser"
|
|
36
|
+
autoload :PubidUrnSchema, "#{__dir__}/wmo/pubid_urn_schema"
|
|
37
|
+
|
|
38
|
+
# Parse a WMO identifier string into an identifier object.
|
|
39
|
+
# @param identifier [String] The WMO identifier string to parse
|
|
40
|
+
# @return [Pubid::Wmo::Identifier]
|
|
41
|
+
def self.parse(identifier)
|
|
42
|
+
Identifier.parse(identifier)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Per-flavor format registry: inherits global formats, overrides :human
|
|
46
|
+
Identifier.format_registry = FormatRegistry.new(parent: ::Pubid::Identifier.format_registry)
|
|
47
|
+
Identifier.format_registry.register(:human, renderer: Wmo::Renderer)
|
|
48
|
+
|
|
49
|
+
# Auto-discover all identifier types from the Identifiers namespace.
|
|
50
|
+
# @return [Array<Class>] identifier classes (Pubid::Identifier subclasses)
|
|
51
|
+
def self.identifier_types
|
|
52
|
+
@identifier_types ||= Identifiers.constants
|
|
53
|
+
.filter_map { |c| resolve_identifier_constant(c) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# One Identifiers constant as an identifier class, or nil: a constant
|
|
57
|
+
# that does not resolve, or resolves to anything but a Pubid::Identifier
|
|
58
|
+
# subclass, is not a type.
|
|
59
|
+
# @param const [Symbol]
|
|
60
|
+
# @return [Class, nil]
|
|
61
|
+
def self.resolve_identifier_constant(const)
|
|
62
|
+
klass = Identifiers.const_get(const)
|
|
63
|
+
return if !klass.is_a?(Class) || !(klass < Pubid::Identifier)
|
|
64
|
+
|
|
65
|
+
klass unless klass == Identifier
|
|
66
|
+
rescue NameError
|
|
67
|
+
nil
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# WMO identifiers carry no typed stages.
|
|
71
|
+
# @return [Array<Pubid::Components::TypedStage>]
|
|
72
|
+
def self.all_typed_stages
|
|
73
|
+
[]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Lookup: type code -> identifier class
|
|
77
|
+
# @param code [String, Symbol]
|
|
78
|
+
# @return [Class, nil]
|
|
79
|
+
def self.locate_type(code)
|
|
80
|
+
identifier_types.find { |t| t.type[:key].to_s == code.to_s }
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# WMO identifiers carry no typed stages.
|
|
84
|
+
# @param _abbr [String, Symbol]
|
|
85
|
+
# @return [nil]
|
|
86
|
+
def self.locate_stage(_abbr)
|
|
87
|
+
nil
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
Pubid::Registry.register(:wmo, Pubid::Wmo)
|
data/lib/pubid.rb
CHANGED
|
@@ -285,6 +285,7 @@ module Pubid
|
|
|
285
285
|
autoload :Sae, "pubid/sae"
|
|
286
286
|
autoload :Tgpp, "pubid/tgpp"
|
|
287
287
|
autoload :Un, "pubid/un"
|
|
288
|
+
autoload :Wmo, "pubid/wmo"
|
|
288
289
|
autoload :Xsf, "pubid/xsf"
|
|
289
290
|
autoload :W3c, "pubid/w3c"
|
|
290
291
|
|
|
@@ -502,6 +503,14 @@ module Pubid
|
|
|
502
503
|
|
|
503
504
|
prefix_owners = candidates_by_prefix(string)
|
|
504
505
|
(prefix_owners + other_candidates(prefix_owners)).each do |mod|
|
|
506
|
+
# An umbrella flavor (ANSI) also parses the joint prefix of a
|
|
507
|
+
# co-publisher that has its own flavor; that flavor's parse wins.
|
|
508
|
+
# Only as a prefix owner: in the exhaustive pass the umbrella is one
|
|
509
|
+
# flavor among the others, and stopping there would skip the rest.
|
|
510
|
+
if fallback && routing_umbrella?(mod) && prefix_owners.include?(mod)
|
|
511
|
+
return fallback
|
|
512
|
+
end
|
|
513
|
+
|
|
505
514
|
begin
|
|
506
515
|
parsed = mod.parse(string)
|
|
507
516
|
rescue Pubid::Errors::ParseError => e
|
|
@@ -565,10 +574,19 @@ module Pubid
|
|
|
565
574
|
routing_table.each do |prefix, modules|
|
|
566
575
|
ordered.concat(modules) if prefix_match?(string, prefix)
|
|
567
576
|
end
|
|
568
|
-
|
|
577
|
+
# An umbrella flavor goes after the other owners (stable partition).
|
|
578
|
+
ordered.compact.uniq.partition { |mod| !routing_umbrella?(mod) }.flatten
|
|
569
579
|
end
|
|
570
580
|
private_class_method :candidates_by_prefix
|
|
571
581
|
|
|
582
|
+
# @param mod [Module] a flavor module
|
|
583
|
+
# @return [Boolean] see {PrefixesSupport#routing_umbrella?}
|
|
584
|
+
# @api private
|
|
585
|
+
def self.routing_umbrella?(mod)
|
|
586
|
+
mod.respond_to?(:routing_umbrella?) && mod.routing_umbrella?
|
|
587
|
+
end
|
|
588
|
+
private_class_method :routing_umbrella?
|
|
589
|
+
|
|
572
590
|
# Every other registered flavor, for the exhaustive second pass.
|
|
573
591
|
#
|
|
574
592
|
# @param exclude [Array<Module>] modules already tried
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pubid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.48
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -156,6 +156,8 @@ files:
|
|
|
156
156
|
- data/parg/tgpp.json
|
|
157
157
|
- data/parg/un.json
|
|
158
158
|
- data/parg/w3c.json
|
|
159
|
+
- data/parg/wmo.json
|
|
160
|
+
- data/parg/wmo.parg
|
|
159
161
|
- data/parg/xsf.json
|
|
160
162
|
- data/plateau/update_codes.yaml
|
|
161
163
|
- lib/pubid.rb
|
|
@@ -188,6 +190,7 @@ files:
|
|
|
188
190
|
- lib/pubid/amca/urn_generator.rb
|
|
189
191
|
- lib/pubid/amca/urn_parser.rb
|
|
190
192
|
- lib/pubid/ansi.rb
|
|
193
|
+
- lib/pubid/ansi/CLAUDE.md
|
|
191
194
|
- lib/pubid/ansi/builder.rb
|
|
192
195
|
- lib/pubid/ansi/identifier.rb
|
|
193
196
|
- lib/pubid/ansi/identifiers.rb
|
|
@@ -1205,6 +1208,19 @@ files:
|
|
|
1205
1208
|
- lib/pubid/w3c/renderer.rb
|
|
1206
1209
|
- lib/pubid/w3c/urn_generator.rb
|
|
1207
1210
|
- lib/pubid/w3c/urn_parser.rb
|
|
1211
|
+
- lib/pubid/wmo.rb
|
|
1212
|
+
- lib/pubid/wmo/CLAUDE.md
|
|
1213
|
+
- lib/pubid/wmo/builder.rb
|
|
1214
|
+
- lib/pubid/wmo/identifier.rb
|
|
1215
|
+
- lib/pubid/wmo/identifiers.rb
|
|
1216
|
+
- lib/pubid/wmo/identifiers/annex.rb
|
|
1217
|
+
- lib/pubid/wmo/identifiers/publication.rb
|
|
1218
|
+
- lib/pubid/wmo/identifiers/standard.rb
|
|
1219
|
+
- lib/pubid/wmo/parser.rb
|
|
1220
|
+
- lib/pubid/wmo/pubid_urn_schema.rb
|
|
1221
|
+
- lib/pubid/wmo/renderer.rb
|
|
1222
|
+
- lib/pubid/wmo/urn_generator.rb
|
|
1223
|
+
- lib/pubid/wmo/urn_parser.rb
|
|
1208
1224
|
- lib/pubid/xsf.rb
|
|
1209
1225
|
- lib/pubid/xsf/CLAUDE.md
|
|
1210
1226
|
- lib/pubid/xsf/builder.rb
|
|
@@ -1248,7 +1264,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
1248
1264
|
- !ruby/object:Gem::Version
|
|
1249
1265
|
version: '0'
|
|
1250
1266
|
requirements: []
|
|
1251
|
-
rubygems_version: 4.0.
|
|
1267
|
+
rubygems_version: 4.0.23
|
|
1252
1268
|
specification_version: 4
|
|
1253
1269
|
summary: The international publication identifier (PubID) library for Ruby.
|
|
1254
1270
|
test_files: []
|