pubid-iso 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pubid/iso/amendment.rb +2 -25
- data/lib/pubid/iso/corrigendum.rb +20 -19
- data/lib/pubid/iso/errors.rb +5 -0
- data/lib/pubid/iso/harmonized_stage_code.rb +59 -19
- data/lib/pubid/iso/identifier.rb +88 -36
- data/lib/pubid/iso/parser.rb +24 -19
- data/lib/pubid/iso/renderer/base.rb +69 -25
- data/lib/pubid/iso/renderer/french.rb +5 -8
- data/lib/pubid/iso/renderer/russian.rb +7 -8
- data/lib/pubid/iso/renderer/urn.rb +13 -4
- data/lib/pubid/iso/stage.rb +31 -34
- data/lib/pubid/iso/supplement.rb +8 -7
- data/lib/pubid/iso/transformer.rb +44 -5
- data/lib/pubid/iso/type.rb +6 -0
- data/lib/pubid/iso/typed_stage.rb +204 -0
- data/lib/pubid/iso/version.rb +1 -1
- data/lib/pubid/iso.rb +1 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 418f8b225027cf9b50cb2ec43aad7d043b3bfd0db87733366c6021df8f92f940
|
4
|
+
data.tar.gz: fd9a028a0cb2721b4422b2f515aa46263c7d713da57e02c8fc1ed4c54c22f737
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf1f97bde499237e29b24b793d7e9fe115e03e42a92471a549f90aea9c416ddc357fcfd95079a97bff4b200b4fe8c93f786fc8e3c8256ad3275f2365f9c946e8
|
7
|
+
data.tar.gz: d4b53365fc22d587b204a7c38fcaf362e7f85b5cc5a07767ecb4f97fe5c7a3b8c70c3e24c8c30b63166321bd4f757f7d6658df154a4ccab4715ae94c62e8f17e
|
data/lib/pubid/iso/amendment.rb
CHANGED
@@ -3,32 +3,9 @@ module Pubid::Iso
|
|
3
3
|
# @param stage_format_long [Boolean] long or short format for stage rendering
|
4
4
|
# @param with_date [Boolean] include date
|
5
5
|
def render_pubid(stage_format_long = true, with_date = true)
|
6
|
-
stage = render_pubid_stage
|
7
6
|
pubid_number = render_pubid_number(with_date: with_date)
|
8
|
-
|
9
|
-
|
10
|
-
if stage_format_long
|
11
|
-
"/DAmd #{pubid_number}"
|
12
|
-
else
|
13
|
-
"/DAM #{pubid_number}"
|
14
|
-
end
|
15
|
-
when "FDIS"
|
16
|
-
if stage_format_long
|
17
|
-
"/FDAmd #{pubid_number}"
|
18
|
-
else
|
19
|
-
"/FDAM #{pubid_number}"
|
20
|
-
end
|
21
|
-
when "CD"
|
22
|
-
if stage_format_long
|
23
|
-
"/CD Amd #{pubid_number}"
|
24
|
-
else
|
25
|
-
"/CDAM #{pubid_number}"
|
26
|
-
end
|
27
|
-
when ""
|
28
|
-
"/Amd #{pubid_number}"
|
29
|
-
else
|
30
|
-
"/#{stage} Amd #{pubid_number}"
|
31
|
-
end
|
7
|
+
|
8
|
+
"/#{@typed_stage.to_s(stage_format_long)} #{pubid_number}"
|
32
9
|
end
|
33
10
|
|
34
11
|
def render_urn
|
@@ -1,26 +1,27 @@
|
|
1
1
|
module Pubid::Iso
|
2
2
|
class Corrigendum < Supplement
|
3
3
|
def render_pubid(stage_format_long = true, with_date = true)
|
4
|
-
stage = render_pubid_stage
|
4
|
+
# stage = render_pubid_stage
|
5
5
|
pubid_number = render_pubid_number(with_date: with_date)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
6
|
+
"/#{@typed_stage.to_s(stage_format_long)} #{pubid_number}"
|
7
|
+
# case stage.to_s
|
8
|
+
# when "DIS"
|
9
|
+
# if stage_format_long
|
10
|
+
# "/DCor #{pubid_number}"
|
11
|
+
# else
|
12
|
+
# "/DCOR #{pubid_number}"
|
13
|
+
# end
|
14
|
+
# when "FDIS"
|
15
|
+
# if stage_format_long
|
16
|
+
# "/FDCor #{pubid_number}"
|
17
|
+
# else
|
18
|
+
# "/FDCOR #{pubid_number}"
|
19
|
+
# end
|
20
|
+
# when ""
|
21
|
+
# "/Cor #{pubid_number}"
|
22
|
+
# else
|
23
|
+
# "/#{stage} Cor #{pubid_number}"
|
24
|
+
# end
|
24
25
|
end
|
25
26
|
|
26
27
|
def render_urn
|
data/lib/pubid/iso/errors.rb
CHANGED
@@ -3,6 +3,7 @@ module Pubid::Iso
|
|
3
3
|
class ParseError < StandardError; end
|
4
4
|
class PublishedIterationError < StandardError; end
|
5
5
|
class HarmonizedStageCodeInvalidError < StandardError; end
|
6
|
+
class HarmonizedStageRenderingError < StandardError; end
|
6
7
|
class StageInvalidError < StandardError; end
|
7
8
|
class IsStageIterationError < StandardError; end
|
8
9
|
class IterationWithoutStageError < StandardError; end
|
@@ -12,5 +13,9 @@ module Pubid::Iso
|
|
12
13
|
class NoEditionError < StandardError; end
|
13
14
|
class WrongTypeError < StandardError; end
|
14
15
|
class ParseTypeError < StandardError; end
|
16
|
+
class TypeStageInvalidError < StandardError; end
|
17
|
+
class TypeStageParseError < StandardError; end
|
18
|
+
|
19
|
+
class SupplementRenderingError < StandardError; end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,7 +1,8 @@
|
|
1
1
|
module Pubid::Iso
|
2
2
|
class HarmonizedStageCode
|
3
3
|
include Comparable
|
4
|
-
attr_accessor :stage, :substage
|
4
|
+
# attr_accessor :stage, :substage
|
5
|
+
attr_accessor :stages
|
5
6
|
|
6
7
|
DESCRIPTIONS = {
|
7
8
|
"00.00" => "Proposal for new project received",
|
@@ -50,7 +51,15 @@ module Pubid::Iso
|
|
50
51
|
"95.60" => "Close of voting",
|
51
52
|
"95.92" => "Decision not to withdraw International Standard",
|
52
53
|
"95.99" => "Withdrawal of International Standard"
|
53
|
-
}
|
54
|
+
}.freeze
|
55
|
+
|
56
|
+
DRAFT_STAGES = %w[00.00 00.20 00.60 00.99 10.00 10.20 10.60 10.92 10.99 20.00 20.20 20.60 20.99 30.00
|
57
|
+
30.20 30.60 30.92 30.99 40.00 40.20 40.60 40.92 40.93 40.99 50.00 50.20 50.60
|
58
|
+
50.92 50.99].freeze
|
59
|
+
|
60
|
+
CANCELED_STAGES = %w[00.98 10.98 20.98 30.98 40.98 50.98 95.99].freeze
|
61
|
+
|
62
|
+
PUBLISHED_STAGES = %w[60.00 60.60 90.20 90.60 90.92 90.93 90.99 95.20 95.60 95.92].freeze
|
54
63
|
|
55
64
|
STAGES_NAMES = {
|
56
65
|
preliminary: "00",
|
@@ -74,32 +83,63 @@ module Pubid::Iso
|
|
74
83
|
proceed: "99",
|
75
84
|
}.freeze
|
76
85
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
# @param stage_or_code [String,Array<String>] stage number or whole harmonized code with substage
|
87
|
+
# or list or stages for fuzzy stages eg. "10", 10, "20.20", ["10.20", "20.20"]
|
88
|
+
# @param substage [Integer, String] eg. "00", 0
|
89
|
+
def initialize(stage_or_code, substage = "00")
|
90
|
+
@stages = if stage_or_code.is_a?(Array)
|
91
|
+
stage_or_code
|
92
|
+
elsif stage_or_code.is_a?(String) && DESCRIPTIONS.key?(stage_or_code)
|
93
|
+
[stage_or_code]
|
94
|
+
# when stage is stage name
|
95
|
+
elsif STAGES_NAMES.key?(stage_or_code)
|
96
|
+
["#{STAGES_NAMES[stage_or_code]}.#{SUBSTAGES_NAMES[substage]}"]
|
97
|
+
else
|
98
|
+
# stage is number
|
99
|
+
["#{stage_or_code}.#{substage}"]
|
100
|
+
end
|
101
|
+
validate_stages
|
102
|
+
end
|
103
|
+
|
104
|
+
def validate_stages
|
105
|
+
@stages.each do |stage|
|
106
|
+
# raise an error when stage is wrong
|
107
|
+
raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(stage)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def to_s
|
112
|
+
if fuzzy?
|
113
|
+
return "draft" if @stages.all? { |s| DRAFT_STAGES.include?(s) || CANCELED_STAGES.include?(s) }
|
114
|
+
|
115
|
+
return "published" if @stages.all? { |s| PUBLISHED_STAGES.include?(s) }
|
116
|
+
|
117
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render fuzzy stages"
|
82
118
|
else
|
83
|
-
|
84
|
-
@stage, @substage = stage, substage
|
85
|
-
validate_stage(stage, substage)
|
119
|
+
@stages.first
|
86
120
|
end
|
87
121
|
end
|
88
122
|
|
89
|
-
def
|
90
|
-
|
91
|
-
|
123
|
+
def ==(other)
|
124
|
+
(stages & other.stages) == other.stages
|
125
|
+
end
|
92
126
|
|
93
|
-
|
94
|
-
|
127
|
+
def fuzzy?
|
128
|
+
@stages.length > 1
|
95
129
|
end
|
96
130
|
|
97
|
-
def
|
98
|
-
"
|
131
|
+
def stage
|
132
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render stage for fuzzy stages" if fuzzy?
|
133
|
+
|
134
|
+
return nil if @stages.empty?
|
135
|
+
|
136
|
+
@stages.first.split(".").first
|
99
137
|
end
|
100
138
|
|
101
|
-
def
|
102
|
-
|
139
|
+
def substage
|
140
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render substage for fuzzy stages" if fuzzy?
|
141
|
+
|
142
|
+
@stages.first.split(".").last
|
103
143
|
end
|
104
144
|
|
105
145
|
def description
|
data/lib/pubid/iso/identifier.rb
CHANGED
@@ -6,12 +6,14 @@ module Pubid::Iso
|
|
6
6
|
:dirtype,
|
7
7
|
# supplement for DIR type identifiers
|
8
8
|
:supplement,
|
9
|
-
:base
|
9
|
+
:base,
|
10
|
+
:typed_stage,
|
11
|
+
:supplements
|
10
12
|
|
11
13
|
# Creates new identifier from options provided, includes options from
|
12
14
|
# Pubid::Core::Identifier#initialize
|
13
15
|
#
|
14
|
-
# @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
|
16
|
+
# @param stage [Stage, TypedStage, Symbol, String] stage or typed stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD), "DTR"
|
15
17
|
# @param iteration [Integer] document iteration, eg. "1", "2", "3"
|
16
18
|
# @param joint_document [Identifier] joint document
|
17
19
|
# @param supplement [Supplement] supplement
|
@@ -39,23 +41,48 @@ module Pubid::Iso
|
|
39
41
|
joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
|
40
42
|
scnumber: nil, wgnumber:nil,
|
41
43
|
dir: nil, dirtype: nil, year: nil, amendments: nil,
|
42
|
-
corrigendums: nil, type: nil, base: nil, **opts)
|
44
|
+
corrigendums: nil, type: nil, base: nil, supplements: nil, **opts)
|
43
45
|
super(**opts.merge(number: number, publisher: publisher, year: year,
|
44
46
|
amendments: amendments, corrigendums: corrigendums))
|
45
47
|
|
48
|
+
if supplements
|
49
|
+
@supplements = supplements.map do |supplement|
|
50
|
+
if supplement.is_a?(Hash)
|
51
|
+
self.class.get_transformer_class.new.apply(:supplements => [supplement])[:supplements].first
|
52
|
+
else
|
53
|
+
supplement
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
46
58
|
if %i(amd cor).include?(type) && (base.year.nil? && base.stage.nil?)
|
47
59
|
raise Errors::SupplementWithoutYearOrStageError,
|
48
60
|
"Cannot apply supplement to document without base identifieredition year or stage"
|
49
61
|
end
|
50
|
-
if stage
|
51
|
-
@stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)
|
52
62
|
|
53
|
-
|
63
|
+
if stage.is_a?(TypedStage)
|
64
|
+
@typed_stage = stage
|
65
|
+
# add type to typed stage when missing (case for amendment with stage, eg. "CD Amd")
|
66
|
+
@typed_stage.type = Type.new(type) if @typed_stage.type.nil? && type
|
67
|
+
elsif stage || type
|
68
|
+
@typed_stage = if type
|
69
|
+
TypedStage.new(type: type.is_a?(Type) ? type : Type.new(type))
|
70
|
+
else
|
71
|
+
TypedStage.new
|
72
|
+
end
|
73
|
+
|
74
|
+
if @typed_stage.type == :is && iteration
|
54
75
|
raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
|
55
76
|
end
|
56
77
|
|
57
|
-
if
|
58
|
-
|
78
|
+
if stage
|
79
|
+
provided_type = @typed_stage.type
|
80
|
+
|
81
|
+
@typed_stage.parse_stage(stage.is_a?(Parslet::Slice) ? stage.to_s : stage)
|
82
|
+
if !provided_type.nil? && @typed_stage.type != provided_type
|
83
|
+
raise Errors::StageInvalidError,
|
84
|
+
"cannot assign typed stage for document with different type (#{provided_type} vs #{@typed_stage.type})"
|
85
|
+
end
|
59
86
|
end
|
60
87
|
elsif iteration
|
61
88
|
raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration"
|
@@ -73,7 +100,6 @@ module Pubid::Iso
|
|
73
100
|
@dir = dir.to_s if dir
|
74
101
|
@dirtype = dirtype.to_s if dirtype
|
75
102
|
@base = base if base
|
76
|
-
@type = type.is_a?(Type) ? type : Type.new(type) unless type.nil?
|
77
103
|
end
|
78
104
|
|
79
105
|
def self.parse_from_title(title)
|
@@ -86,34 +112,49 @@ module Pubid::Iso
|
|
86
112
|
end
|
87
113
|
|
88
114
|
class << self
|
89
|
-
def
|
90
|
-
|
91
|
-
|
92
|
-
end
|
115
|
+
def supplements_has_type?(supplements, type)
|
116
|
+
supplements.any? do |supplement|
|
117
|
+
supplement.typed_stage.type == type
|
118
|
+
end
|
119
|
+
end
|
93
120
|
|
94
|
-
|
121
|
+
def supplement_by_type(supplements, type)
|
122
|
+
supplements.select { |supplement| supplement.type == type }.first
|
123
|
+
end
|
95
124
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
125
|
+
def transform_supplements(supplements_params, base_params)
|
126
|
+
supplements = supplements_params.map do |supplement|
|
127
|
+
new(number: supplement[:number], year: supplement[:year],
|
128
|
+
stage: supplement[:typed_stage], edition: supplement[:edition],
|
129
|
+
iteration: supplement[:iteration],
|
130
|
+
base: new(**base_params))
|
103
131
|
end
|
104
132
|
|
133
|
+
return supplements.first if supplements.count == 1
|
105
134
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
135
|
+
# update corrigendum base to amendment
|
136
|
+
if supplements_has_type?(supplements, :cor) &&
|
137
|
+
supplements_has_type?(supplements, :amd) && supplements.count == 2
|
138
|
+
|
139
|
+
supplement = supplement_by_type(supplements, :cor)
|
140
|
+
supplement.base = supplement_by_type(supplements, :amd)
|
141
|
+
supplement
|
142
|
+
else
|
143
|
+
raise Errors::SupplementRenderingError, "don't know how to render provided supplements"
|
113
144
|
end
|
145
|
+
end
|
114
146
|
|
147
|
+
def transform(params)
|
148
|
+
identifier_params = params.map do |k, v|
|
149
|
+
get_transformer_class.new.apply(k => v).to_a.first
|
150
|
+
end.to_h
|
115
151
|
|
116
|
-
return supplement if
|
152
|
+
# return supplement if supplements applied
|
153
|
+
if identifier_params[:supplements]
|
154
|
+
return transform_supplements(
|
155
|
+
identifier_params[:supplements],
|
156
|
+
identifier_params.dup.tap { |h| h.delete(:supplements) })
|
157
|
+
end
|
117
158
|
|
118
159
|
new(**identifier_params)
|
119
160
|
end
|
@@ -142,10 +183,10 @@ module Pubid::Iso
|
|
142
183
|
# Render URN identifier
|
143
184
|
# @return [String] URN identifier
|
144
185
|
def urn
|
145
|
-
if %i(amd cor).include?(
|
186
|
+
if %i(amd cor).include?(type&.type) && (@base.base.nil? && !@base.edition || (!@base.base.nil? && !@base.base.edition))
|
146
187
|
raise Errors::NoEditionError, "Base document must have edition"
|
147
188
|
end
|
148
|
-
(@tctype && Renderer::UrnTc ||
|
189
|
+
(@tctype && Renderer::UrnTc || type == :dir && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
|
149
190
|
end
|
150
191
|
|
151
192
|
# Renders pubid identifier
|
@@ -203,27 +244,38 @@ module Pubid::Iso
|
|
203
244
|
else
|
204
245
|
if @tctype
|
205
246
|
Renderer::Tc.new(get_params)
|
206
|
-
elsif @type == :dir
|
247
|
+
elsif @typed_stage&.type == :dir
|
207
248
|
Renderer::Dir.new(get_params)
|
208
249
|
else
|
209
250
|
self.class.get_renderer_class.new(get_params)
|
210
251
|
end
|
211
252
|
end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
|
212
253
|
stage_format_long: stage_format_long, with_prf: with_prf) +
|
213
|
-
if @joint_document && @type != :dir
|
254
|
+
if @joint_document && @typed_stage&.type != :dir
|
214
255
|
"|#{@joint_document}"
|
215
256
|
end.to_s
|
216
257
|
end
|
217
258
|
|
259
|
+
def stage
|
260
|
+
typed_stage&.stage
|
261
|
+
end
|
262
|
+
|
263
|
+
def type
|
264
|
+
typed_stage&.type
|
265
|
+
end
|
266
|
+
|
218
267
|
# Return typed stage abbreviation, eg. "FDTR", "DIS", "TR"
|
219
268
|
def typed_stage_abbrev
|
220
|
-
|
221
|
-
renderer.prerendered_params[:type_stage]
|
269
|
+
typed_stage.to_s
|
222
270
|
end
|
223
271
|
|
224
272
|
# Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
|
225
273
|
def typed_stage_name
|
226
|
-
|
274
|
+
typed_stage.name
|
275
|
+
end
|
276
|
+
|
277
|
+
def ==(other)
|
278
|
+
get_params == other.get_params
|
227
279
|
end
|
228
280
|
end
|
229
281
|
end
|
data/lib/pubid/iso/parser.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
module Pubid::Iso
|
2
2
|
class Parser < Pubid::Core::Parser
|
3
|
-
STAGES = %w[NP NWIP WD CD
|
4
|
-
TYPES = %w[DATA ISP IWA R TTA TS TR PAS Guide GUIDE DIR].freeze
|
3
|
+
STAGES = %w[NP NWIP WD CD PRF AWI PWI FPD].freeze
|
4
|
+
TYPES = %w[DATA ISP IWA R TTA TS TR IS PAS Guide GUIDE DIR].freeze
|
5
|
+
TYPED_STAGES = %w[DIS FDIS DPAS FDTR FDTS DTS DTR PDTR PDTS].freeze
|
6
|
+
SUPPLEMENTS = %w[Amd Cor AMD COR]
|
7
|
+
STAGED_SUPPLEMENTS = %w[DAmd DAM DCor FDAmd FDCor DCOR FCOR FDCOR FDAM PDAM pDCOR FPDAM]
|
5
8
|
|
6
9
|
TCTYPES = ["TC", "JTC", "PC", "IT", "CAB", "CASCO", "COPOLCO",
|
7
10
|
"COUNCIL", "CPSG", "CS", "DEVCO", "GA", "GAAB", "INFCO",
|
@@ -21,6 +24,18 @@ module Pubid::Iso
|
|
21
24
|
array_to_str(Renderer::Russian::STAGE.values) | array_to_str(STAGES)
|
22
25
|
end
|
23
26
|
|
27
|
+
rule(:typed_stage) do
|
28
|
+
array_to_str(TYPED_STAGES)
|
29
|
+
end
|
30
|
+
|
31
|
+
rule(:staged_supplement) do
|
32
|
+
array_to_str(STAGED_SUPPLEMENTS)
|
33
|
+
end
|
34
|
+
|
35
|
+
rule(:supplements) do
|
36
|
+
array_to_str(SUPPLEMENTS)
|
37
|
+
end
|
38
|
+
|
24
39
|
rule(:type) do
|
25
40
|
(array_to_str(Renderer::Russian::TYPE.values) | array_to_str(TYPES)).as(:type)
|
26
41
|
end
|
@@ -56,24 +71,13 @@ module Pubid::Iso
|
|
56
71
|
str(".") >> digits.as(:iteration)
|
57
72
|
end
|
58
73
|
|
59
|
-
rule(:
|
60
|
-
((str("/")
|
61
|
-
|
62
|
-
(str("Amd") | str("AMD") | str("AM")) >>
|
63
|
-
(space | str(".")).repeat(1).maybe >>
|
64
|
-
digits.as(:number) >>
|
65
|
-
(str(".") >> digits.as(:iteration)).maybe >>
|
66
|
-
((str(":") | str("-")) >> digits.as(:year)).maybe).repeat(1).as(:amendments)
|
67
|
-
end
|
68
|
-
|
69
|
-
rule(:corrigendum) do
|
70
|
-
((str("/") >> stage.as(:stage)).maybe >>
|
71
|
-
(str("/") | space).maybe >>
|
72
|
-
(str("Cor") | str("COR")) >>
|
74
|
+
rule(:supplement) do
|
75
|
+
((str("/") | space).maybe >>
|
76
|
+
(staged_supplement | (stage >> space).maybe >> supplements).as(:typed_stage) >>
|
73
77
|
(space | str(".")).repeat(1).maybe >>
|
74
78
|
digits.as(:number) >>
|
75
79
|
(str(".") >> digits.as(:iteration)).maybe >>
|
76
|
-
((str(":") | str("-")) >> digits.as(:year)).maybe).repeat(1).as(:
|
80
|
+
((str(":") | str("-")) >> digits.as(:year)).maybe).repeat(1).as(:supplements)
|
77
81
|
end
|
78
82
|
|
79
83
|
rule(:language) do
|
@@ -117,7 +121,7 @@ module Pubid::Iso
|
|
117
121
|
rule(:std_document_body) do
|
118
122
|
(type | stage.as(:stage)).maybe >>
|
119
123
|
# for ISO/IEC WD TS 25025
|
120
|
-
space? >> ((stage.as(:stage) | type) >> space).maybe >>
|
124
|
+
space? >> ((stage.as(:stage) | typed_stage.as(:stage) | type) >> space).maybe >>
|
121
125
|
digits.as(:number) >>
|
122
126
|
# for identifiers like ISO 5537/IDF 26
|
123
127
|
(str("|") >> (str("IDF").as(:publisher) >> space >> digits.as(:number)).as(:joint_document)).maybe >>
|
@@ -126,7 +130,7 @@ module Pubid::Iso
|
|
126
130
|
# stage before amendment
|
127
131
|
(
|
128
132
|
# stage before corrigendum
|
129
|
-
(
|
133
|
+
(supplement).maybe) >>
|
130
134
|
edition.maybe >>
|
131
135
|
language.maybe
|
132
136
|
end
|
@@ -138,6 +142,7 @@ module Pubid::Iso
|
|
138
142
|
# for French and Russian PubIDs starting with Guide type
|
139
143
|
(guide_prefix.as(:type) >> space).maybe >>
|
140
144
|
(stage.as(:stage) >> space).maybe >>
|
145
|
+
(typed_stage.as(:stage) >> space).maybe >>
|
141
146
|
originator >> (space | str("/")) >>
|
142
147
|
(tc_document_body | std_document_body | (dir_document_body >>
|
143
148
|
(str(" + ") >> (originator >> space >> dir_document_body).as(:joint_document)).maybe))
|
@@ -17,42 +17,86 @@ module Pubid::Iso::Renderer
|
|
17
17
|
super
|
18
18
|
end
|
19
19
|
|
20
|
+
def render_supplement(supplement_params, **args)
|
21
|
+
if supplement_params[:base].type == :amd
|
22
|
+
# render inner amendment (cor -> amd -> base)
|
23
|
+
render_supplement(supplement_params[:base].get_params, **args)
|
24
|
+
else
|
25
|
+
self.class.new(supplement_params[:base].get_params).render_base_identifier(
|
26
|
+
# always render year for identifiers with supplement
|
27
|
+
**args.merge({ with_date: true }),
|
28
|
+
)
|
29
|
+
end +
|
30
|
+
case supplement_params[:typed_stage].type.type
|
31
|
+
when :amd
|
32
|
+
render_amendments(
|
33
|
+
[Pubid::Iso::Amendment.new(**supplement_params.slice(:number, :year, :typed_stage, :edition, :iteration))],
|
34
|
+
args,
|
35
|
+
nil,
|
36
|
+
)
|
37
|
+
when :cor
|
38
|
+
render_corrigendums(
|
39
|
+
[Pubid::Iso::Corrigendum.new(**supplement_params.slice(:number, :year, :typed_stage, :edition, :iteration))],
|
40
|
+
args,
|
41
|
+
nil,
|
42
|
+
)
|
43
|
+
# copy parameters from Identifier only supported by Corrigendum
|
44
|
+
end +
|
45
|
+
(supplement_params[:base].language ? render_language(supplement_params[:base].language, args, nil) : "")
|
46
|
+
end
|
47
|
+
|
20
48
|
# Render identifier
|
21
49
|
# @param with_edition [Boolean] include edition in output
|
22
50
|
# @see Pubid::Core::Renderer::Base for another options
|
23
|
-
def render(with_edition: true, **args)
|
24
|
-
super(**args.merge({ with_edition: with_edition }))
|
51
|
+
def render(with_edition: true, with_language_code: :iso, with_date: true, **args)
|
52
|
+
# super(**args.merge({ with_edition: with_edition }))
|
53
|
+
if %i(amd cor).include? @params[:typed_stage]&.type&.type
|
54
|
+
render_supplement(@params, **args.merge({ with_date: with_date,
|
55
|
+
with_language_code: with_language_code,
|
56
|
+
with_edition: with_edition }))
|
57
|
+
else
|
58
|
+
render_base_identifier(**args.merge({ with_date: with_date,
|
59
|
+
with_language_code: with_language_code,
|
60
|
+
with_edition: with_edition })) +
|
61
|
+
@prerendered_params[:language].to_s
|
62
|
+
end
|
63
|
+
|
25
64
|
end
|
26
65
|
|
27
66
|
def render_identifier(params)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
render_base(params,
|
67
|
+
# typed_stage = if params[:typed_stage] && params[:typed_stage] != ""
|
68
|
+
# ((params[:copublisher] && !params[:copublisher].empty?) ? " " : "/") + params[:typed_stage].to_s
|
69
|
+
# else
|
70
|
+
# ""
|
71
|
+
# end
|
72
|
+
render_base(params, params[:typed_stage]) +
|
34
73
|
("%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{edition}" % params)
|
35
74
|
end
|
36
75
|
|
37
|
-
def
|
38
|
-
|
39
|
-
stage = render_stage(values[:stage], opts, params)
|
40
|
-
type = values[:type]&.to_s
|
41
|
-
return unless type || stage
|
42
|
-
|
43
|
-
if type && stage
|
44
|
-
# don't add prefix for pdf format
|
45
|
-
if %w(DIS FDIS).include?(stage)
|
46
|
-
"#{render_short_stage(stage)}#{type}"
|
47
|
-
else
|
48
|
-
"#{stage} #{type}"
|
49
|
-
end
|
50
|
-
else
|
51
|
-
# when only type or stage
|
52
|
-
"#{type}#{stage}"
|
53
|
-
end
|
76
|
+
def render_typed_stage(typed_stage, _opts, params)
|
77
|
+
(params[:copublisher] ? " " : "/") + typed_stage.to_s
|
54
78
|
end
|
55
79
|
|
80
|
+
# def render_type_stage(values, opts, params)
|
81
|
+
#
|
82
|
+
# # prerender stage and type before
|
83
|
+
# stage = render_stage(values[:stage], opts, params)
|
84
|
+
# type = values[:type]&.to_s
|
85
|
+
# return unless type || stage
|
86
|
+
#
|
87
|
+
# if type && stage
|
88
|
+
# # don't add prefix for pdf format
|
89
|
+
# if %w(DIS FDIS).include?(stage)
|
90
|
+
# "#{render_short_stage(stage)}#{type}"
|
91
|
+
# else
|
92
|
+
# "#{stage} #{type}"
|
93
|
+
# end
|
94
|
+
# else
|
95
|
+
# # when only type or stage
|
96
|
+
# "#{type}#{stage}"
|
97
|
+
# end
|
98
|
+
# end
|
99
|
+
|
56
100
|
def render_short_stage(stage)
|
57
101
|
case stage
|
58
102
|
when "DIS"
|
@@ -1,16 +1,13 @@
|
|
1
1
|
module Pubid::Iso::Renderer
|
2
2
|
class French < Base
|
3
|
-
def
|
4
|
-
if
|
5
|
-
|
6
|
-
|
7
|
-
super
|
8
|
-
end
|
3
|
+
def render_typed_stage(typed_stage, opts, params)
|
4
|
+
return nil if typed_stage.type == :guide
|
5
|
+
|
6
|
+
super
|
9
7
|
end
|
10
8
|
|
11
9
|
def render_identifier(params)
|
12
|
-
if params[:type
|
13
|
-
params[:type] = nil
|
10
|
+
if @params[:typed_stage]&.type == :guide
|
14
11
|
"Guide #{super(params)}"
|
15
12
|
else
|
16
13
|
super
|
@@ -18,17 +18,16 @@ module Pubid::Iso::Renderer
|
|
18
18
|
"ISP" => "ИСП",
|
19
19
|
}.freeze
|
20
20
|
|
21
|
-
def
|
22
|
-
if
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
def render_typed_stage(typed_stage, opts, params)
|
22
|
+
return nil if typed_stage.type == :guide
|
23
|
+
|
24
|
+
return (params[:copublisher] ? " " : "/") + STAGE[typed_stage.to_s] if STAGE.key?(typed_stage.to_s)
|
25
|
+
|
26
|
+
super
|
27
27
|
end
|
28
28
|
|
29
29
|
def render_identifier(params)
|
30
|
-
if params[:type
|
31
|
-
params[:type] = nil
|
30
|
+
if @params[:typed_stage]&.type == :guide
|
32
31
|
"Руководство #{super(params)}"
|
33
32
|
else
|
34
33
|
super
|
@@ -19,20 +19,29 @@ module Pubid::Iso::Renderer
|
|
19
19
|
# @param with_edition [Boolean] include edition in output
|
20
20
|
# @see Pubid::Core::Renderer::Base for another options
|
21
21
|
def render(with_edition: true, **args)
|
22
|
+
# copy type from typed stage
|
23
|
+
@params[:type] = @params[:typed_stage].type if @params[:typed_stage] && @params[:typed_stage].type
|
22
24
|
super(**args.merge({ with_edition: with_edition }))
|
23
25
|
end
|
24
26
|
|
25
27
|
def render_identifier(params)
|
26
|
-
render_base(params) + "%{
|
28
|
+
render_base(params) + "%{typed_stage}"\
|
27
29
|
"%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}" % params
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
31
|
-
":stage-#{stage.harmonized_code}"
|
32
|
+
def render_typed_stage(typed_stage, _opts, _params)
|
33
|
+
":stage-#{typed_stage.stage.harmonized_code}" if typed_stage.stage
|
34
|
+
end
|
35
|
+
# def render_stage(stage, _opts, params)
|
36
|
+
# ":stage-#{stage.harmonized_code}"
|
37
|
+
# end
|
38
|
+
|
39
|
+
def render_iteration(iteration, _opts, params)
|
40
|
+
".v#{iteration}" if params[:typed_stage]&.stage
|
32
41
|
end
|
33
42
|
|
34
43
|
def render_type(type, _, _)
|
35
|
-
":#{type.to_s.downcase}"
|
44
|
+
":#{type.to_s.downcase}" unless type == :is
|
36
45
|
end
|
37
46
|
|
38
47
|
def render_year(year, _opts, _params)
|
data/lib/pubid/iso/stage.rb
CHANGED
@@ -2,37 +2,20 @@ module Pubid::Iso
|
|
2
2
|
class Stage
|
3
3
|
attr_accessor :abbr, :harmonized_code
|
4
4
|
|
5
|
-
STAGES = { PWI:
|
6
|
-
NP:
|
5
|
+
STAGES = { PWI: %w[00.00 00.20 00.60 00.98 00.99],
|
6
|
+
NP: %w[10.00 10.20 10.60 10.98 10.92],
|
7
7
|
AWI: %w[20.00 10.99],
|
8
8
|
WD: %w[20.20 20.60 20.98 20.99],
|
9
|
-
CD:
|
10
|
-
|
11
|
-
FDIS: "50.00",
|
12
|
-
PRF: "60.00",
|
13
|
-
IS: "60.60" }.freeze
|
9
|
+
CD: %w[30.00 30.20 30.60 30.92 30.98 30.99],
|
10
|
+
PRF: "60.00" }.freeze
|
14
11
|
|
15
12
|
|
16
13
|
STAGE_NAMES = {
|
17
|
-
FDIS: "Final Draft International Standard",
|
18
|
-
DIS: "Draft International Standard",
|
19
14
|
WD: "Working Draft",
|
20
15
|
PWI: "Preliminary Work Item",
|
21
16
|
NP: "New Proposal",
|
22
17
|
CD: "Committee Draft",
|
23
18
|
PRF: "Proof of a new International Standard",
|
24
|
-
IS: "International Standard",
|
25
|
-
}.freeze
|
26
|
-
|
27
|
-
STAGE_NAMES_SHORT = {
|
28
|
-
FDIS: "Final Draft",
|
29
|
-
DIS: "Draft",
|
30
|
-
WD: "Working Draft",
|
31
|
-
PWI: "Preliminary Work Item",
|
32
|
-
NP: "New Proposal",
|
33
|
-
CD: "Committee Draft",
|
34
|
-
PRF: "Proof of a new International Standard",
|
35
|
-
IS: "International Standard",
|
36
19
|
}.freeze
|
37
20
|
|
38
21
|
# @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
|
@@ -44,27 +27,38 @@ module Pubid::Iso
|
|
44
27
|
@harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
|
45
28
|
harmonized_code
|
46
29
|
else
|
47
|
-
HarmonizedStageCode.new(
|
30
|
+
HarmonizedStageCode.new(harmonized_code)
|
48
31
|
end
|
49
|
-
@abbr ||= lookup_abbr(@harmonized_code.
|
32
|
+
@abbr ||= lookup_abbr(@harmonized_code.stages)
|
33
|
+
# unless @harmonized_code.fuzzy?
|
34
|
+
# @abbr ||= lookup_abbr(@harmonized_code.to_s) || lookup_abbr("#{@harmonized_code.stage}.00")
|
35
|
+
# end
|
50
36
|
end
|
51
37
|
|
52
38
|
if abbr
|
53
39
|
raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)
|
54
40
|
|
55
|
-
@harmonized_code ||= HarmonizedStageCode.new(
|
41
|
+
@harmonized_code ||= HarmonizedStageCode.new(lookup_code(abbr))
|
56
42
|
end
|
57
43
|
end
|
58
44
|
|
59
45
|
# Lookup for abbreviated code by numeric stage code
|
60
|
-
# @param lookup_code [String] stage code
|
46
|
+
# @param lookup_code [String, Array] stage code or array of stage codes,
|
47
|
+
# e.g. "00.00", "20.20", ["00.00", "00.20"]
|
61
48
|
def lookup_abbr(lookup_code)
|
49
|
+
lookup_code = lookup_code.first if lookup_code.is_a?(Array) && lookup_code.count == 1
|
50
|
+
|
62
51
|
STAGES.each do |abbr, codes|
|
63
52
|
case codes
|
64
53
|
when Array
|
65
|
-
|
66
|
-
return abbr if
|
54
|
+
if lookup_code.is_a?(Array)
|
55
|
+
return abbr if codes == lookup_code
|
56
|
+
else
|
57
|
+
return abbr if codes.include?(lookup_code)
|
67
58
|
end
|
59
|
+
# codes.each do |code|
|
60
|
+
# return abbr if code == lookup_code
|
61
|
+
# end
|
68
62
|
when lookup_code
|
69
63
|
return abbr
|
70
64
|
end
|
@@ -74,8 +68,8 @@ module Pubid::Iso
|
|
74
68
|
end
|
75
69
|
|
76
70
|
def lookup_code(lookup_abbr)
|
77
|
-
|
78
|
-
code.is_a?(Array) ? code.first : code
|
71
|
+
STAGES[lookup_abbr.to_sym]
|
72
|
+
# code.is_a?(Array) ? code.first : code
|
79
73
|
end
|
80
74
|
|
81
75
|
def self.parse(stage)
|
@@ -88,6 +82,14 @@ module Pubid::Iso
|
|
88
82
|
end
|
89
83
|
end
|
90
84
|
|
85
|
+
def self.has_stage?(stage)
|
86
|
+
if stage.is_a?(Stage)
|
87
|
+
STAGES.key?(stage.abbr.to_sym)
|
88
|
+
else
|
89
|
+
STAGES.key?(stage.to_sym) || /\A[\d.]+\z/.match?(stage)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
91
93
|
# Compares one stage with another
|
92
94
|
def ==(other)
|
93
95
|
other&.harmonized_code == harmonized_code
|
@@ -97,10 +99,5 @@ module Pubid::Iso
|
|
97
99
|
def name
|
98
100
|
STAGE_NAMES[abbr.to_sym]
|
99
101
|
end
|
100
|
-
|
101
|
-
# Return short stage name, eg. "Draft" for "DIS"
|
102
|
-
def short_name
|
103
|
-
STAGE_NAMES_SHORT[abbr.to_sym]
|
104
|
-
end
|
105
102
|
end
|
106
103
|
end
|
data/lib/pubid/iso/supplement.rb
CHANGED
@@ -1,35 +1,36 @@
|
|
1
1
|
module Pubid::Iso
|
2
2
|
class Supplement < Pubid::Core::Supplement
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :typed_stage, :publisher, :edition, :iteration
|
4
4
|
|
5
5
|
# @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
|
6
6
|
# @param publisher [String] publisher, e.g. "ISO", "IEC" (only for DIR documents)
|
7
7
|
# @param edition [Integer] edition, e.g. 1, 2, 3
|
8
8
|
# @param iteration [Integer] iteration, e.g. 1, 2, 3
|
9
9
|
# @see Pubid::Core::Supplement for other options
|
10
|
-
def initialize(
|
10
|
+
def initialize(typed_stage: nil, publisher: nil, edition: nil, iteration: nil, **args)
|
11
11
|
super(**args)
|
12
|
-
@
|
12
|
+
@typed_stage = TypedStage.parse(typed_stage) if typed_stage
|
13
13
|
# for DIR identifiers only
|
14
14
|
@publisher = publisher.to_s
|
15
15
|
@edition = edition&.to_i
|
16
16
|
@iteration = iteration&.to_i
|
17
17
|
|
18
|
-
if @iteration && @
|
18
|
+
if @iteration && @typed_stage.nil?
|
19
19
|
raise Errors::PublishedIterationError.new("cannot assign iteration to published supplement")
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def render_pubid_stage
|
24
|
-
|
24
|
+
# @typed_stage.stage.abbr != "IS" &&
|
25
|
+
((@typed_stage && @typed_stage.to_s) || "")
|
25
26
|
end
|
26
27
|
|
27
28
|
def render_urn_stage
|
28
|
-
((@stage && ":stage-#{@stage.harmonized_code}") || "")
|
29
|
+
((@typed_stage&.stage && ":stage-#{@typed_stage.stage.harmonized_code}") || "")
|
29
30
|
end
|
30
31
|
|
31
32
|
def <=>(other)
|
32
|
-
(super == 0) && ((
|
33
|
+
(super == 0) && ((typed_stage.nil? || typed_stage == other.typed_stage) && 0 || -1) || super
|
33
34
|
end
|
34
35
|
|
35
36
|
def render_iteration
|
@@ -8,13 +8,47 @@ module Pubid::Iso
|
|
8
8
|
{ stage: convert_stage(context[:stage]) }
|
9
9
|
end
|
10
10
|
|
11
|
+
rule(supplements: subtree(:supplements)) do |context|
|
12
|
+
context[:supplements] =
|
13
|
+
context[:supplements].map do |supplement|
|
14
|
+
supplement[:typed_stage] = case supplement[:typed_stage]
|
15
|
+
when "PDAM"
|
16
|
+
"CD Amd"
|
17
|
+
when "pDCOR"
|
18
|
+
"CD Cor"
|
19
|
+
when "FCOR"
|
20
|
+
"FDCor"
|
21
|
+
when "FPDAM"
|
22
|
+
"DAmd"
|
23
|
+
when "FDAM"
|
24
|
+
"FDAmd"
|
25
|
+
else
|
26
|
+
supplement[:typed_stage]
|
27
|
+
end
|
28
|
+
# Supplement.new(
|
29
|
+
# number: supplement[:number],
|
30
|
+
# year: supplement[:year],
|
31
|
+
# typed_stage:
|
32
|
+
# case supplement[:typed_stage]
|
33
|
+
# when "FCOR"
|
34
|
+
# "FDCor"
|
35
|
+
# else
|
36
|
+
# supplement[:typed_stage]
|
37
|
+
# end,
|
38
|
+
# iteration: supplement[:iteration]
|
39
|
+
# )
|
40
|
+
supplement
|
41
|
+
end
|
42
|
+
context
|
43
|
+
end
|
44
|
+
|
11
45
|
rule(amendments: subtree(:amendments)) do |context|
|
12
46
|
context[:amendments] =
|
13
47
|
context[:amendments].map do |amendment|
|
14
48
|
Amendment.new(
|
15
49
|
number: amendment[:number],
|
16
50
|
year: amendment[:year],
|
17
|
-
|
51
|
+
typed_stage: amendment[:stage] && convert_stage(amendment[:stage]),
|
18
52
|
iteration: amendment[:iteration])
|
19
53
|
end
|
20
54
|
context
|
@@ -26,7 +60,7 @@ module Pubid::Iso
|
|
26
60
|
Corrigendum.new(
|
27
61
|
number: corrigendum[:number],
|
28
62
|
year: corrigendum[:year],
|
29
|
-
|
63
|
+
typed_stage: corrigendum[:stage] && convert_stage(corrigendum[:stage]),
|
30
64
|
iteration: corrigendum[:iteration])
|
31
65
|
end
|
32
66
|
context
|
@@ -124,12 +158,17 @@ module Pubid::Iso
|
|
124
158
|
"FDIS"
|
125
159
|
when "Fpr"
|
126
160
|
"PRF"
|
127
|
-
when "pD", "PD"
|
128
|
-
|
161
|
+
# when "pD", "PD"
|
162
|
+
# "CD"
|
163
|
+
when "PDTR"
|
164
|
+
"CD TR"
|
165
|
+
when "PDTS"
|
166
|
+
"CD TS"
|
129
167
|
else
|
130
168
|
code
|
131
169
|
end
|
132
|
-
|
170
|
+
russian_code || code
|
171
|
+
# Stage.new(abbr: (russian_code || code))
|
133
172
|
end
|
134
173
|
|
135
174
|
def self.convert_language(code)
|
data/lib/pubid/iso/type.rb
CHANGED
@@ -0,0 +1,204 @@
|
|
1
|
+
module Pubid::Iso
|
2
|
+
class TypedStage
|
3
|
+
attr_accessor :type, :stage, :typed_stage
|
4
|
+
|
5
|
+
TYPED_STAGES = {
|
6
|
+
dtr: {
|
7
|
+
abbr: "DTR",
|
8
|
+
type: :tr,
|
9
|
+
name: "Draft Technical Report",
|
10
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93 50.00 50.20 50.60 50.92],
|
11
|
+
},
|
12
|
+
dis: {
|
13
|
+
abbr: "DIS",
|
14
|
+
type: :is,
|
15
|
+
name: "Draft International Standard",
|
16
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93],
|
17
|
+
},
|
18
|
+
dts: {
|
19
|
+
abbr: "DTS",
|
20
|
+
type: :ts,
|
21
|
+
name: "Draft Technical Specification",
|
22
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93 50.00 50.20 50.60 50.92],
|
23
|
+
},
|
24
|
+
fdts: {
|
25
|
+
abbr: "FDTS",
|
26
|
+
type: :ts,
|
27
|
+
name: "Final Draft Technical Specification",
|
28
|
+
harmonized_stages: %w[50.00 50.20 50.60 50.92],
|
29
|
+
},
|
30
|
+
fdtr: {
|
31
|
+
abbr: "FDTR",
|
32
|
+
type: :tr,
|
33
|
+
name: "Final Draft Technical Report",
|
34
|
+
harmonized_stages: %w[50.00 50.20 50.60 50.92],
|
35
|
+
},
|
36
|
+
fdis: {
|
37
|
+
abbr: "FDIS",
|
38
|
+
type: :is,
|
39
|
+
name: "Final Draft International Standard",
|
40
|
+
harmonized_stages: %w[50.00 50.20 50.60 50.92],
|
41
|
+
},
|
42
|
+
dpas: {
|
43
|
+
abbr: "DPAS",
|
44
|
+
type: :pas,
|
45
|
+
name: "Publicly Available Specification Draft",
|
46
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93 50.00 50.20 50.60 50.92],
|
47
|
+
},
|
48
|
+
damd: {
|
49
|
+
abbr: { short: "DAM", long: "DAmd" },
|
50
|
+
type: :amd,
|
51
|
+
name: "Draft Amendment",
|
52
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93 50.00 50.20 50.60 50.92],
|
53
|
+
},
|
54
|
+
dcor: {
|
55
|
+
abbr: { short: "DCOR", long: "DCor" },
|
56
|
+
type: :cor,
|
57
|
+
name: "Draft Corrigendum",
|
58
|
+
harmonized_stages: %w[40.00 40.20 40.60 40.92 40.93 50.00 50.20 50.60 50.92],
|
59
|
+
},
|
60
|
+
fdamd: {
|
61
|
+
abbr: { short: "FDAM", long: "FDAmd" },
|
62
|
+
type: :amd,
|
63
|
+
name: "Final Draft Amendment",
|
64
|
+
harmonized_stages: %w[50.00 50.20 50.60 50.92],
|
65
|
+
},
|
66
|
+
fdcor: {
|
67
|
+
abbr: { short: "FDCOR", long: "FDCor" },
|
68
|
+
type: :cor,
|
69
|
+
name: "Final Draft Corrigendum",
|
70
|
+
harmonized_stages: %w[50.00 50.20 50.60 50.92],
|
71
|
+
},
|
72
|
+
}.freeze
|
73
|
+
|
74
|
+
# @param type [Symbol,Type] eg. :tr, Type.new(:tr)
|
75
|
+
# @param stage [Symbol,Stage] eg. :CD, Stage.new(abbr: :CD)
|
76
|
+
def initialize(abbr: nil, type: nil, stage: nil)
|
77
|
+
@type = type.is_a?(Type) ? type : Type.new(type) if type
|
78
|
+
@stage = stage.is_a?(Stage) ? stage : Stage.new(abbr: stage) if stage
|
79
|
+
|
80
|
+
if abbr
|
81
|
+
raise Errors::TypeStageInvalidError, "#{abbr} is not valid typed stage" unless TYPED_STAGES.key?(abbr)
|
82
|
+
assign_abbreviation(abbr)
|
83
|
+
elsif !@stage.nil?
|
84
|
+
# lookup for typed stage
|
85
|
+
@typed_stage = lookup_typed_stage
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def lookup_typed_stage
|
90
|
+
return nil unless @stage
|
91
|
+
|
92
|
+
TYPED_STAGES.each do |typed_stage, values|
|
93
|
+
if values[:harmonized_stages].include?(@stage.harmonized_code.to_s) && values[:type] == @type&.type
|
94
|
+
return typed_stage
|
95
|
+
end
|
96
|
+
end
|
97
|
+
nil
|
98
|
+
end
|
99
|
+
|
100
|
+
# Assigns type and stage according to provided typed stage abbreviation
|
101
|
+
# @param abbr [Symbol] eg. :dtr, :damd, :dis
|
102
|
+
def assign_abbreviation(abbr)
|
103
|
+
@typed_stage = if TYPED_STAGES.key?(abbr.downcase.to_sym)
|
104
|
+
abbr.downcase.to_sym
|
105
|
+
else
|
106
|
+
TYPED_STAGES.select do |_, v|
|
107
|
+
if v[:abbr].is_a?(Hash)
|
108
|
+
v[:abbr].values.include?(abbr)
|
109
|
+
else
|
110
|
+
v[:abbr] == abbr
|
111
|
+
end
|
112
|
+
end.keys.first
|
113
|
+
end
|
114
|
+
|
115
|
+
@type = Type.new(TYPED_STAGES[@typed_stage][:type])
|
116
|
+
@stage = Stage.new(harmonized_code: HarmonizedStageCode.new(TYPED_STAGES[@typed_stage][:harmonized_stages]))
|
117
|
+
end
|
118
|
+
|
119
|
+
# Render typed stage
|
120
|
+
# @param stage_format_long [Boolean] render stage in long or short format
|
121
|
+
def to_s(stage_format_long = true)
|
122
|
+
# return "" if @type == :amd || @type == :cor
|
123
|
+
if @typed_stage
|
124
|
+
if TYPED_STAGES[@typed_stage][:abbr].is_a?(Hash)
|
125
|
+
return TYPED_STAGES[@typed_stage][:abbr][stage_format_long ? :long : :short]
|
126
|
+
else
|
127
|
+
return TYPED_STAGES[@typed_stage][:abbr]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
result = (@stage && @stage.abbr != "IS") ? "#{@stage.abbr}" : ""
|
132
|
+
result += " " if !result.empty? && @type && stage_format_long
|
133
|
+
result + if stage_format_long
|
134
|
+
"#{@type&.to_s}"
|
135
|
+
else
|
136
|
+
if @type == :amd
|
137
|
+
"AM"
|
138
|
+
elsif @type == :cor
|
139
|
+
"COR"
|
140
|
+
else
|
141
|
+
"#{@type&.to_s}"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# Check if typed stage listed in TYPED_STAGES constant
|
147
|
+
# @param typed_stage [String,Symbol] typed stage abbreviation, eg. "DTS", :dts, "DAmd", :damd
|
148
|
+
def self.has_typed_stage?(typed_stage)
|
149
|
+
return true if TYPED_STAGES.key?(typed_stage)
|
150
|
+
|
151
|
+
TYPED_STAGES.any? do |_, v|
|
152
|
+
if v[:abbr].is_a?(Hash)
|
153
|
+
v[:abbr].values.include?(typed_stage)
|
154
|
+
else
|
155
|
+
v[:abbr] == typed_stage
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Assigns stage or type or typed stage or stage and type depending on provided string
|
161
|
+
# @param stage_or_typed_stage [String, Stage] eg. "DTR", "CD", Stage.new(:CD), "TR", "CD Amd", :dtr
|
162
|
+
def parse_stage(stage_or_typed_stage)
|
163
|
+
if self.class.has_typed_stage?(stage_or_typed_stage)
|
164
|
+
return assign_abbreviation(stage_or_typed_stage)
|
165
|
+
end
|
166
|
+
|
167
|
+
if stage_or_typed_stage.is_a?(Stage)
|
168
|
+
@stage = stage_or_typed_stage
|
169
|
+
elsif stage_or_typed_stage.is_a?(String) && stage_or_typed_stage.split.count == 2 &&
|
170
|
+
Stage.has_stage?(stage_or_typed_stage.split.first)
|
171
|
+
# stage and type ("CD Amd")
|
172
|
+
@stage = Stage.parse(stage_or_typed_stage.split.first)
|
173
|
+
@type = Type.parse(stage_or_typed_stage.split.last)
|
174
|
+
elsif Type.has_type?(stage_or_typed_stage)
|
175
|
+
@type = Type.parse(stage_or_typed_stage)
|
176
|
+
elsif Stage.has_stage?(stage_or_typed_stage)
|
177
|
+
@stage = Stage.parse(stage_or_typed_stage.to_s)
|
178
|
+
else
|
179
|
+
raise Errors::TypeStageParseError, "cannot parse typed stage or stage"
|
180
|
+
end
|
181
|
+
@typed_stage = lookup_typed_stage
|
182
|
+
end
|
183
|
+
|
184
|
+
# Parse stage or typed stage
|
185
|
+
# @return [TypedStage] typed stage object with parsed stage and typed stage
|
186
|
+
def self.parse(stage_or_typed_stage)
|
187
|
+
return stage_or_typed_stage if stage_or_typed_stage.is_a?(TypedStage)
|
188
|
+
|
189
|
+
typed_stage = new
|
190
|
+
typed_stage.parse_stage(stage_or_typed_stage)
|
191
|
+
typed_stage
|
192
|
+
end
|
193
|
+
|
194
|
+
def name
|
195
|
+
TYPED_STAGES[@typed_stage][:name]
|
196
|
+
end
|
197
|
+
|
198
|
+
def ==(other)
|
199
|
+
return false if other.nil?
|
200
|
+
|
201
|
+
type == other.type && typed_stage == other.typed_stage && stage == other.stage
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
data/lib/pubid/iso/version.rb
CHANGED
data/lib/pubid/iso.rb
CHANGED
@@ -12,6 +12,7 @@ require "pubid-core"
|
|
12
12
|
require_relative "iso/errors"
|
13
13
|
require_relative "iso/stage"
|
14
14
|
require_relative "iso/type"
|
15
|
+
require_relative "iso/typed_stage"
|
15
16
|
require_relative "iso/harmonized_stage_code"
|
16
17
|
require_relative "iso/parser"
|
17
18
|
require_relative "iso/transformer"
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.3.0
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.3.0
|
111
111
|
description: Library to generate, parse and manipulate ISO PubID.
|
112
112
|
email:
|
113
113
|
- open.source@ribose.com
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/pubid/iso/supplement.rb
|
140
140
|
- lib/pubid/iso/transformer.rb
|
141
141
|
- lib/pubid/iso/type.rb
|
142
|
+
- lib/pubid/iso/typed_stage.rb
|
142
143
|
- lib/pubid/iso/version.rb
|
143
144
|
homepage: https://github.com/metanorma/pubid-iso
|
144
145
|
licenses:
|