pubid-iso 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d60d5581ae205f08b23f80682735696086c753587386ab0b7bfcf7ce306e6156
4
- data.tar.gz: '08d626a7cbb67820faac3fb9503dce84f21d13fcd8387671d110878de84adc4a'
3
+ metadata.gz: 93b04a876f8ee73e80af8c49af1efc223d1b63a4d8a6b6b679a114d77befcc73
4
+ data.tar.gz: c39834a8f5290dc71d8bbcd79801e3313c1c888715040a7d67fbbda116d7572e
5
5
  SHA512:
6
- metadata.gz: b690e1a4d95efe0ed794ce74c1fef9e320cbb394c473650af6e7fded623ec4f986cb1d4ca463bdeab988be14d82fd14c0f7ec48f51febd8cd98d0ae2cd17a5eb
7
- data.tar.gz: 33ca94206cb4b8812956fd3d1c146c77a5a5d8e24cd55e002405e6acc28b54b5433f4caf23e59bab5320b4189a4fb78c469696218995538d36600a1124abe341
6
+ metadata.gz: 3bef9b0e5791702f0bcf3c291639d78cb3cd0319d94345b953a0e3608b22b895f019ee75bdcc742c78007281392be6cd2d60081fbe0a81cec9109de59fc31005
7
+ data.tar.gz: eb469ae1abc30c718355173cab16ee1b80cf1386adc1e65fbd5ba96b493f7c7ee9abdd0cab0612ec34159214524465d8323007ba3fd344a0ec3d2b611d6718de
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
@@ -5,9 +5,12 @@ module Pubid::Iso
5
5
  class HarmonizedStageCodeInvalidError < StandardError; end
6
6
  class StageInvalidError < StandardError; end
7
7
  class IsStageIterationError < StandardError; end
8
+ class IterationWithoutStageError < StandardError; end
8
9
  class WrongFormat < StandardError; end
9
10
  # Error raised when supplement applied to base document without publication year or stage
10
11
  class SupplementWithoutYearOrStageError < StandardError; end
11
12
  class NoEditionError < StandardError; end
13
+ class WrongTypeError < StandardError; end
14
+ class ParseTypeError < StandardError; end
12
15
  end
13
16
  end
@@ -3,15 +3,15 @@ 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
9
10
 
10
11
  # Creates new identifier from options provided, includes options from
11
12
  # Pubid::Core::Identifier#initialize
12
13
  #
13
14
  # @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
15
15
  # @param iteration [Integer] document iteration, eg. "1", "2", "3"
16
16
  # @param joint_document [Identifier] joint document
17
17
  # @param supplement [Supplement] supplement
@@ -22,26 +22,30 @@ module Pubid::Iso
22
22
  # @param scnumber [Integer] Subsommittee number, eg. "1", "2"
23
23
  # @param wgnumber [Integer] Working group number, eg. "1", "2"
24
24
  # @param dirtype [String] Directives document type, eg. "JTC"
25
+ # @param base [Identifier] base document for supplement's identifier
26
+ # @param type [nil, :tr, :ts, :amd, :cor, :guide, :dir, :tc, Type] document's type, eg. :tr, :ts, :amd, :cor, Type.new(:tr)
25
27
  # @raise [Errors::SupplementWithoutYearOrStageError] when trying to apply
26
28
  # supplement to the document without edition year or stage
27
29
  # @raise [Errors::IsStageIterationError] when trying to apply iteration
28
30
  # to document with IS stage
31
+ # @raise [Errors::IterationWithoutStageError] when trying to applu iteration
32
+ # to document without stage
29
33
  # @see Supplement
30
34
  # @see Identifier
31
35
  # @see Pubid::Core::Identifier
32
36
  # @see Parser
33
37
  #
34
38
  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,
39
+ joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
37
40
  scnumber: nil, wgnumber:nil,
38
41
  dir: nil, dirtype: nil, year: nil, amendments: nil,
39
- corrigendums: nil, type: nil, **opts)
42
+ corrigendums: nil, type: nil, base: nil, **opts)
40
43
  super(**opts.merge(number: number, publisher: publisher, year: year,
41
- amendments: amendments, corrigendums: corrigendums, type: type))
44
+ amendments: amendments, corrigendums: corrigendums))
42
45
 
43
- if (amendments || corrigendums) && (year.nil? && stage.nil?)
44
- raise Errors::SupplementWithoutYearOrStageError, "Cannot apply supplement to document without edition year or stage"
46
+ if %i(amd cor).include?(type) && (base.year.nil? && base.stage.nil?)
47
+ raise Errors::SupplementWithoutYearOrStageError,
48
+ "Cannot apply supplement to document without base identifieredition year or stage"
45
49
  end
46
50
  if stage
47
51
  @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)
@@ -50,14 +54,16 @@ module Pubid::Iso
50
54
  raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
51
55
  end
52
56
 
53
- if @stage.abbr == "FDIS" && type == "PAS"
57
+ if @stage.abbr == "FDIS" && type == :pas
54
58
  raise Errors::StageInvalidError, "PAS type cannot have FDIS stage"
55
59
  end
60
+ elsif iteration
61
+ raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration"
56
62
  end
63
+
57
64
  @iteration = iteration.to_i if iteration
58
65
  @supplement = supplement if supplement
59
66
  @joint_document = joint_document if joint_document
60
- @urn_stage = urn_stage if urn_stage
61
67
  @tctype = tctype if tctype
62
68
  @sctype = sctype.to_s if sctype
63
69
  @wgtype = wgtype.to_s if wgtype
@@ -66,6 +72,8 @@ module Pubid::Iso
66
72
  @wgnumber = wgnumber.to_s if wgnumber
67
73
  @dir = dir.to_s if dir
68
74
  @dirtype = dirtype.to_s if dirtype
75
+ @base = base if base
76
+ @type = type.is_a?(Type) ? type : Type.new(type) unless type.nil?
69
77
  end
70
78
 
71
79
  def self.parse_from_title(title)
@@ -78,6 +86,38 @@ module Pubid::Iso
78
86
  end
79
87
 
80
88
  class << self
89
+ def transform(params)
90
+ identifier_params = params.map do |k, v|
91
+ get_transformer_class.new.apply(k => v).to_a.first
92
+ end.to_h
93
+
94
+ supplement = nil
95
+
96
+ if identifier_params[:amendments]
97
+ identifier_params[:amendments].first.tap do |amendment|
98
+ supplement = new(type: :amd, number: amendment.number, year: amendment.year,
99
+ stage: amendment.stage, edition: amendment.edition,
100
+ iteration: amendment.iteration,
101
+ base: new(**identifier_params.dup.tap { |h| h.delete(:amendments); h.delete(:corrigendums) }))
102
+ end
103
+ end
104
+
105
+
106
+ if identifier_params[:corrigendums]
107
+ corrigendum = identifier_params[:corrigendums].first
108
+ return new(type: :cor, number: corrigendum.number, year: corrigendum.year,
109
+ stage: corrigendum.stage, edition: corrigendum.edition,
110
+ iteration: corrigendum.iteration,
111
+ base: supplement ? supplement :
112
+ new(**identifier_params.dup.tap { |h| h.delete(:amendments); h.delete(:corrigendums) }))
113
+ end
114
+
115
+
116
+ return supplement if supplement
117
+
118
+ new(**identifier_params)
119
+ end
120
+
81
121
  def get_amendment_class
82
122
  Pubid::Iso::Amendment
83
123
  end
@@ -102,10 +142,10 @@ module Pubid::Iso
102
142
  # Render URN identifier
103
143
  # @return [String] URN identifier
104
144
  def urn
105
- if (@amendments || @corrigendums) && !@edition
145
+ if %i(amd cor).include?(@type&.type) && (@base.base.nil? && !@base.edition || (!@base.base.nil? && !@base.base.edition))
106
146
  raise Errors::NoEditionError, "Base document must have edition"
107
147
  end
108
- (@tctype && Renderer::UrnTc || @type == "DIR" && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
148
+ (@tctype && Renderer::UrnTc || @type == :dir && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
109
149
  end
110
150
 
111
151
  # Renders pubid identifier
@@ -115,6 +155,7 @@ module Pubid::Iso
115
155
  # @param with_edition [Boolean] render identifier with edition
116
156
  # @param stage_format_long [Boolean] render with long or short stage format
117
157
  # @param format [:ref_num_short,:ref_num_long,:ref_dated,:ref_dated_long,:ref_undated,:ref_undated_long] create reference with specified format
158
+ # @param with_prf [Boolean] include PRF stage in output
118
159
  # Format options are:
119
160
  # :ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
120
161
  # :ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
@@ -162,16 +203,27 @@ module Pubid::Iso
162
203
  else
163
204
  if @tctype
164
205
  Renderer::Tc.new(get_params)
165
- elsif @type == "DIR"
206
+ elsif @type == :dir
166
207
  Renderer::Dir.new(get_params)
167
208
  else
168
209
  self.class.get_renderer_class.new(get_params)
169
210
  end
170
211
  end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
171
212
  stage_format_long: stage_format_long, with_prf: with_prf) +
172
- if @joint_document && @type != "DIR"
213
+ if @joint_document && @type != :dir
173
214
  "|#{@joint_document}"
174
215
  end.to_s
175
216
  end
217
+
218
+ # Return typed stage abbreviation, eg. "FDTR", "DIS", "TR"
219
+ def typed_stage_abbrev
220
+ renderer = self.class.get_renderer_class.new(get_params).prerender
221
+ renderer.prerendered_params[:type_stage]
222
+ end
223
+
224
+ # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
225
+ def typed_stage_name
226
+ "#{stage.short_name} #{type.to_s(:long)}"
227
+ end
176
228
  end
177
229
  end
@@ -1,60 +1,71 @@
1
1
  module Pubid::Iso::Renderer
2
2
  class Base < Pubid::Core::Renderer::Base
3
+ attr_accessor :prerendered_params
4
+
5
+ TYPE_VALUES = {
6
+ tr: "TR",
7
+ ts: "TS",
8
+ isp: "ISP",
9
+ guide: "Guide",
10
+ pas: "PAS",
11
+ dpas: "DPAS",
12
+ }.freeze
13
+
14
+ # Prerender parameters
15
+ def prerender(with_edition: true, **args)
16
+ @params[:type_stage] = @params.slice(:stage, :type) if @params[:stage] || @params[:type]
17
+ super
18
+ end
19
+
3
20
  # Render identifier
4
21
  # @param with_edition [Boolean] include edition in output
5
22
  # @see Pubid::Core::Renderer::Base for another options
6
23
  def render(with_edition: true, **args)
7
- params = prerender_params(@params,
8
- { with_edition: with_edition }.merge(args))
9
- # render empty string when the key is not exist
10
- params.default = ""
11
-
12
- render_identifier(params)
24
+ super(**args.merge({ with_edition: with_edition }))
13
25
  end
14
26
 
15
27
  def render_identifier(params)
16
- if @params[:type] && @params[:stage]
17
- if %w(DIS FDIS).include?(@params[:stage].abbr)
18
- render_base(params, "#{render_short_stage(@params[:stage].abbr)}#{@params[:type]}")
28
+ type_stage = if params[:type_stage] && !params[:type_stage].empty?
29
+ ((params[:copublisher] && !params[:copublisher].empty?) ? " " : "/") + params[:type_stage]
30
+ else
31
+ ""
32
+ end
33
+ render_base(params, type_stage) +
34
+ ("%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{edition}" % params)
35
+ end
36
+
37
+ def render_type_stage(values, opts, params)
38
+ # prerender stage and type before
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}"
19
47
  else
20
- if params[:copublisher] && !params[:copublisher].empty?
21
- render_base(params, "%{type}%{stage}" % params)
22
- else
23
- render_base(params, "%{stage}%{type}" % params)
24
- end
48
+ "#{stage} #{type}"
25
49
  end
26
50
  else
27
- render_base(params, "%{type}%{stage}" % params)
28
- end +
29
- "%{part}%{iteration}%{year}%{amendments}%{corrigendums}%{edition}%{language}" % params
51
+ # when only type or stage
52
+ "#{type}#{stage}"
53
+ end
30
54
  end
31
55
 
32
56
  def render_short_stage(stage)
33
- (params[:copublisher] ? " " : "/") +
34
- case stage
35
- when "DIS"
36
- "D"
37
- when "FDIS"
38
- "FD"
39
- end
40
- end
41
-
42
- def render_type(type, opts, params)
43
- if params[:copublisher] || (params[:stage] && params[:stage].abbr != "IS")
44
- " #{type}"
45
- else
46
- "/#{type}"
57
+ case stage
58
+ when "DIS"
59
+ "D"
60
+ when "FDIS"
61
+ "FD"
47
62
  end
48
63
  end
49
64
 
50
- def render_stage(stage, opts, params)
51
- return if (stage.abbr == "PRF" and !opts[:with_prf]) || stage.abbr == "IS"
65
+ def render_stage(stage, opts, _params)
66
+ return if stage.nil? || (stage.abbr == "PRF" and !opts[:with_prf]) || stage.abbr == "IS"
52
67
 
53
- if params[:copublisher]
54
- " #{stage.abbr}"
55
- else
56
- "/#{stage.abbr}"
57
- end
68
+ stage.abbr
58
69
  end
59
70
 
60
71
  def render_edition(edition, opts, _params)
@@ -2,7 +2,7 @@ module Pubid::Iso::Renderer
2
2
  class Dir < Base
3
3
 
4
4
  def render_identifier(params)
5
- res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}%{language}" % params)
5
+ res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}" % params)
6
6
 
7
7
  if params.key?(:joint_document)
8
8
  joint_params = prerender_params(params[:joint_document].get_params, {})
@@ -1,8 +1,16 @@
1
1
  module Pubid::Iso::Renderer
2
2
  class French < Base
3
+ def render_type_stage(values, opts, params)
4
+ if values[:type] == :guide
5
+ super(values.slice(:stage), opts, params)
6
+ else
7
+ super
8
+ end
9
+ end
10
+
3
11
  def render_identifier(params)
4
- if params[:type] == " Guide"
5
- params[:type] = ""
12
+ if params[:type] == :guide
13
+ params[:type] = nil
6
14
  "Guide #{super(params)}"
7
15
  else
8
16
  super
@@ -18,9 +18,17 @@ module Pubid::Iso::Renderer
18
18
  "ISP" => "ИСП",
19
19
  }.freeze
20
20
 
21
+ def render_type_stage(values, opts, params)
22
+ if values[:type] == :guide
23
+ super(values.slice(:stage), opts, params)
24
+ else
25
+ super
26
+ end
27
+ end
28
+
21
29
  def render_identifier(params)
22
- if params[:type] == " Guide"
23
- params[:type] = ""
30
+ if params[:type] == :guide
31
+ params[:type] = nil
24
32
  "Руководство #{super(params)}"
25
33
  else
26
34
  super
@@ -43,11 +51,7 @@ module Pubid::Iso::Renderer
43
51
  end
44
52
 
45
53
  def render_stage(stage, _opts, params)
46
- if params[:copublisher]
47
- " #{STAGE[stage.abbr]}"
48
- else
49
- "/#{STAGE[stage.abbr]}"
50
- end
54
+ STAGE[stage.abbr] unless stage.nil?
51
55
  end
52
56
 
53
57
  def render_corrigendums(corrigendums, _opts, _params)
@@ -10,13 +10,33 @@ module Pubid::Iso::Renderer
10
10
  PRF: 50,
11
11
  IS: 60 }.freeze
12
12
 
13
+ def prerender(with_edition: true, **args)
14
+ @params[:type_stage] = @params.slice(:stage, :type) if @params[:stage] || @params[:type]
15
+ super
16
+ end
17
+
18
+ # Render identifier
19
+ # @param with_edition [Boolean] include edition in output
20
+ # @see Pubid::Core::Renderer::Base for another options
21
+ def render(with_edition: true, **args)
22
+ super(**args.merge({ with_edition: with_edition }))
23
+ end
24
+
13
25
  def render_identifier(params)
14
26
  render_base(params) + "%{stage}"\
15
- "%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}%{language}" % params
27
+ "%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}" % params
16
28
  end
17
29
 
18
30
  def render_stage(stage, _opts, params)
19
31
  ":stage-#{stage.harmonized_code}"
20
32
  end
33
+
34
+ def render_type(type, _, _)
35
+ ":#{type.to_s.downcase}"
36
+ end
37
+
38
+ def render_year(year, _opts, _params)
39
+ ":#{year}"
40
+ end
21
41
  end
22
42
  end
@@ -13,6 +13,28 @@ module Pubid::Iso
13
13
  IS: "60.60" }.freeze
14
14
 
15
15
 
16
+ STAGE_NAMES = {
17
+ FDIS: "Final Draft International Standard",
18
+ DIS: "Draft International Standard",
19
+ WD: "Working Draft",
20
+ PWI: "Preliminary Work Item",
21
+ NP: "New Proposal",
22
+ CD: "Committee Draft",
23
+ 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
+ }.freeze
37
+
16
38
  # @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
17
39
  # @param harmonized_code [String, Float, HarmonizedStageCode]
18
40
  def initialize(abbr: nil, harmonized_code: nil)
@@ -70,5 +92,15 @@ module Pubid::Iso
70
92
  def ==(other)
71
93
  other&.harmonized_code == harmonized_code
72
94
  end
95
+
96
+ # Return stage name, eg. "Draft International Standard" for "DIS"
97
+ def name
98
+ STAGE_NAMES[abbr.to_sym]
99
+ end
100
+
101
+ # Return short stage name, eg. "Draft" for "DIS"
102
+ def short_name
103
+ STAGE_NAMES_SHORT[abbr.to_sym]
104
+ end
73
105
  end
74
106
  end
@@ -3,13 +3,14 @@ module Pubid::Iso
3
3
  attr_accessor :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
- # @param publisher [String] publisher, e.g. "ISO", "IEC"
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
10
  def initialize(stage: nil, publisher: nil, edition: nil, iteration: nil, **args)
11
11
  super(**args)
12
12
  @stage = stage.is_a?(Stage) ? stage : Stage.parse(stage) if stage
13
+ # for DIR identifiers only
13
14
  @publisher = publisher.to_s
14
15
  @edition = edition&.to_i
15
16
  @iteration = iteration&.to_i
@@ -44,21 +44,26 @@ module Pubid::Iso
44
44
 
45
45
  rule(type: simple(:type)) do
46
46
  russian_type = Renderer::Russian::TYPE.key(type.to_s)
47
- { type: russian_type&.to_s ||
48
- case type
49
- # XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
50
- when "GUIDE", "Руководства"
51
- "Guide"
52
- when "ТС"
53
- "TS"
54
- when "ТО"
55
- "TR"
56
- when "Directives Part", "Directives, Part", "Directives,"
57
- "DIR"
58
- else
59
- type
60
- end
61
- }
47
+ { type: Type.new(russian_type&.downcase&.to_sym ||
48
+ case type
49
+ # XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
50
+ when "GUIDE", "Guide", "Руководства"
51
+ :guide
52
+ when "ТС", "TS"
53
+ :ts
54
+ when "ТО", "TR"
55
+ :tr
56
+ when "Directives Part", "Directives, Part", "Directives,"
57
+ :dir
58
+ when "PAS"
59
+ :pas
60
+ when "DPAS"
61
+ :dpas
62
+ when "DIR"
63
+ :dir
64
+ else
65
+ type
66
+ end) }
62
67
  end
63
68
 
64
69
  rule(copublisher: simple(:copublisher)) do
@@ -0,0 +1,71 @@
1
+ module Pubid::Iso
2
+ class Type
3
+ attr_accessor :type
4
+
5
+ TYPE_NAMES = {
6
+ tr: {
7
+ long: "Technical Report",
8
+ short: "TR",
9
+ },
10
+ ts: {
11
+ long: "Technical Specification",
12
+ short: "TS",
13
+ },
14
+ is: {
15
+ long: "International Standard",
16
+ short: "IS",
17
+ },
18
+ pas: {
19
+ long: "Publicly Available Specification",
20
+ short: "PAS",
21
+ },
22
+ isp: {
23
+ long: "International Standardized Profiles",
24
+ short: "ISP",
25
+ },
26
+ guide: {
27
+ long: "Guide",
28
+ short: "Guide",
29
+ },
30
+ dir: {
31
+ long: "Directives",
32
+ short: "DIR",
33
+ },
34
+ dpas: {
35
+ long: "Publicly Available Specification Draft",
36
+ short: "DPAS",
37
+ },
38
+ cor: {
39
+ short: "Cor",
40
+ },
41
+ amd: {
42
+ short: "Amd",
43
+ },
44
+ }.freeze
45
+
46
+ # Create new type
47
+ # @param type [Symbol]
48
+ def initialize(type)
49
+ raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type)
50
+
51
+ @type = type
52
+ end
53
+
54
+ def self.parse(type_string)
55
+ TYPE_NAMES.each do |type, values|
56
+ return new(type) if values[:short] == type_string
57
+ end
58
+ raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type"
59
+ end
60
+
61
+ def to_s(format = :short)
62
+ TYPE_NAMES[type][format]
63
+ end
64
+
65
+ def ==(other)
66
+ return type == other if other.is_a?(Symbol)
67
+
68
+ type == other.type
69
+ end
70
+ end
71
+ end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.2.1".freeze
3
+ VERSION = "0.2.2".freeze
4
4
  end
5
5
  end
data/lib/pubid/iso.rb CHANGED
@@ -11,6 +11,7 @@ end
11
11
  require "pubid-core"
12
12
  require_relative "iso/errors"
13
13
  require_relative "iso/stage"
14
+ require_relative "iso/type"
14
15
  require_relative "iso/harmonized_stage_code"
15
16
  require_relative "iso/parser"
16
17
  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.2.1
4
+ version: 0.2.2
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-09-29 00:00:00.000000000 Z
11
+ date: 2022-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -138,6 +138,7 @@ files:
138
138
  - lib/pubid/iso/stage.rb
139
139
  - lib/pubid/iso/supplement.rb
140
140
  - lib/pubid/iso/transformer.rb
141
+ - lib/pubid/iso/type.rb
141
142
  - lib/pubid/iso/version.rb
142
143
  homepage: https://github.com/metanorma/pubid-iso
143
144
  licenses: