pubid 2.0.51 → 2.0.53

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.
@@ -2,25 +2,47 @@
2
2
 
3
3
  module Pubid
4
4
  module Iho
5
- # Parses IHO URNs back into identifiers through the documented
6
- # positional segment grammar (the same grammar the generator emits;
7
- # the segment table lives in the grammar header and the flavor notes):
5
+ # Parses IHO URNs back into identifiers, both emitted schemes:
6
+ #
7
+ # == The adopted IHO MRN guidance form (S/P/M emission)
8
+ #
9
+ # urn:mrn:iho:pub:<type>:<name>[:<edition>][:<trailing atoms>...]
10
+ #
11
+ # - <type>: spec / per / reg — the guidance publication types
12
+ # (Standards and Specifications, periodic publications,
13
+ # Miscellaneous Base Regulatory Publications); each maps back to
14
+ # its series letter.
15
+ # - <name>: sNNN — the lowercase series letter + number; the S-158
16
+ # member joins hyphenated (s158-102), the fleet extension of the
17
+ # guidance for compound publication numbers.
18
+ # - <edition>: the bare dotted x.y.z right after the name (the
19
+ # guidance's canonical 4th segment; the S-98 precedent).
20
+ # - The trailing atoms are the lowercase marker segments: a
21
+ # component's own edition rides as ed- right after it (the duality
22
+ # law), the Appendix subnumber hyphen-joins its appendix
23
+ # (appendix-D-2), values case-preserved. The guidance's bare
24
+ # correction/clarification slots (the s57:3:1 form) are not modeled
25
+ # faces — a bare digit tail segment rejects as unexpected.
26
+ #
27
+ # == The legacy positional form (B/C emission; decodable for every
28
+ # series, never emitted for S/P/M)
8
29
  #
9
30
  # urn:iho:<type>:<number>[:ed-<x.y.z>][:sup-<n>][:part-<X>]
10
31
  # [:spec-<n>[:specsub-<n>][:specvar-<X>]][:annex-<A>]
11
32
  # [:appendix-<B>][:<sub>][:vol-<n>][:issue-<n>][:year-<yyyy>]
12
33
  #
13
34
  # Segment discipline (mirrors the ISO URN parser's strictness):
14
- # - the docnumber occupies every leading bare number segment up to
15
- # the first marker, so a colon number ("158:100") round-trips
16
- # without escaping;
35
+ # - the docnumber occupies the first bare number segment; a further
36
+ # bare digit segment binds checks_for — the S-158 member number as
37
+ # its own segment ("urn:iho:s:158:100"), never glued into the
38
+ # number (issue #774);
17
39
  # - every other component is a marker-prefixed segment validated
18
40
  # against its own value pattern — unknown, reordered or junk
19
41
  # segments raise {Pubid::Errors::UrnParseError}, never
20
42
  # mis-consume;
21
- # - the appendix subnumber is a bare digit atom allowed only
22
- # directly after its appendix segment (a year is always
23
- # marker-tagged, so a bare digit there can only be the subnumber);
43
+ # - the appendix subnumber is either the bare digit atom directly
44
+ # after its appendix segment (the legacy emission) or the
45
+ # hyphen-joined compound value ("appendix-D-2", the MRN emission);
24
46
  # - the issue is allowed only beside its volume and validated as
25
47
  # digits;
26
48
  # - the S-4 spec atom is a child of its part (the citation letter
@@ -35,22 +57,39 @@ module Pubid
35
57
  # appendix values stored the subnumber inside one string, "D-2",
36
58
  # which decodes into the two components).
37
59
  #
60
+ # Both paths build through Builder.build — the S-158 alias
61
+ # unification (a draft-era part-S-102 URN decodes to the checks_for
62
+ # identity) and every other semantic validation is shared with the
63
+ # text parse.
64
+ #
38
65
  # Examples:
39
- # - urn:iho:s:44:ed-5.0.0 → IHO S-44 5.0.0
40
- # - urn:iho:s:100:ed-5.0.0:part-2 → IHO S-100 5.0.0 Part 2
41
- # - urn:iho:s:122:ed-1.0.0:appendix-D:2 → IHO S-122 1.0.0 Appendix D-2
42
- # - urn:iho:p:5:vol-2024 → IHO P-5 Vol. 2024
43
- # - urn:iho:p:1:vol-30:issue-2 → IHO P-1 Vol. 30 (2)
44
- # - urn:iho:s:158:100 → IHO S-158:100
45
- # - urn:iho:s:4:ed-4.10.0:part-B:spec-401 → IHO S-4 4.10.0 B-401
66
+ # - urn:mrn:iho:pub:spec:s44:5.0.0 → IHO S-44 5.0.0
67
+ # - urn:mrn:iho:pub:spec:s158-102:1.0.0 → IHO S-158:102 1.0.0
68
+ # - urn:mrn:iho:pub:reg:m2:sup-1 → IHO M-2 Sup 1
69
+ # - urn:mrn:iho:pub:per:p1:vol-30:issue-2 → IHO P-1 Vol. 30 (2)
70
+ # - urn:iho:s:44:ed-5.0.0 → IHO S-44 5.0.0
71
+ # - urn:iho:s:158:100:ed-1.0.0 → IHO S-158:100 1.0.0
72
+ # - urn:iho:s:4:ed-4.10.0:part-B:spec-401 → IHO S-4 4.10.0 B-401
46
73
  class UrnParser < Pubid::UrnParser::Base
47
74
  TYPE_LETTERS = %w[s p m b c].freeze
48
75
 
76
+ # The guidance publication type -> series letter (the emission's
77
+ # MRN_TYPES inverted). bathy/cb have no series in this flavor; an
78
+ # unknown type rejects.
79
+ MRN_TYPE_LETTERS = { "spec" => "S", "per" => "P", "reg" => "M" }.freeze
80
+
81
+ MRN_PREFIX = "urn:mrn:iho:pub:"
82
+ # The publication name: the lowercase series letter + number, the
83
+ # S-158 member hyphen-joined (s158-102).
84
+ MRN_NAME_RE = /\A([spmbc])(\d+)(?:-(\d+))?\z/
85
+
49
86
  # Marker => attribute, with the value pattern each marker's slot
50
87
  # accepts. The patterns mirror the grammar's own production rules
51
88
  # (upper-case letters are case-preserved; "part" allows the
52
89
  # digits-then-letters compound like "4a" beside a lone letter; the
53
- # volume takes any serial locator, yearbook years included).
90
+ # volume takes any serial locator, yearbook years included;
91
+ # "appendix" allows the hyphen-joined compound "D-2" — the MRN
92
+ # emission — which splits into the appendix and its subnumber).
54
93
  MARKERS = {
55
94
  "ed" => [:edition, /\A\d+\.\d+\.\d+\z/],
56
95
  "sup" => [:supplement, /\A\d+\z/],
@@ -59,7 +98,7 @@ module Pubid
59
98
  "specsub" => [:spec_sub, /\A\d+\z/],
60
99
  "specvar" => [:spec_variant, /\A[A-Z]+\z/],
61
100
  "annex" => [:annex, /\A[A-Z]\z/],
62
- "appendix" => [:appendix, /\A(?:[A-Z]|\d+)\z/],
101
+ "appendix" => [:appendix, /\A(?:[A-Z](?:-\d+)?|\d+)\z/],
63
102
  "vol" => [:volume, /\A\d+\z/],
64
103
  "issue" => [:issue, /\A\d+\z/],
65
104
  "year" => [:year, /\A(?:19|20)\d{2}\z/],
@@ -100,11 +139,64 @@ module Pubid
100
139
  SUBNUMBER_RE = /\A\d+\z/
101
140
  # The docnumber's own charset: digits with : / - suffix runs.
102
141
  NUMBER_RE = /\A\d+(?:[:\/-]\d+)*\z/
142
+ # The further bare segments that bind the S-158 member number.
143
+ CHECKS_SEGMENT_RE = /\A\d+\z/
103
144
 
104
145
  def parse_urn(urn)
146
+ return parse_mrn_urn(urn) if urn.downcase.start_with?(MRN_PREFIX)
147
+
148
+ parse_legacy_urn(urn)
149
+ end
150
+
151
+ private
152
+
153
+ # The guidance-form decode: publication type, name (number +
154
+ # optional S-158 member), the bare dotted edition, then the shared
155
+ # marker machinery (the positional ed-/year- attachment included).
156
+ # The body is NOT case-folded: values are case-preserved
157
+ # (appendix-D-2, part-B); only the type token lowercases.
158
+ def parse_mrn_urn(urn)
159
+ segments = urn[MRN_PREFIX.length..].split(":")
160
+ type_token = segments.shift.to_s.downcase
161
+ letter = MRN_TYPE_LETTERS.fetch(type_token) do
162
+ raise Pubid::Errors::UrnParseError,
163
+ "Unknown IHO publication type #{type_token.inspect} " \
164
+ "in #{urn.inspect}"
165
+ end
166
+ attrs = mrn_name_attributes!(segments, urn)
167
+ # the bare dotted edition in the canonical 4th segment
168
+ if segments.first&.match?(LEGACY_EDITION_RE)
169
+ attrs[:edition] = segments.shift
170
+ end
171
+ ctx = { component: nil, edition_owner: nil }
172
+ consume_segments!(attrs, segments, ctx, urn)
173
+ build_identifier({ type: letter, **attrs }, urn)
174
+ end
175
+
176
+ # The name segment: sNNN, or s158-NNN with the S-158 member bound
177
+ # as its own component. The series letter maps back through the
178
+ # type token; the name carries only the number (and member).
179
+ def mrn_name_attributes!(segments, urn)
180
+ name = segments.shift.to_s
181
+ match = MRN_NAME_RE.match(name)
182
+ unless match
183
+ raise Pubid::Errors::UrnParseError,
184
+ "Unknown IHO publication name #{name.inspect} in #{urn.inspect}"
185
+ end
186
+
187
+ attrs = { number: match[2] }
188
+ # the member designator rides the S-158 anchor; another series
189
+ # rejects through the builder's anchor assert
190
+ attrs[:checks_for] = match[3] if match[3]
191
+ attrs
192
+ end
193
+
194
+ # The legacy positional decode (the pre-guidance emission shape and
195
+ # every legacy spelling it decodes).
196
+ def parse_legacy_urn(urn)
105
197
  segments = split_parts(strip_namespace(urn))
106
198
  type_token = read_type!(segments, urn)
107
- attrs = { number: consume_number!(segments, urn) }
199
+ attrs = consume_number!(segments, urn)
108
200
  # Positional context: the component the upcoming ed-/year- would
109
201
  # attach to, and the owner of the edition just consumed (a year
110
202
  # belongs to a component only when it follows that component's
@@ -114,14 +206,17 @@ module Pubid
114
206
  build_identifier({ type: type_token.upcase, **attrs }, urn)
115
207
  end
116
208
 
117
- private
118
-
119
209
  # The semantic validations the builder applies to the decoded shape
120
- # (the S-4 anchor, the citation letter) are URN validation at this
121
- # layer: a URN that asserts a citation it cannot carry is a
122
- # malformed URN, and the raw ArgumentError stays as the cause.
210
+ # (the S-4 anchor, the citation letter, the S-158 checks anchor)
211
+ # are URN validation at this layer: a URN that asserts a shape it
212
+ # cannot carry is a malformed URN, and the raw ArgumentError stays
213
+ # as the cause. The URN is the canonical shape, so the decoded
214
+ # identifier drops the parse-only spelling face — a legacy
215
+ # part-S-102 decode renders the canonical colon designator.
123
216
  def build_identifier(hash, urn)
124
- Builder.build(hash)
217
+ identifier = Builder.build(hash)
218
+ identifier.checks_for_face = nil
219
+ identifier
125
220
  rescue ArgumentError => e
126
221
  raise Pubid::Errors::UrnParseError,
127
222
  "#{e.message} in #{urn.inspect}"
@@ -141,20 +236,23 @@ module Pubid
141
236
  end
142
237
  end
143
238
 
144
- # The number occupies every leading bare number segment; the first
145
- # segment that is not number-shaped ends it (and the segment loop
146
- # below decides whether it is a legal marker).
239
+ # The first bare number segment is the docnumber; the next bare
240
+ # digit segment binds the S-158 member number (checks_for — the
241
+ # member as its own segment, never glued into the number), and
242
+ # anything else ends the number run (the segment loop below
243
+ # decides whether it is a legal marker).
147
244
  def consume_number!(segments, urn)
148
- number = []
149
- while segments.first&.match?(NUMBER_RE)
150
- number << segments.shift
151
- end
152
- if number.empty?
245
+ number = segments.shift.to_s
246
+ unless number.match?(NUMBER_RE)
153
247
  raise Pubid::Errors::UrnParseError,
154
248
  "Missing docnumber in #{urn.inspect}"
155
249
  end
156
250
 
157
- number.join(":")
251
+ attrs = { number: number }
252
+ if segments.first&.match?(CHECKS_SEGMENT_RE)
253
+ attrs[:checks_for] = segments.shift
254
+ end
255
+ attrs
158
256
  end
159
257
 
160
258
  def consume_segment!(attrs, segments, ctx, urn)
@@ -174,8 +272,9 @@ module Pubid
174
272
 
175
273
  # A marker segment: validate the value against the marker's own
176
274
  # pattern, store it, and claim the bare atom that follows an
177
- # appendix (its subnumber — the only bare atom allowed after a
178
- # marker). The ed- and year- markers are POSITIONAL: the edition
275
+ # appendix (its subnumber — the legacy emission's only bare atom
276
+ # after a marker; the MRN emission hyphen-joins the compound
277
+ # instead). The ed- and year- markers are POSITIONAL: the edition
179
278
  # attaches to the component it follows (the base when no component
180
279
  # precedes it), and a year belongs to a component only when it
181
280
  # follows that component's own edition — the separately-published
@@ -188,7 +287,16 @@ module Pubid
188
287
  return consume_positional!(attrs, key, value, ctx, urn) if
189
288
  POSITIONAL_MARKERS.include?(key)
190
289
 
191
- store!(attrs, key, value, urn)
290
+ # The hyphen-joined compound appendix value ("D-2", the MRN
291
+ # emission) splits into the appendix and its subnumber; the
292
+ # legacy emission instead carries the subnumber as the bare
293
+ # atom consumed below.
294
+ if key == :appendix && (compound = /\A([A-Z])-(\d+)\z/.match(value))
295
+ store!(attrs, :appendix, compound[1], urn)
296
+ store!(attrs, :appendix_subnumber, compound[2], urn)
297
+ else
298
+ store!(attrs, key, value, urn)
299
+ end
192
300
  ctx[:component] = key
193
301
  ctx[:edition_owner] = nil
194
302
  consume_subnumber!(attrs, key, segments, ctx, urn)
data/lib/pubid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pubid
4
- VERSION = "2.0.51"
4
+ VERSION = "2.0.53"
5
5
  end
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.51
4
+ version: 2.0.53
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
@@ -675,6 +675,7 @@ files:
675
675
  - lib/pubid/iala/identifiers/letter.rb
676
676
  - lib/pubid/iala/identifiers/manual.rb
677
677
  - lib/pubid/iala/identifiers/model_course.rb
678
+ - lib/pubid/iala/identifiers/product_specification.rb
678
679
  - lib/pubid/iala/identifiers/publication.rb
679
680
  - lib/pubid/iala/identifiers/recommendation.rb
680
681
  - lib/pubid/iala/identifiers/report.rb
@@ -683,6 +684,7 @@ files:
683
684
  - lib/pubid/iala/parser.rb
684
685
  - lib/pubid/iala/pubid_urn_schema.rb
685
686
  - lib/pubid/iala/renderer.rb
687
+ - lib/pubid/iala/urn.adoc
686
688
  - lib/pubid/iala/urn_generator.rb
687
689
  - lib/pubid/iala/urn_parser.rb
688
690
  - lib/pubid/iana.rb
@@ -843,6 +845,7 @@ files:
843
845
  - lib/pubid/iho/pubid_urn_schema.rb
844
846
  - lib/pubid/iho/renderer.rb
845
847
  - lib/pubid/iho/reserved_specs.rb
848
+ - lib/pubid/iho/urn.adoc
846
849
  - lib/pubid/iho/urn_generator.rb
847
850
  - lib/pubid/iho/urn_parser.rb
848
851
  - lib/pubid/isbn.rb