pubid-iso 0.7.8 → 0.8.0
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 +3 -3
- data/lib/pubid/iso/identifier/amendment.rb +1 -1
- data/lib/pubid/iso/identifier/base.rb +38 -27
- data/lib/pubid/iso/identifier/international_standard.rb +20 -1
- data/lib/pubid/iso/identifier/supplement.rb +1 -1
- data/lib/pubid/iso/parser.rb +13 -5
- data/lib/pubid/iso/parser_urn.rb +88 -0
- data/lib/pubid/iso/renderer/base.rb +13 -11
- data/lib/pubid/iso/renderer/supplement.rb +6 -6
- data/lib/pubid/iso/renderer/urn-amendment.rb +2 -2
- data/lib/pubid/iso/renderer/urn-corrigendum.rb +2 -2
- data/lib/pubid/iso/renderer/urn-dir.rb +6 -7
- data/lib/pubid/iso/renderer/urn-extract.rb +2 -2
- data/lib/pubid/iso/renderer/urn-supplement.rb +2 -2
- data/lib/pubid/iso/renderer/urn-tc.rb +2 -2
- data/lib/pubid/iso/renderer/urn.rb +7 -3
- data/lib/pubid/iso/transformer.rb +122 -75
- data/lib/pubid/iso/version.rb +1 -1
- data/stages.yaml +4 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ff5f4411528d056d31e56420d5c9f34b8e896e7f29e587641e495042a81322
|
4
|
+
data.tar.gz: 9818b9a1c8be3b1c390bca461295e6058ebac2102a9bb0112b694b76cf1df1d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45eadb0c1cf4394f171b9a6e32e1895df9ce7e20085882521fa5c84c6e89dceb971f2abf55851eb9a4453a38926f1eddd468a383f75d0138fe2bc5bce8c2956d
|
7
|
+
data.tar.gz: 83546bfa875b22228644c7ae30e24fa798748dee012f48e0dd03f47d2b8c02b43081a673ca46423cf5c43197bed0a344bcbee0f66a54c9eda6dfd95d0cba11f9
|
data/README.adoc
CHANGED
@@ -154,11 +154,11 @@ to see all available options.
|
|
154
154
|
language: "en"
|
155
155
|
)
|
156
156
|
> pubid = Pubid::Iso::Identifier.create(type: :amd, number: "1", year: "2021", stage: "DAM", base: base)
|
157
|
-
> pubid.to_s(:ref_num_short)
|
157
|
+
> pubid.to_s(format: :ref_num_short)
|
158
158
|
=> "ISO 8601-1:2019/DAM 1:2021(E)"
|
159
|
-
> pubid.to_s(:ref_dated)
|
159
|
+
> pubid.to_s(format: :ref_dated)
|
160
160
|
=> "ISO 8601-1:2019/DAM 1:2021"
|
161
|
-
> pubid.to_s(:ref_undated)
|
161
|
+
> pubid.to_s(format: :ref_undated)
|
162
162
|
=> "ISO 8601-1:2019/DAM 1"
|
163
163
|
----
|
164
164
|
|
@@ -4,7 +4,7 @@ require_relative "../renderer/urn-amendment"
|
|
4
4
|
module Pubid::Iso
|
5
5
|
module Identifier
|
6
6
|
class Amendment < Supplement
|
7
|
-
def_delegators
|
7
|
+
def_delegators "Pubid::Iso::Identifier::Amendment", :type
|
8
8
|
|
9
9
|
TYPED_STAGES = {
|
10
10
|
damd: {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "forwardable"
|
2
2
|
require_relative "../renderer/urn"
|
3
3
|
require_relative "../renderer/urn-tc"
|
4
4
|
|
@@ -114,46 +114,55 @@ module Pubid::Iso
|
|
114
114
|
supplements.select { |supplement| supplement.type[:key] == type }.first
|
115
115
|
end
|
116
116
|
|
117
|
-
def transform_supplements(supplements_params, base_params)
|
118
|
-
|
119
|
-
Identifier.create(number: supplement[:number], year: supplement[:year],
|
120
|
-
month: supplement[:month],
|
121
|
-
stage: supplement[:typed_stage], edition: supplement[:edition],
|
122
|
-
iteration: supplement[:iteration], type: (supplement[:type] || !supplement[:typed_stage] && :sup),
|
123
|
-
publisher: supplement[:publisher], base: Identifier.create(**base_params))
|
124
|
-
end
|
117
|
+
def transform_supplements(supplements_params, base_params) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
118
|
+
all_parts = base_params.delete(:all_parts)
|
125
119
|
|
126
|
-
|
120
|
+
supplements = create_supplements supplements_params, base_params
|
127
121
|
|
122
|
+
if supplements.count == 1
|
123
|
+
supplement = supplements.first
|
128
124
|
# update corrigendum base to amendment
|
129
|
-
|
125
|
+
elsif supplements_has_type?(supplements, :cor) &&
|
130
126
|
(supplements_has_type?(supplements, :amd) ||
|
131
127
|
supplements_has_type?(supplements, :sup)) && supplements.count == 2
|
132
128
|
|
133
129
|
supplement = supplement_by_type(supplements, :cor)
|
134
|
-
supplement.base = supplement_by_type(supplements, :amd) ||
|
135
|
-
supplement_by_type(supplements, :sup)
|
136
|
-
supplement
|
130
|
+
supplement.base = supplement_by_type(supplements, :amd) || supplement_by_type(supplements, :sup)
|
137
131
|
else
|
138
132
|
raise Errors::SupplementRenderingError, "don't know how to render provided supplements"
|
139
133
|
end
|
134
|
+
|
135
|
+
supplement.all_parts = all_parts if all_parts
|
136
|
+
supplement
|
137
|
+
end
|
138
|
+
|
139
|
+
def create_supplements(params, base_params)
|
140
|
+
params.map do |supplement|
|
141
|
+
Identifier.create(
|
142
|
+
number: supplement[:number], year: supplement[:year],
|
143
|
+
month: supplement[:month],
|
144
|
+
stage: supplement[:typed_stage], edition: supplement[:edition],
|
145
|
+
iteration: supplement[:iteration], type: supplement[:type] || !supplement[:typed_stage] && :sup,
|
146
|
+
publisher: supplement[:publisher], base: Identifier.create(**base_params)
|
147
|
+
)
|
148
|
+
end
|
140
149
|
end
|
141
150
|
|
142
|
-
def transform(params)
|
143
|
-
|
144
|
-
|
145
|
-
|
151
|
+
def transform(params) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
152
|
+
transformer = get_transformer_class.new
|
153
|
+
params = transformer.apply(root: params)
|
154
|
+
identifier_params = params.map { |k, v| transformer.apply(k => v) }.inject({}, :merge)
|
146
155
|
|
147
156
|
# return supplement if supplements applied
|
148
|
-
if identifier_params[:supplements]
|
157
|
+
if identifier_params[:supplements].is_a?(Array)
|
149
158
|
return transform_supplements(
|
150
159
|
identifier_params[:supplements],
|
151
|
-
identifier_params.dup.tap { |h| h.delete(:supplements) }
|
160
|
+
identifier_params.dup.tap { |h| h.delete(:supplements) },
|
152
161
|
)
|
153
162
|
end
|
154
163
|
|
155
164
|
if identifier_params[:extract]
|
156
|
-
base_parameters =
|
165
|
+
base_parameters = identifier_params.reject { |k, _| k == :extract }
|
157
166
|
|
158
167
|
return Identifier.create(base: Identifier.create(**base_parameters),
|
159
168
|
type: :ext, **identifier_params[:extract])
|
@@ -256,24 +265,26 @@ module Pubid::Iso
|
|
256
265
|
# :ref_undated -- reference undated: no language code + short form (DAM) + undated
|
257
266
|
# :ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated
|
258
267
|
# @return [String] pubid identifier
|
259
|
-
def to_s(lang: nil, with_edition: false, with_prf: false,
|
260
|
-
format: :ref_dated_long)
|
261
|
-
|
268
|
+
def to_s(lang: nil, with_edition: false, with_prf: false, format: :ref_dated_long)
|
262
269
|
options = resolve_format(format)
|
263
270
|
options[:with_edition] = with_edition
|
264
271
|
options[:with_prf] = with_prf
|
265
272
|
options[:language] = lang
|
266
273
|
|
267
274
|
self.class.get_renderer_class.new(to_h(deep: false)).render(**options) +
|
268
|
-
|
269
|
-
render_joint_document(@joint_document)
|
270
|
-
end.to_s
|
275
|
+
render_joint_document(@joint_document) + render_all_parts
|
271
276
|
end
|
272
277
|
|
273
278
|
def render_joint_document(joint_document)
|
279
|
+
return "" if joint_document.nil? || joint_document.to_s.empty?
|
280
|
+
|
274
281
|
"|#{@joint_document}"
|
275
282
|
end
|
276
283
|
|
284
|
+
def render_all_parts
|
285
|
+
all_parts ? " (all parts)" : ""
|
286
|
+
end
|
287
|
+
|
277
288
|
# Return typed stage abbreviation, eg. "FDTR", "DIS", "TR"
|
278
289
|
# returns root identifier
|
279
290
|
def root
|
@@ -19,10 +19,29 @@ module Pubid::Iso
|
|
19
19
|
name: "Final Draft International Standard",
|
20
20
|
harmonized_stages: %w[50.00 50.20 50.60 50.92 50.98 50.99],
|
21
21
|
},
|
22
|
+
wdr: {
|
23
|
+
abbr: "WDR",
|
24
|
+
name: "Proposed for Withdrawal",
|
25
|
+
harmonized_stages: %w[90.92],
|
26
|
+
},
|
27
|
+
wda: {
|
28
|
+
abbr: "WDA",
|
29
|
+
name: "Withdrawal Approved",
|
30
|
+
harmonized_stages: %w[90.93],
|
31
|
+
},
|
32
|
+
wdar: {
|
33
|
+
abbr: "WDAR",
|
34
|
+
name: "Withdrawal Archived",
|
35
|
+
harmonized_stages: %w[95.99],
|
36
|
+
},
|
37
|
+
is: {
|
38
|
+
abbr: "IS",
|
39
|
+
name: "International Standard",
|
40
|
+
harmonized_stages: %w[60.00 60.60],
|
41
|
+
},
|
22
42
|
}.freeze
|
23
43
|
|
24
44
|
def initialize(stage: nil, iteration: nil, **opts)
|
25
|
-
|
26
45
|
if iteration && stage.nil?
|
27
46
|
raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
|
28
47
|
end
|
@@ -4,7 +4,7 @@ require_relative "../renderer/urn-supplement"
|
|
4
4
|
module Pubid::Iso
|
5
5
|
module Identifier
|
6
6
|
class Supplement < Base
|
7
|
-
def_delegators
|
7
|
+
def_delegators "Pubid::Iso::Identifier::Supplement", :type
|
8
8
|
|
9
9
|
TYPED_STAGES = {
|
10
10
|
dsuppl: {
|
data/lib/pubid/iso/parser.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require_relative "identifier/base"
|
2
2
|
require_relative "renderer/base"
|
3
|
+
require_relative "parser_urn"
|
3
4
|
|
4
5
|
module Pubid::Iso
|
5
6
|
class Parser < Pubid::Core::Parser
|
7
|
+
include Pubid::Iso::ParserUrn
|
8
|
+
|
6
9
|
STAGES = %w[NP NWIP WD CD FCD PRF AWI PWI FPD].freeze
|
7
10
|
TYPES = %w[DATA ISP IWA R TTA TS TR IS PAS Guide GUIDE DIR].freeze
|
8
11
|
# TYPED_STAGES = %w[DIS FDIS DPAS FDTR FDTS DTS DTR PDTR PDTS].freeze
|
@@ -118,7 +121,7 @@ module Pubid::Iso
|
|
118
121
|
rule(:supplement) do
|
119
122
|
((str("/") | space).maybe >>
|
120
123
|
(((stage.as(:typed_stage) >> space).maybe >> supplements.as(:type)) |
|
121
|
-
|
124
|
+
staged_supplement.as(:typed_stage)) >>
|
122
125
|
(space | str(".")).repeat(1).maybe >>
|
123
126
|
digits.as(:number).maybe >>
|
124
127
|
(str(".") >> digits.as(:iteration)).maybe >>
|
@@ -129,7 +132,7 @@ module Pubid::Iso
|
|
129
132
|
(
|
130
133
|
(((str("/") >> (str("Add") | str("ADD")).as(:type)) | (str(" — ") >> str("Addendum").as(:type))) |
|
131
134
|
(str("/") >> staged_addenda.as(:typed_stage))) >>
|
132
|
-
space >> digits.as(:number) >> (
|
135
|
+
space >> digits.as(:number) >> (str(":") >> digits.as(:year)).maybe
|
133
136
|
).repeat(1).as(:supplements)
|
134
137
|
end
|
135
138
|
|
@@ -166,6 +169,10 @@ module Pubid::Iso
|
|
166
169
|
space >> (str("Edition") | str("Ed")) >> space >> digits.as(:edition)
|
167
170
|
end
|
168
171
|
|
172
|
+
rule(:all_parts) do
|
173
|
+
space >> str("(all parts)").as(:all_parts)
|
174
|
+
end
|
175
|
+
|
169
176
|
rule(:dir_document_body) do
|
170
177
|
((str("DIR") | str("Directives Part") | str("Directives, Part") | str("Directives,")).as(:type) >> space).maybe >>
|
171
178
|
(str("JTC").as(:dirtype) >> space).maybe >>
|
@@ -177,7 +184,6 @@ module Pubid::Iso
|
|
177
184
|
dir_supplement_edition.maybe).repeat(1).as(:supplements)).maybe >>
|
178
185
|
# parse identifiers with publisher at the end, e.g. "ISO/IEC DIR 2 ISO"
|
179
186
|
(space >> organization.as(:publisher) >> (str(":") >> year).maybe).as(:edition).maybe
|
180
|
-
|
181
187
|
end
|
182
188
|
|
183
189
|
rule(:std_document_body) do
|
@@ -189,11 +195,13 @@ module Pubid::Iso
|
|
189
195
|
(str("|") >> (str("IDF").as(:publisher) >> space >> digits.as(:number)).as(:joint_document)).maybe >>
|
190
196
|
part.maybe >> iteration.maybe >>
|
191
197
|
(space? >> (str(":") | dash) >> year).maybe >>
|
198
|
+
edition.maybe >>
|
192
199
|
supplement.maybe >>
|
193
200
|
extract.maybe >>
|
194
201
|
addendum.maybe >>
|
195
202
|
edition.maybe >>
|
196
|
-
language.maybe
|
203
|
+
language.maybe >>
|
204
|
+
all_parts.maybe
|
197
205
|
end
|
198
206
|
|
199
207
|
rule(:identifier) do
|
@@ -209,6 +217,6 @@ module Pubid::Iso
|
|
209
217
|
(str(" + ") >> (originator >> space >> dir_document_body).as(:dir_joint_document)).maybe))
|
210
218
|
end
|
211
219
|
|
212
|
-
rule(:root) { identifier }
|
220
|
+
rule(:root) { identifier | urn_identifier }
|
213
221
|
end
|
214
222
|
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Pubid
|
2
|
+
module Iso
|
3
|
+
module ParserUrn
|
4
|
+
LANGUAGES = %w[en fr ru other].freeze
|
5
|
+
SUPPLEMENTS = %w[amd cor sup].freeze
|
6
|
+
|
7
|
+
def self.included(base) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
8
|
+
base.class_eval do # rubocop:disable Metrics/BlockLength
|
9
|
+
rule(:colon) { str(":") }
|
10
|
+
|
11
|
+
rule(:urn_organization) do
|
12
|
+
array_to_str(Parser::ORGANIZATIONS.map(&:downcase))
|
13
|
+
end
|
14
|
+
|
15
|
+
rule(:urn_publisher_copublisher) do
|
16
|
+
urn_organization.as(:publisher) >> (dash >> urn_organization.as(:copublisher)).repeat >> colon
|
17
|
+
end
|
18
|
+
|
19
|
+
rule(:urn_type) do
|
20
|
+
(array_to_str(Parser::TYPES.map(&:downcase)).as(:type) >> colon).maybe
|
21
|
+
end
|
22
|
+
|
23
|
+
rule(:urn_part) { (colon >> part).maybe }
|
24
|
+
|
25
|
+
rule(:urn_iteration) do
|
26
|
+
(str(".v") >> digits.as(:iteration)).maybe
|
27
|
+
end
|
28
|
+
|
29
|
+
rule(:stage_digits) do
|
30
|
+
match('\d').repeat(2, 2) >> str(".") >> match('\d').repeat(2, 2)
|
31
|
+
end
|
32
|
+
|
33
|
+
rule(:urn_stage_prefix) do
|
34
|
+
colon >> str("stage-")
|
35
|
+
end
|
36
|
+
|
37
|
+
rule(:urn_draft) do
|
38
|
+
str("draft") | str("published") | stage_digits
|
39
|
+
end
|
40
|
+
|
41
|
+
rule(:urn_stage) do
|
42
|
+
(urn_stage_prefix >> urn_draft.as(:stage) >> urn_iteration).maybe
|
43
|
+
end
|
44
|
+
|
45
|
+
rule(:urn_edition) do
|
46
|
+
(colon >> (str("ed-") >> digits.as(:edition))).maybe
|
47
|
+
end
|
48
|
+
|
49
|
+
rule(:urn_typed_stage) do
|
50
|
+
(urn_stage_prefix >> urn_draft.as(:typed_stage)).maybe
|
51
|
+
end
|
52
|
+
|
53
|
+
rule(:urn_supplement) do
|
54
|
+
(urn_typed_stage >>
|
55
|
+
colon >> (array_to_str(SUPPLEMENTS).as(:type) >>
|
56
|
+
(colon >> year_digits.as(:year)).maybe >>
|
57
|
+
(colon >> ((digits.as(:number) >> str(":v1")) | str("v") >> digits.as(:number))).maybe)
|
58
|
+
).repeat(1).as(:supplements).maybe
|
59
|
+
end
|
60
|
+
|
61
|
+
rule(:urn_extract) do
|
62
|
+
((urn_stage_prefix >> urn_draft).maybe >>
|
63
|
+
colon >> str("ext") >> colon >> year_digits.as(:year) >>
|
64
|
+
(colon >> str("v") >> digits.as(:number))).as(:extract).maybe
|
65
|
+
end
|
66
|
+
|
67
|
+
rule(:languages) do
|
68
|
+
array_to_str(LANGUAGES)
|
69
|
+
end
|
70
|
+
|
71
|
+
rule(:urn_language) do
|
72
|
+
(colon >> (languages >> (str(",") >> languages).repeat).as(:language)).maybe
|
73
|
+
end
|
74
|
+
|
75
|
+
rule(:urn_all_parts) do
|
76
|
+
(colon >> str("ser").as(:all_parts)).maybe
|
77
|
+
end
|
78
|
+
|
79
|
+
rule(:urn_identifier) do
|
80
|
+
str("urn:iso:std:") >> urn_publisher_copublisher >> urn_type >>
|
81
|
+
digits.as(:number) >> urn_part >> urn_stage >> urn_edition >>
|
82
|
+
urn_supplement >> urn_extract >> urn_language >> urn_all_parts
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -39,10 +39,9 @@ module Pubid::Iso::Renderer
|
|
39
39
|
@prerendered_params[:language].to_s
|
40
40
|
end
|
41
41
|
|
42
|
-
def render_base(_base, _opts, _params)
|
43
|
-
end
|
42
|
+
def render_base(_base, _opts, _params); end
|
44
43
|
|
45
|
-
def render_type_prefix(params, opts)
|
44
|
+
def render_type_prefix(params, opts) # rubocop:disable Metrics/AbcSize
|
46
45
|
result = params[:stage].nil? || !params[:stage].is_a?(Pubid::Core::TypedStage) ? self.class::TYPE : ""
|
47
46
|
|
48
47
|
if params[:stage] != "" && !params[:stage].to_s(with_prf: opts[:with_prf]).empty? && !result.empty?
|
@@ -54,10 +53,12 @@ module Pubid::Iso::Renderer
|
|
54
53
|
|
55
54
|
def render_identifier(params, opts)
|
56
55
|
stage = params.key?(:stage) ? postrender_stage(params[:stage], opts, params) : ""
|
57
|
-
|
56
|
+
type = render_type_prefix(params, opts)
|
57
|
+
"%<publisher>s#{stage}#{type} %<number>s%<part>s%<iteration>s%<year>s%" \
|
58
|
+
"<amendments>s%<corrigendums>s%<addendum>s%<edition>s" % params
|
58
59
|
end
|
59
60
|
|
60
|
-
def render_copublisher_string(publisher, copublishers, opts)
|
61
|
+
def render_copublisher_string(publisher, copublishers, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
61
62
|
case copublishers
|
62
63
|
when String
|
63
64
|
if opts[:language]
|
@@ -83,8 +84,7 @@ module Pubid::Iso::Renderer
|
|
83
84
|
(stage.nil? || stage.empty_abbr?(with_prf: opts[:with_prf])) && typed_stage.nil?
|
84
85
|
end
|
85
86
|
|
86
|
-
def render_publisher(publisher, opts, params)
|
87
|
-
|
87
|
+
def render_publisher(publisher, opts, params) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength
|
88
88
|
if opts[:language]
|
89
89
|
publisher = TRANSLATION[opts[:language]][:publisher][publisher] || publisher
|
90
90
|
end
|
@@ -113,7 +113,7 @@ module Pubid::Iso::Renderer
|
|
113
113
|
|
114
114
|
# With copublisher but not IS
|
115
115
|
# ISO/IEC TR xxx
|
116
|
-
publisher_string
|
116
|
+
"#{publisher_string} "
|
117
117
|
end
|
118
118
|
|
119
119
|
def render_typed_stage(typed_stage, opts, params)
|
@@ -130,12 +130,12 @@ module Pubid::Iso::Renderer
|
|
130
130
|
stage
|
131
131
|
end
|
132
132
|
|
133
|
-
def postrender_stage(stage, opts,
|
133
|
+
def postrender_stage(stage, opts, _params)
|
134
134
|
return if stage.empty_abbr?(with_prf: opts[:with_prf])
|
135
135
|
|
136
136
|
if opts[:language]
|
137
137
|
return TRANSLATION[opts[:language]][:stage][stage.to_s(with_prf: opts[:with_prf])] ||
|
138
|
-
|
138
|
+
stage.to_s(with_prf: opts[:with_prf])
|
139
139
|
end
|
140
140
|
|
141
141
|
stage.to_s(with_prf: opts[:with_prf])
|
@@ -151,15 +151,17 @@ module Pubid::Iso::Renderer
|
|
151
151
|
|
152
152
|
def render_language(language, opts, _params)
|
153
153
|
return if opts[:with_language_code] == :none
|
154
|
+
|
154
155
|
super
|
155
156
|
end
|
156
157
|
|
157
158
|
def render_year(year, opts, params)
|
158
159
|
return ":#{year}" if params[:amendments] || params[:corrigendums]
|
160
|
+
|
159
161
|
opts[:with_date] && ":#{year}" || ""
|
160
162
|
end
|
161
163
|
|
162
|
-
def render_part(part,
|
164
|
+
def render_part(part, _opts, _params)
|
163
165
|
"-#{part}"
|
164
166
|
end
|
165
167
|
|
@@ -7,7 +7,7 @@ module Pubid::Iso::Renderer
|
|
7
7
|
# Render identifier
|
8
8
|
# @param with_edition [Boolean] include edition in output
|
9
9
|
# @see Pubid::Core::Renderer::Base for another options
|
10
|
-
def render(with_edition: true, with_language_code: :iso, with_date: true, **args)
|
10
|
+
def render(with_edition: true, with_language_code: :iso, with_date: true, **args) # rubocop:disable Metrics/MethodLength
|
11
11
|
@params[:base].to_s(lang: args[:language], with_edition: with_edition) +
|
12
12
|
super(
|
13
13
|
with_edition: with_edition, with_language_code: with_language_code, with_date: with_date,
|
@@ -22,7 +22,7 @@ module Pubid::Iso::Renderer
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def render_identifier(params, opts)
|
25
|
+
def render_identifier(params, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
26
26
|
type_prefix = params[:stage].nil? || !params[:stage].is_a?(Pubid::Core::TypedStage) ? self.class::TYPE : ""
|
27
27
|
|
28
28
|
stage = params[:stage]
|
@@ -32,14 +32,14 @@ module Pubid::Iso::Renderer
|
|
32
32
|
stage = params[:stage].to_s(with_prf: opts[:with_prf])
|
33
33
|
end
|
34
34
|
|
35
|
-
if
|
35
|
+
if instance_of?(Supplement)
|
36
36
|
if opts[:base_type] == :dir
|
37
|
-
"
|
37
|
+
"%<stage>s%<publisher>s SUP%<number>s%<part>s%<iteration>s%<year>s%<month>s%<edition>s" % params
|
38
38
|
else
|
39
|
-
"/#{stage}#{type_prefix}
|
39
|
+
"/#{stage}#{type_prefix}%<number>s%<part>s%<iteration>s%<year>s%<edition>s" % params
|
40
40
|
end
|
41
41
|
else
|
42
|
-
"/#{stage}#{type_prefix}
|
42
|
+
"/#{stage}#{type_prefix}%<number>s%<part>s%<iteration>s%<year>s%<edition>s" % params
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -5,8 +5,8 @@ module Pubid::Iso::Renderer
|
|
5
5
|
TYPE = "amd".freeze
|
6
6
|
|
7
7
|
def render_identifier(params)
|
8
|
-
"
|
9
|
-
"#{@params[:base].language ?
|
8
|
+
"%<base>s%<stage>s:amd%<year>s%<number>s%<edition>s" \
|
9
|
+
"#{@params[:base].language ? ":#{@params[:base].language}" : ''}%<all_parts>s" % params
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -5,8 +5,8 @@ module Pubid::Iso::Renderer
|
|
5
5
|
TYPE = "cor".freeze
|
6
6
|
|
7
7
|
def render_identifier(params)
|
8
|
-
"
|
9
|
-
"#{@params[:base].language ?
|
8
|
+
"%<base>s%<stage>s:cor%<year>s%<number>s%<edition>s" \
|
9
|
+
"#{@params[:base].language ? ":#{@params[:base].language}" : ''}%<all_parts>s" % params
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -2,23 +2,22 @@ require_relative "urn"
|
|
2
2
|
|
3
3
|
module Pubid::Iso::Renderer
|
4
4
|
class UrnDir < Urn
|
5
|
-
|
6
|
-
|
7
|
-
res = ("urn:iso:doc:%{publisher}%{copublisher}:dir%{dirtype}%{number}%{year}%{supplement}" % params)
|
5
|
+
def render_identifier(params) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
6
|
+
res = ("urn:iso:doc:%<publisher>s%<copublisher>s:dir%<dirtype>s%<number>s%<year>s%<supplement>s" % params)
|
8
7
|
|
9
8
|
if params.key?(:joint_document)
|
10
9
|
if params[:joint_document].is_a?(Pubid::Iso::Identifier::Supplement)
|
11
10
|
joint_params = params[:joint_document].to_h(deep: false)
|
12
|
-
res += ":#{joint_params[:base].publisher.downcase}:sup
|
11
|
+
res += ":#{joint_params[:base].publisher.downcase}:sup:%<year>s" % joint_params
|
13
12
|
else
|
14
13
|
joint_params = prerender_params(params[:joint_document].to_h(deep: false), {})
|
15
14
|
joint_params.default = ""
|
16
|
-
res += ("
|
15
|
+
res += (":%<publisher>s%<copublisher>s%<dirtype>s%<number>s%<supplement>s" % joint_params)
|
17
16
|
end
|
18
17
|
|
19
18
|
end
|
20
19
|
|
21
|
-
res
|
20
|
+
res + params[:all_parts]
|
22
21
|
end
|
23
22
|
|
24
23
|
def render_number(number, _opts, _params)
|
@@ -29,7 +28,7 @@ module Pubid::Iso::Renderer
|
|
29
28
|
":#{dirtype.downcase}"
|
30
29
|
end
|
31
30
|
|
32
|
-
def render_supplement(supplement, _opts, _params)
|
31
|
+
def render_supplement(supplement, _opts, _params) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
33
32
|
if supplement.publisher && supplement.publisher != ""
|
34
33
|
":sup:#{supplement.publisher.downcase}"
|
35
34
|
else
|
@@ -3,8 +3,8 @@ require_relative "urn"
|
|
3
3
|
module Pubid::Iso::Renderer
|
4
4
|
class UrnExtract < Urn
|
5
5
|
def render_identifier(params)
|
6
|
-
"
|
7
|
-
"#{@params[:base].language ?
|
6
|
+
"%<base>s%<stage>s:ext%<year>s%<number>s%<edition>s" \
|
7
|
+
"#{@params[:base].language ? ":#{@params[:base].language}" : ''}%<all_parts>s" % params
|
8
8
|
end
|
9
9
|
|
10
10
|
def render_base(base, _opts, _params)
|
@@ -5,8 +5,8 @@ module Pubid::Iso::Renderer
|
|
5
5
|
TYPE = "sup".freeze
|
6
6
|
|
7
7
|
def render_identifier(params)
|
8
|
-
"
|
9
|
-
"#{@params[:base].language ?
|
8
|
+
"%<base>s%<stage>s:#{self.class::TYPE}%<publisher>s%<year>s%<number>s%<edition>s" \
|
9
|
+
"#{@params[:base].language ? ":#{@params[:base].language}" : ''}%<all_parts>s" % params
|
10
10
|
end
|
11
11
|
|
12
12
|
def render_base(base, _opts, _params)
|
@@ -2,9 +2,9 @@ require_relative "urn"
|
|
2
2
|
|
3
3
|
module Pubid::Iso::Renderer
|
4
4
|
class UrnTc < Urn
|
5
|
-
|
6
5
|
def render_identifier(params)
|
7
|
-
"urn:iso:doc
|
6
|
+
"urn:iso:doc:%<publisher>s%<copublisher>s:%<tctype>s:%<tcnumber>s" \
|
7
|
+
"%<sctype>s%<wgtype>s:%<number>s%<all_parts>s" % params
|
8
8
|
end
|
9
9
|
|
10
10
|
def render_tctype(tctype, _opts, _params)
|
@@ -26,12 +26,12 @@ module Pubid::Iso::Renderer
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def render_prefix(params)
|
29
|
-
"urn:iso:std
|
29
|
+
"urn:iso:std:%<publisher>s%<copublisher>s%<type>s:%<number>s%<part>s" % params
|
30
30
|
end
|
31
31
|
|
32
32
|
def render_identifier(params)
|
33
|
-
render_prefix(params) + "
|
34
|
-
"
|
33
|
+
render_prefix(params) + "%<stage>s%<corrigendum_stage>s%<iteration>s" \
|
34
|
+
"%<edition>s%<amendments>s%<corrigendums>s%<all_parts>s" % params
|
35
35
|
end
|
36
36
|
|
37
37
|
# def render_typed_stage(typed_stage, _opts, _params)
|
@@ -59,5 +59,9 @@ module Pubid::Iso::Renderer
|
|
59
59
|
|
60
60
|
":-#{part}"
|
61
61
|
end
|
62
|
+
|
63
|
+
def render_all_parts(value, _opts, _params)
|
64
|
+
":ser" if value == true
|
65
|
+
end
|
62
66
|
end
|
63
67
|
end
|
@@ -3,6 +3,13 @@ require_relative "renderer/base"
|
|
3
3
|
|
4
4
|
module Pubid::Iso
|
5
5
|
class Transformer < Pubid::Core::Transformer
|
6
|
+
rule(root: subtree(:root)) do |context|
|
7
|
+
if context[:root][:stage] == "draft"
|
8
|
+
context[:root][:stage] = convert_urn_stage context[:root][:type]
|
9
|
+
end
|
10
|
+
context[:root]
|
11
|
+
end
|
12
|
+
|
6
13
|
rule(edition: "Ed") do
|
7
14
|
{ edition: "1" }
|
8
15
|
end
|
@@ -14,27 +21,25 @@ module Pubid::Iso
|
|
14
21
|
context
|
15
22
|
end
|
16
23
|
|
17
|
-
rule(supplements: subtree(:supplements)) do |context|
|
24
|
+
rule(supplements: subtree(:supplements)) do |context| # rubocop:disable Metrics/BlockLength
|
18
25
|
if context[:supplements].is_a?(Array)
|
19
26
|
context[:supplements] =
|
20
27
|
context[:supplements].map do |supplement|
|
21
28
|
if supplement[:typed_stage]
|
22
29
|
supplement.merge(
|
23
30
|
case supplement[:typed_stage]
|
24
|
-
when "PDAM"
|
25
|
-
|
26
|
-
when "
|
27
|
-
|
28
|
-
else
|
29
|
-
|
30
|
-
end
|
31
|
+
when "PDAM" then { typed_stage: "CD", type: "Amd" }
|
32
|
+
when "pDCOR" then { typed_stage: "CD", type: "Cor" }
|
33
|
+
# when "DAD" then { typed_stage: "WD", type: "Amd" }
|
34
|
+
when "draft" then convert_urn_sup_draft_type supplement[:type]
|
35
|
+
else convert_urn_sup_stage_code(supplement)
|
36
|
+
end,
|
31
37
|
)
|
32
38
|
else
|
33
39
|
case supplement[:type]
|
34
|
-
when "Addendum"
|
35
|
-
|
36
|
-
else
|
37
|
-
supplement
|
40
|
+
when "Addendum" then supplement.merge({ type: "Add" })
|
41
|
+
when "sup" then supplement.merge({ type: "Suppl" })
|
42
|
+
else supplement
|
38
43
|
end
|
39
44
|
end
|
40
45
|
end
|
@@ -52,28 +57,9 @@ module Pubid::Iso
|
|
52
57
|
end
|
53
58
|
end
|
54
59
|
|
55
|
-
rule(type: simple(:type)) do
|
56
|
-
russian_type = Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:type].key(type.to_s)
|
57
|
-
{ type: russian_type&.downcase&.to_sym ||
|
58
|
-
case type
|
59
|
-
# XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
|
60
|
-
when "GUIDE", "Guide", "Руководство"
|
61
|
-
:guide
|
62
|
-
when "ТС", "TS"
|
63
|
-
:ts
|
64
|
-
when "ТО", "TR"
|
65
|
-
:tr
|
66
|
-
when "Directives Part", "Directives, Part", "Directives,", "DIR"
|
67
|
-
:dir
|
68
|
-
when "PAS"
|
69
|
-
:pas
|
70
|
-
when "DPAS"
|
71
|
-
:dpas
|
72
|
-
when "R"
|
73
|
-
:r
|
74
|
-
else
|
75
|
-
type
|
76
|
-
end }
|
60
|
+
rule(type: simple(:type)) do |context|
|
61
|
+
russian_type = Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:type].key(context[:type].to_s)
|
62
|
+
{ type: russian_type&.downcase&.to_sym || convert_type(context[:type]) }
|
77
63
|
end
|
78
64
|
|
79
65
|
rule(tctype: subtree(:tctype)) do |context|
|
@@ -81,21 +67,20 @@ module Pubid::Iso
|
|
81
67
|
context
|
82
68
|
end
|
83
69
|
|
84
|
-
rule(copublisher:
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
}
|
70
|
+
rule(copublisher: sequence(:copublisher)) do |context|
|
71
|
+
copublishers = context[:copublisher].map! do |publisher|
|
72
|
+
convert_copublisher(publisher)
|
73
|
+
end
|
74
|
+
|
75
|
+
{ copublisher: copublishers }
|
76
|
+
end
|
77
|
+
|
78
|
+
rule(copublisher: simple(:copublisher)) do |context|
|
79
|
+
{ copublisher: convert_copublisher(context[:copublisher]) }
|
94
80
|
end
|
95
81
|
|
96
|
-
rule(publisher: simple(:publisher)) do
|
97
|
-
|
98
|
-
{ publisher: russian_publisher&.to_s || publisher }
|
82
|
+
rule(publisher: simple(:publisher)) do |context|
|
83
|
+
{ publisher: convert_publisher(context[:publisher]) }
|
99
84
|
end
|
100
85
|
|
101
86
|
rule(part: sequence(:part)) do
|
@@ -110,8 +95,8 @@ module Pubid::Iso
|
|
110
95
|
|
111
96
|
rule(dir_joint_document: subtree(:dir_joint_document)) do |context|
|
112
97
|
context[:joint_document] =
|
113
|
-
Identifier::Base.transform(**
|
114
|
-
context.
|
98
|
+
Identifier::Base.transform(**context[:dir_joint_document].merge(type: :dir))
|
99
|
+
context.reject { |k, _| k == :dir_joint_document }
|
115
100
|
end
|
116
101
|
|
117
102
|
rule(jtc_dir: simple(:jtc_dir)) do |context|
|
@@ -119,42 +104,104 @@ module Pubid::Iso
|
|
119
104
|
context
|
120
105
|
end
|
121
106
|
|
122
|
-
def self.
|
107
|
+
def self.convert_publisher(publisher)
|
108
|
+
pblsh = publisher.to_s.upcase
|
109
|
+
Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:publisher].key(pblsh) || pblsh
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.convert_copublisher(copublisher)
|
113
|
+
copblsh = convert_publisher copublisher
|
114
|
+
Pubid::Iso::Renderer::Base::TRANSLATION[:french][:publisher].key(copblsh) || copblsh
|
115
|
+
end
|
116
|
+
|
117
|
+
rule(all_parts: simple(:all_parts)) do
|
118
|
+
["(all parts)", "ser"].include?(all_parts) ? { all_parts: true } : {}
|
119
|
+
end
|
120
|
+
|
121
|
+
# Convert ISO stage to Russian and other formats if needed
|
122
|
+
# @param code [String] ISO stage code
|
123
|
+
# @return [Hash] a hash with keys :stage and optionally :type
|
124
|
+
def self.convert_stage(code) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
123
125
|
russian_code = Pubid::Iso::Renderer::Base::TRANSLATION[:russian][:stage].key(code.to_s)
|
124
126
|
return { stage: russian_code } if russian_code
|
125
127
|
|
126
128
|
case code
|
127
|
-
when "NWIP"
|
128
|
-
|
129
|
-
when "
|
130
|
-
|
131
|
-
when "
|
132
|
-
|
133
|
-
when "
|
134
|
-
|
135
|
-
when "
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
129
|
+
when "NWIP" then { stage: "NP" }
|
130
|
+
when "D", "FPD" then { stage: "DIS" }
|
131
|
+
when "FD", "F" then { stage: "FDIS" }
|
132
|
+
when "Fpr" then { stage: "PRF" }
|
133
|
+
when "PDTR" then { stage: "CD", type: "TR" }
|
134
|
+
when "PDTS" then { stage: "CD", type: "TS" }
|
135
|
+
when "preCD" then { stage: "PreCD" }
|
136
|
+
when "published" then { stage: "IS" }
|
137
|
+
# when "draft" then { stage: "WD" }
|
138
|
+
else { stage: convert_stage_code(code.to_s) }
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.convert_urn_sup_stage_code(sup)
|
143
|
+
stage_type = convert_urn_sup_type(sup[:type])
|
144
|
+
abbr = convert_stage_code(sup[:typed_stage])
|
145
|
+
stage_type[:typed_stage] = abbr if abbr
|
146
|
+
stage_type
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.convert_urn_sup_type(type)
|
150
|
+
case type
|
151
|
+
when "sup" then { type: "Suppl" }
|
152
|
+
when String, Parslet::Slice then { type: type.to_s }
|
153
|
+
else {}
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def self.convert_stage_code(code)
|
158
|
+
Identifier::InternationalStandard::TYPED_STAGES.each_value do |v|
|
159
|
+
return v[:abbr] if v[:harmonized_stages].include?(code)
|
143
160
|
end
|
161
|
+
|
162
|
+
code
|
144
163
|
end
|
145
164
|
|
146
165
|
def self.convert_language(code)
|
147
166
|
case code
|
148
|
-
when "R"
|
149
|
-
|
150
|
-
when "
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
167
|
+
when "R" then "ru"
|
168
|
+
when "F" then "fr"
|
169
|
+
when "E" then "en"
|
170
|
+
when "A" then "ar"
|
171
|
+
else code
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def self.convert_urn_sup_draft_type(type)
|
176
|
+
if type == "sup"
|
177
|
+
{ typed_stage: "DSuppl", type: "Suppl" }
|
156
178
|
else
|
157
|
-
|
179
|
+
{ typed_stage: "WD" }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def self.convert_urn_stage(type)
|
184
|
+
case type
|
185
|
+
when "tr" then "DTR"
|
186
|
+
when "ts" then "DTS"
|
187
|
+
when "iwa" then "DIWA"
|
188
|
+
when "pas" then "DPAS"
|
189
|
+
when "guide" then "DGuide"
|
190
|
+
else "D"
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def self.convert_type(type) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength
|
195
|
+
case type
|
196
|
+
# XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
|
197
|
+
when "GUIDE", "Guide", "Руководство" then :guide
|
198
|
+
when "ТС", "TS" then :ts
|
199
|
+
when "ТО", "TR" then :tr
|
200
|
+
when "Directives Part", "Directives, Part", "Directives,", "DIR" then :dir
|
201
|
+
when "PAS" then :pas
|
202
|
+
when "DPAS" then :dpas
|
203
|
+
when "R" then :r
|
204
|
+
else type
|
158
205
|
end
|
159
206
|
end
|
160
207
|
end
|
data/lib/pubid/iso/version.rb
CHANGED
data/stages.yaml
CHANGED
@@ -7,6 +7,10 @@ abbreviations:
|
|
7
7
|
CD: ["30.00", "30.20", "30.60", "30.92", "30.98", "30.99"]
|
8
8
|
FCD: ["40.00", "40.20", "40.60", "40.92", "40.98", "40.99"]
|
9
9
|
PRF: ["50.00", "50.20", "50.60", "50.92", "50.98", "50.99"]
|
10
|
+
WDR: ["90.92"]
|
11
|
+
WDA: ["90.93"]
|
12
|
+
WDAR: ["95.99"]
|
13
|
+
IS: ["60.00", "60.60"]
|
10
14
|
|
11
15
|
names:
|
12
16
|
WD: Working Draft
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubid-iso
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.
|
61
|
+
version: 1.13.0
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.
|
68
|
+
version: 1.13.0
|
69
69
|
description: Library to generate, parse and manipulate ISO PubID.
|
70
70
|
email:
|
71
71
|
- open.source@ribose.com
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- lib/pubid/iso/identifier/technical_specification.rb
|
101
101
|
- lib/pubid/iso/identifier/technology_trends_assessments.rb
|
102
102
|
- lib/pubid/iso/parser.rb
|
103
|
+
- lib/pubid/iso/parser_urn.rb
|
103
104
|
- lib/pubid/iso/renderer/addendum.rb
|
104
105
|
- lib/pubid/iso/renderer/amendment.rb
|
105
106
|
- lib/pubid/iso/renderer/base.rb
|
@@ -133,7 +134,7 @@ homepage: https://github.com/metanorma/pubid-iso
|
|
133
134
|
licenses:
|
134
135
|
- BSD-2-Clause
|
135
136
|
metadata: {}
|
136
|
-
post_install_message:
|
137
|
+
post_install_message:
|
137
138
|
rdoc_options: []
|
138
139
|
require_paths:
|
139
140
|
- lib
|
@@ -141,15 +142,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
142
|
requirements:
|
142
143
|
- - ">="
|
143
144
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
145
|
+
version: 3.1.0
|
145
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
147
|
requirements:
|
147
148
|
- - ">="
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
152
|
-
signing_key:
|
152
|
+
rubygems_version: 3.5.22
|
153
|
+
signing_key:
|
153
154
|
specification_version: 4
|
154
155
|
summary: Library to generate, parse and manipulate ISO PubID.
|
155
156
|
test_files: []
|