pubid-iso 0.2.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d60d5581ae205f08b23f80682735696086c753587386ab0b7bfcf7ce306e6156
4
- data.tar.gz: '08d626a7cbb67820faac3fb9503dce84f21d13fcd8387671d110878de84adc4a'
3
+ metadata.gz: 418f8b225027cf9b50cb2ec43aad7d043b3bfd0db87733366c6021df8f92f940
4
+ data.tar.gz: fd9a028a0cb2721b4422b2f515aa46263c7d713da57e02c8fc1ed4c54c22f737
5
5
  SHA512:
6
- metadata.gz: b690e1a4d95efe0ed794ce74c1fef9e320cbb394c473650af6e7fded623ec4f986cb1d4ca463bdeab988be14d82fd14c0f7ec48f51febd8cd98d0ae2cd17a5eb
7
- data.tar.gz: 33ca94206cb4b8812956fd3d1c146c77a5a5d8e24cd55e002405e6acc28b54b5433f4caf23e59bab5320b4189a4fb78c469696218995538d36600a1124abe341
6
+ metadata.gz: bf1f97bde499237e29b24b793d7e9fe115e03e42a92471a549f90aea9c416ddc357fcfd95079a97bff4b200b4fe8c93f786fc8e3c8256ad3275f2365f9c946e8
7
+ data.tar.gz: d4b53365fc22d587b204a7c38fcaf362e7f85b5cc5a07767ecb4f97fe5c7a3b8c70c3e24c8c30b63166321bd4f757f7d6658df154a4ccab4715ae94c62e8f17e
data/README.adoc CHANGED
@@ -64,6 +64,31 @@ pubid.to_s
64
64
  => "ISO 1234-1"
65
65
  ----
66
66
 
67
+ ==== Iteration
68
+
69
+ [source,ruby]
70
+ ----
71
+ pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123, part: 1, stage: :DIS, iteration: 1)
72
+ pubid.to_s
73
+
74
+ => "ISO/DIS 1234-1.1"
75
+ ----
76
+ To apply iteration to document stage should be provided as well.
77
+ Without stage error will be raised.
78
+
79
+ ==== Amendment and Corrigendum
80
+ [source,ruby]
81
+ ----
82
+ > pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123, part: 1, year: 2019, amendments: [{ number: "1", year: "2021", stage: :WD }])
83
+ > pubid.to_s
84
+ => "ISO 1234-1:2019/WD Amd 1:2021"
85
+
86
+ > pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123, part: 1, year: 2019, corrigendums: [{ number: "1", year: "2021", stage: :WD }])
87
+ > pubid.to_s
88
+ => "ISO 1234-1:2019/WD Cor 1:2021"
89
+ ----
90
+ See documentation on https://rubydoc.info/gems/pubid-iso/Pubid%2FIso%2FSupplement:initialize[PubId::Iso::Supplement#initialize] and https://rubydoc.info/gems/pubid-core/Pubid%2FCore%2FSupplement:initialize[Pubid::Core::Supplement#initialize] to see all available options.
91
+
67
92
  ==== Using format options
68
93
  [source,ruby]
69
94
  ----
@@ -107,12 +132,34 @@ pubid.to_s
107
132
  part: "1",
108
133
  year: 2019,
109
134
  edition: 1,
110
- amendment: {number: "1", year: "2021", stage: "DIS"}
135
+ amendments: {number: "1", year: "2021", stage: "DIS"}
111
136
  )
112
137
  > pubid.urn
113
138
  => "urn:iso:std:iso:8601:-1:ed-1:amd:2021:v1"
114
139
  ----
115
140
 
141
+ ==== Typed stage abbreviation
142
+ [source,ruby]
143
+ ----
144
+ > pubid = Pubid::Iso::Identifier.parse("ISO/FDIS 26000:2010")
145
+ > pubid.typed_stage_abbrev
146
+ => "FDIS"
147
+ > pubid.typed_stage_name
148
+ => "Final Draft"
149
+
150
+ > pubid = Pubid::Iso::Identifier.parse("ISO/FDTR 26000:2010")
151
+ > pubid.typed_stage_abbrev
152
+ => "FDTR"
153
+ > pubid.typed_stage_name
154
+ => "Final Draft Technical Report"
155
+
156
+ > pubid = Pubid::Iso::Identifier.parse("ISO/WD TR 26000:2010")
157
+ > pubid.typed_stage_abbrev
158
+ => "WD TR"
159
+ > pubid.typed_stage_name
160
+ => "Working Draft Technical Report"
161
+ ----
162
+
116
163
  See documentation (https://www.rubydoc.info/gems/pubid-iso/Pubid/Iso/Identifier#initialize-instance_method[Pubid::Iso::Identifier] and https://www.rubydoc.info/gems/pubid-core/Pubid/Core/Identifier#initialize-instance_method[Pubid::Core::Identifier]) for all available attributes and options.
117
164
 
118
165
  == Elements of the PubID
@@ -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
- case stage.to_s
9
- when "DIS"
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
- case stage.to_s
7
- when "DIS"
8
- if stage_format_long
9
- "/DCor #{pubid_number}"
10
- else
11
- "/DCOR #{pubid_number}"
12
- end
13
- when "FDIS"
14
- if stage_format_long
15
- "/FDCor #{pubid_number}"
16
- else
17
- "/FDCOR #{pubid_number}"
18
- end
19
- when ""
20
- "/Cor #{pubid_number}"
21
- else
22
- "/#{stage} Cor #{pubid_number}"
23
- end
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
@@ -3,11 +3,19 @@ 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
9
+ class IterationWithoutStageError < StandardError; end
8
10
  class WrongFormat < StandardError; end
9
11
  # Error raised when supplement applied to base document without publication year or stage
10
12
  class SupplementWithoutYearOrStageError < StandardError; end
11
13
  class NoEditionError < StandardError; end
14
+ class WrongTypeError < StandardError; end
15
+ class ParseTypeError < StandardError; end
16
+ class TypeStageInvalidError < StandardError; end
17
+ class TypeStageParseError < StandardError; end
18
+
19
+ class SupplementRenderingError < StandardError; end
12
20
  end
13
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
- def initialize(stage, substage = "00")
78
- # when stage is stage name
79
- if STAGES_NAMES.key?(stage)
80
- @stage = STAGES_NAMES[stage]
81
- @substage = SUBSTAGES_NAMES[substage]
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
- # stage is number
84
- @stage, @substage = stage, substage
85
- validate_stage(stage, substage)
119
+ @stages.first
86
120
  end
87
121
  end
88
122
 
89
- def validate_stage(stage, substage)
90
- # raise an error if stage is not number
91
- raise Errors::HarmonizedStageCodeInvalidError if Integer(stage).nil?
123
+ def ==(other)
124
+ (stages & other.stages) == other.stages
125
+ end
92
126
 
93
- # raise an error when substage wrong
94
- raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(to_s)
127
+ def fuzzy?
128
+ @stages.length > 1
95
129
  end
96
130
 
97
- def to_s
98
- "#{stage}.#{substage}"
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 ==(other)
102
- stage == other.stage && substage == other.substage
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
@@ -3,15 +3,17 @@ module Pubid::Iso
3
3
  attr_accessor :stage,
4
4
  :iteration, :joint_document,
5
5
  :tctype, :sctype, :wgtype, :tcnumber, :scnumber, :wgnumber,
6
- :urn_stage, :dirtype,
6
+ :dirtype,
7
7
  # supplement for DIR type identifiers
8
- :supplement
8
+ :supplement,
9
+ :base,
10
+ :typed_stage,
11
+ :supplements
9
12
 
10
13
  # Creates new identifier from options provided, includes options from
11
14
  # Pubid::Core::Identifier#initialize
12
15
  #
13
- # @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
14
- # @param urn_stage [Float] numeric stage for URN rendering
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
@@ -22,42 +24,73 @@ module Pubid::Iso
22
24
  # @param scnumber [Integer] Subsommittee number, eg. "1", "2"
23
25
  # @param wgnumber [Integer] Working group number, eg. "1", "2"
24
26
  # @param dirtype [String] Directives document type, eg. "JTC"
27
+ # @param base [Identifier] base document for supplement's identifier
28
+ # @param type [nil, :tr, :ts, :amd, :cor, :guide, :dir, :tc, Type] document's type, eg. :tr, :ts, :amd, :cor, Type.new(:tr)
25
29
  # @raise [Errors::SupplementWithoutYearOrStageError] when trying to apply
26
30
  # supplement to the document without edition year or stage
27
31
  # @raise [Errors::IsStageIterationError] when trying to apply iteration
28
32
  # to document with IS stage
33
+ # @raise [Errors::IterationWithoutStageError] when trying to applu iteration
34
+ # to document without stage
29
35
  # @see Supplement
30
36
  # @see Identifier
31
37
  # @see Pubid::Core::Identifier
32
38
  # @see Parser
33
39
  #
34
40
  def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
35
- joint_document: nil, urn_stage: nil,
36
- tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
41
+ joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
37
42
  scnumber: nil, wgnumber:nil,
38
43
  dir: nil, dirtype: nil, year: nil, amendments: nil,
39
- corrigendums: nil, type: nil, **opts)
44
+ corrigendums: nil, type: nil, base: nil, supplements: nil, **opts)
40
45
  super(**opts.merge(number: number, publisher: publisher, year: year,
41
- amendments: amendments, corrigendums: corrigendums, type: type))
46
+ amendments: amendments, corrigendums: corrigendums))
42
47
 
43
- if (amendments || corrigendums) && (year.nil? && stage.nil?)
44
- raise Errors::SupplementWithoutYearOrStageError, "Cannot apply supplement to document without edition year or stage"
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
+
58
+ if %i(amd cor).include?(type) && (base.year.nil? && base.stage.nil?)
59
+ raise Errors::SupplementWithoutYearOrStageError,
60
+ "Cannot apply supplement to document without base identifieredition year or stage"
45
61
  end
46
- if stage
47
- @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)
48
62
 
49
- if @stage.abbr == "IS" && iteration
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
50
75
  raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
51
76
  end
52
77
 
53
- if @stage.abbr == "FDIS" && type == "PAS"
54
- raise Errors::StageInvalidError, "PAS type cannot have FDIS stage"
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
55
86
  end
87
+ elsif iteration
88
+ raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration"
56
89
  end
90
+
57
91
  @iteration = iteration.to_i if iteration
58
92
  @supplement = supplement if supplement
59
93
  @joint_document = joint_document if joint_document
60
- @urn_stage = urn_stage if urn_stage
61
94
  @tctype = tctype if tctype
62
95
  @sctype = sctype.to_s if sctype
63
96
  @wgtype = wgtype.to_s if wgtype
@@ -66,6 +99,7 @@ module Pubid::Iso
66
99
  @wgnumber = wgnumber.to_s if wgnumber
67
100
  @dir = dir.to_s if dir
68
101
  @dirtype = dirtype.to_s if dirtype
102
+ @base = base if base
69
103
  end
70
104
 
71
105
  def self.parse_from_title(title)
@@ -78,6 +112,53 @@ module Pubid::Iso
78
112
  end
79
113
 
80
114
  class << self
115
+ def supplements_has_type?(supplements, type)
116
+ supplements.any? do |supplement|
117
+ supplement.typed_stage.type == type
118
+ end
119
+ end
120
+
121
+ def supplement_by_type(supplements, type)
122
+ supplements.select { |supplement| supplement.type == type }.first
123
+ end
124
+
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))
131
+ end
132
+
133
+ return supplements.first if supplements.count == 1
134
+
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"
144
+ end
145
+ end
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
151
+
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
158
+
159
+ new(**identifier_params)
160
+ end
161
+
81
162
  def get_amendment_class
82
163
  Pubid::Iso::Amendment
83
164
  end
@@ -102,10 +183,10 @@ module Pubid::Iso
102
183
  # Render URN identifier
103
184
  # @return [String] URN identifier
104
185
  def urn
105
- if (@amendments || @corrigendums) && !@edition
186
+ if %i(amd cor).include?(type&.type) && (@base.base.nil? && !@base.edition || (!@base.base.nil? && !@base.base.edition))
106
187
  raise Errors::NoEditionError, "Base document must have edition"
107
188
  end
108
- (@tctype && Renderer::UrnTc || @type == "DIR" && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
189
+ (@tctype && Renderer::UrnTc || type == :dir && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
109
190
  end
110
191
 
111
192
  # Renders pubid identifier
@@ -115,6 +196,7 @@ module Pubid::Iso
115
196
  # @param with_edition [Boolean] render identifier with edition
116
197
  # @param stage_format_long [Boolean] render with long or short stage format
117
198
  # @param format [:ref_num_short,:ref_num_long,:ref_dated,:ref_dated_long,:ref_undated,:ref_undated_long] create reference with specified format
199
+ # @param with_prf [Boolean] include PRF stage in output
118
200
  # Format options are:
119
201
  # :ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
120
202
  # :ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
@@ -162,16 +244,38 @@ module Pubid::Iso
162
244
  else
163
245
  if @tctype
164
246
  Renderer::Tc.new(get_params)
165
- elsif @type == "DIR"
247
+ elsif @typed_stage&.type == :dir
166
248
  Renderer::Dir.new(get_params)
167
249
  else
168
250
  self.class.get_renderer_class.new(get_params)
169
251
  end
170
252
  end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
171
253
  stage_format_long: stage_format_long, with_prf: with_prf) +
172
- if @joint_document && @type != "DIR"
254
+ if @joint_document && @typed_stage&.type != :dir
173
255
  "|#{@joint_document}"
174
256
  end.to_s
175
257
  end
258
+
259
+ def stage
260
+ typed_stage&.stage
261
+ end
262
+
263
+ def type
264
+ typed_stage&.type
265
+ end
266
+
267
+ # Return typed stage abbreviation, eg. "FDTR", "DIS", "TR"
268
+ def typed_stage_abbrev
269
+ typed_stage.to_s
270
+ end
271
+
272
+ # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
273
+ def typed_stage_name
274
+ typed_stage.name
275
+ end
276
+
277
+ def ==(other)
278
+ get_params == other.get_params
279
+ end
176
280
  end
177
281
  end
@@ -1,7 +1,10 @@
1
1
  module Pubid::Iso
2
2
  class Parser < Pubid::Core::Parser
3
- STAGES = %w[NP NWIP WD CD DIS FDIS PRF IS AWI PWI FPD pD PD FD D F].freeze
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(:amendment) do
60
- ((str("/") >> stage.as(:stage)).maybe >>
61
- (str("/") | space).maybe >>
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(:corrigendums)
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
- ((amendment >> corrigendum.maybe) | corrigendum).maybe) >>
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))