pubid-iso 0.1.12 → 0.2.2
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 +137 -7
- data/lib/pubid/iso/errors.rb +7 -2
- data/lib/pubid/iso/harmonized_stage_code.rb +21 -8
- data/lib/pubid/iso/identifier.rb +119 -36
- data/lib/pubid/iso/renderer/base.rb +46 -24
- data/lib/pubid/iso/renderer/french.rb +10 -2
- data/lib/pubid/iso/renderer/russian.rb +11 -7
- data/lib/pubid/iso/renderer/urn.rb +21 -1
- data/lib/pubid/iso/stage.rb +84 -11
- data/lib/pubid/iso/supplement.rb +4 -3
- data/lib/pubid/iso/transformer.rb +20 -15
- data/lib/pubid/iso/type.rb +71 -0
- data/lib/pubid/iso/version.rb +1 -1
- data/lib/pubid/iso.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93b04a876f8ee73e80af8c49af1efc223d1b63a4d8a6b6b679a114d77befcc73
|
4
|
+
data.tar.gz: c39834a8f5290dc71d8bbcd79801e3313c1c888715040a7d67fbbda116d7572e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bef9b0e5791702f0bcf3c291639d78cb3cd0319d94345b953a0e3608b22b895f019ee75bdcc742c78007281392be6cd2d60081fbe0a81cec9109de59fc31005
|
7
|
+
data.tar.gz: eb469ae1abc30c718355173cab16ee1b80cf1386adc1e65fbd5ba96b493f7c7ee9abdd0cab0612ec34159214524465d8323007ba3fd344a0ec3d2b611d6718de
|
data/README.adoc
CHANGED
@@ -12,8 +12,7 @@ identifiers.
|
|
12
12
|
. generate language specific PubID
|
13
13
|
. generate dated vs undated PubIDs
|
14
14
|
|
15
|
-
=== Usage
|
16
|
-
|
15
|
+
=== Usage samples
|
17
16
|
|
18
17
|
[source,ruby]
|
19
18
|
----
|
@@ -25,12 +24,143 @@ pubid.to_s
|
|
25
24
|
=> "ISO 1234"
|
26
25
|
----
|
27
26
|
|
28
|
-
|
27
|
+
==== With coopublisher
|
28
|
+
|
29
|
+
[source,ruby]
|
30
|
+
----
|
31
|
+
pubid = Pubid::Iso::Identifier.new(publisher: "ISO", copublisher: "IEC", number: 123)
|
32
|
+
pubid.to_s
|
33
|
+
|
34
|
+
=> "ISO/IEC 1234"
|
35
|
+
----
|
36
|
+
|
37
|
+
==== With document type
|
38
|
+
|
39
|
+
[source,ruby]
|
40
|
+
----
|
41
|
+
pubid = Pubid::Iso::Identifier.new(publisher: "ISO", type: "TR", number: 123)
|
42
|
+
pubid.to_s
|
43
|
+
|
44
|
+
=> "ISO/TR 1234"
|
45
|
+
----
|
46
|
+
|
47
|
+
==== With stage
|
48
|
+
|
49
|
+
[source,ruby]
|
50
|
+
----
|
51
|
+
pubid = Pubid::Iso::Identifier.new(publisher: "ISO", stage: :WD, number: 123)
|
52
|
+
pubid.to_s
|
53
|
+
|
54
|
+
=> "ISO/WD 1234"
|
55
|
+
----
|
56
|
+
|
57
|
+
==== With part number
|
58
|
+
|
59
|
+
[source,ruby]
|
60
|
+
----
|
61
|
+
pubid = Pubid::Iso::Identifier.new(publisher: "ISO", number: 123, part: 1)
|
62
|
+
pubid.to_s
|
63
|
+
|
64
|
+
=> "ISO 1234-1"
|
65
|
+
----
|
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
|
+
|
92
|
+
==== Using format options
|
93
|
+
[source,ruby]
|
94
|
+
----
|
95
|
+
> pubid = Pubid::Iso::Identifier.new(
|
96
|
+
number: "8601",
|
97
|
+
part: "1",
|
98
|
+
year: 2019,
|
99
|
+
edition: 1,
|
100
|
+
amendment: {number: "1", year: "2021", stage: "DIS"}
|
101
|
+
)
|
102
|
+
> pubid.to_s(:ref_num_short)
|
103
|
+
=> "ISO 8601-1:2019/DAM 1:2021(E)"
|
104
|
+
> pubid.to_s(:ref_num_long)
|
105
|
+
=> "ISO 8601-1:2019/DAmd 1:2021(en)"
|
106
|
+
> pubid.to_s(:ref_dated)
|
107
|
+
=> "ISO 8601-1:2019/DAM 1:2021"
|
108
|
+
> pubid.to_s(:ref_dated_long)
|
109
|
+
=> "ISO 8601-1:2019/DAmd 1:2021"
|
110
|
+
> pubid.to_s(:ref_undated)
|
111
|
+
=> "ISO 8601-1:2019/DAM 1"
|
112
|
+
> pubid.to_s(:ref_undated_long)
|
113
|
+
=> "ISO 8601-1:2019/DAmd 1"
|
114
|
+
----
|
115
|
+
|
116
|
+
==== Using language specific rendering
|
117
|
+
[source,ruby]
|
118
|
+
----
|
119
|
+
> pubid = Pubid::Iso::Identifier.parse("ISO/FDIS 26000:2010(ru)")
|
120
|
+
> pubid.to_s(format: :ref_num_long, lang: :russian)
|
121
|
+
=> "ИСО/ОПМС 26000:2010(ru)"
|
122
|
+
> pubid = Pubid::Iso::Identifier.parse("ISO/IEC Guide 71:2001(fr)")
|
123
|
+
> pubid.to_s(format: :ref_num_long, lang: :french)
|
124
|
+
=> "Guide ISO/CEI 71:2001(fr)"
|
125
|
+
----
|
126
|
+
|
127
|
+
==== Rendering URN identifier
|
128
|
+
[source,ruby]
|
129
|
+
----
|
130
|
+
> pubid = Pubid::Iso::Identifier.new(
|
131
|
+
number: "8601",
|
132
|
+
part: "1",
|
133
|
+
year: 2019,
|
134
|
+
edition: 1,
|
135
|
+
amendments: {number: "1", year: "2021", stage: "DIS"}
|
136
|
+
)
|
137
|
+
> pubid.urn
|
138
|
+
=> "urn:iso:std:iso:8601:-1:ed-1:amd:2021:v1"
|
139
|
+
----
|
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
|
+
----
|
29
162
|
|
30
|
-
|
31
|
-
`corrigendums`, `stage`, `substage`, `iteration`, `supplements`, `amendment_stage`, `corrigendum_stage`,
|
32
|
-
`joint_document`, `tctype`, `sctype`, `wgtype`, `tcnumber`, `scnumber`, `wgnumber`, `urn_stage`,
|
33
|
-
`dir`, `dirtype`, `supplement`
|
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.
|
34
164
|
|
35
165
|
== Elements of the PubID
|
36
166
|
|
data/lib/pubid/iso/errors.rb
CHANGED
@@ -3,9 +3,14 @@ module Pubid::Iso
|
|
3
3
|
class ParseError < StandardError; end
|
4
4
|
class PublishedIterationError < StandardError; end
|
5
5
|
class HarmonizedStageCodeInvalidError < StandardError; end
|
6
|
-
class
|
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
|
11
|
+
class SupplementWithoutYearOrStageError < StandardError; end
|
12
|
+
class NoEditionError < StandardError; end
|
13
|
+
class WrongTypeError < StandardError; end
|
14
|
+
class ParseTypeError < StandardError; end
|
10
15
|
end
|
11
16
|
end
|
@@ -53,22 +53,36 @@ module Pubid::Iso
|
|
53
53
|
}
|
54
54
|
|
55
55
|
STAGES_NAMES = {
|
56
|
-
|
57
|
-
|
56
|
+
preliminary: "00",
|
57
|
+
proposal: "10",
|
58
|
+
preparatory: "20",
|
59
|
+
committee: "30",
|
60
|
+
enquiry: "40",
|
61
|
+
approval: "50",
|
62
|
+
publication: "60",
|
63
|
+
review: "90",
|
64
|
+
withdrawal: "95",
|
65
|
+
}.freeze
|
58
66
|
|
59
67
|
SUBSTAGES_NAMES = {
|
60
|
-
registration: "00"
|
61
|
-
|
68
|
+
registration: "00",
|
69
|
+
start_of_main_action: "20",
|
70
|
+
completion_of_main_action: "60",
|
71
|
+
repeat_an_earlier_phase: "92",
|
72
|
+
repeat_current_phase: "93",
|
73
|
+
abandon: "98",
|
74
|
+
proceed: "99",
|
75
|
+
}.freeze
|
62
76
|
|
63
|
-
def initialize(stage, substage =
|
77
|
+
def initialize(stage, substage = "00")
|
64
78
|
# when stage is stage name
|
65
79
|
if STAGES_NAMES.key?(stage)
|
66
80
|
@stage = STAGES_NAMES[stage]
|
67
81
|
@substage = SUBSTAGES_NAMES[substage]
|
68
82
|
else
|
69
83
|
# stage is number
|
70
|
-
validate_stage(stage, substage)
|
71
84
|
@stage, @substage = stage, substage
|
85
|
+
validate_stage(stage, substage)
|
72
86
|
end
|
73
87
|
end
|
74
88
|
|
@@ -77,8 +91,7 @@ module Pubid::Iso
|
|
77
91
|
raise Errors::HarmonizedStageCodeInvalidError if Integer(stage).nil?
|
78
92
|
|
79
93
|
# raise an error when substage wrong
|
80
|
-
raise Errors::HarmonizedStageCodeInvalidError
|
81
|
-
# raise Errors::HarmonizedStageCodeNotValidError if stage.to_i
|
94
|
+
raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(to_s)
|
82
95
|
end
|
83
96
|
|
84
97
|
def to_s
|
data/lib/pubid/iso/identifier.rb
CHANGED
@@ -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
|
-
:
|
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
|
-
# @param stage [Stage] stage
|
14
|
-
# @param urn_stage [Float] numeric stage for URN rendering
|
14
|
+
# @param stage [Stage, Symbol, String] stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD)
|
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,33 +22,48 @@ 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)
|
27
|
+
# @raise [Errors::SupplementWithoutYearOrStageError] when trying to apply
|
28
|
+
# supplement to the document without edition year or stage
|
29
|
+
# @raise [Errors::IsStageIterationError] when trying to apply iteration
|
30
|
+
# to document with IS stage
|
31
|
+
# @raise [Errors::IterationWithoutStageError] when trying to applu iteration
|
32
|
+
# to document without stage
|
25
33
|
# @see Supplement
|
26
34
|
# @see Identifier
|
27
35
|
# @see Pubid::Core::Identifier
|
28
36
|
# @see Parser
|
29
37
|
#
|
30
38
|
def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
|
31
|
-
joint_document: nil,
|
32
|
-
tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
|
39
|
+
joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
|
33
40
|
scnumber: nil, wgnumber:nil,
|
34
41
|
dir: nil, dirtype: nil, year: nil, amendments: nil,
|
35
|
-
corrigendums: nil, **opts)
|
42
|
+
corrigendums: nil, type: nil, base: nil, **opts)
|
36
43
|
super(**opts.merge(number: number, publisher: publisher, year: year,
|
37
44
|
amendments: amendments, corrigendums: corrigendums))
|
38
45
|
|
39
|
-
if (
|
40
|
-
raise Errors::
|
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"
|
41
49
|
end
|
42
50
|
if stage
|
43
|
-
@stage =
|
51
|
+
@stage = stage.is_a?(Stage) ? stage : Stage.parse(stage)
|
52
|
+
|
44
53
|
if @stage.abbr == "IS" && iteration
|
45
54
|
raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
|
46
55
|
end
|
56
|
+
|
57
|
+
if @stage.abbr == "FDIS" && type == :pas
|
58
|
+
raise Errors::StageInvalidError, "PAS type cannot have FDIS stage"
|
59
|
+
end
|
60
|
+
elsif iteration
|
61
|
+
raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration"
|
47
62
|
end
|
63
|
+
|
48
64
|
@iteration = iteration.to_i if iteration
|
49
65
|
@supplement = supplement if supplement
|
50
66
|
@joint_document = joint_document if joint_document
|
51
|
-
@urn_stage = urn_stage if urn_stage
|
52
67
|
@tctype = tctype if tctype
|
53
68
|
@sctype = sctype.to_s if sctype
|
54
69
|
@wgtype = wgtype.to_s if wgtype
|
@@ -57,6 +72,8 @@ module Pubid::Iso
|
|
57
72
|
@wgnumber = wgnumber.to_s if wgnumber
|
58
73
|
@dir = dir.to_s if dir
|
59
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?
|
60
77
|
end
|
61
78
|
|
62
79
|
def self.parse_from_title(title)
|
@@ -69,6 +86,38 @@ module Pubid::Iso
|
|
69
86
|
end
|
70
87
|
|
71
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
|
+
|
72
121
|
def get_amendment_class
|
73
122
|
Pubid::Iso::Amendment
|
74
123
|
end
|
@@ -90,39 +139,62 @@ module Pubid::Iso
|
|
90
139
|
end
|
91
140
|
end
|
92
141
|
|
142
|
+
# Render URN identifier
|
143
|
+
# @return [String] URN identifier
|
93
144
|
def urn
|
94
|
-
(@
|
95
|
-
|
96
|
-
|
97
|
-
def formatted(format)
|
98
|
-
case format
|
99
|
-
when :ref_num_short
|
100
|
-
to_s(with_language_code: :single, stage_format_long: false)
|
101
|
-
when :ref_num_long
|
102
|
-
to_s(with_language_code: :iso, stage_format_long: true)
|
103
|
-
when :ref_dated
|
104
|
-
to_s(with_language_code: :none, stage_format_long: false)
|
105
|
-
when :ref_dated_long
|
106
|
-
to_s(with_language_code: :none, stage_format_long: true)
|
107
|
-
when :ref_undated
|
108
|
-
to_s(with_language_code: :none, stage_format_long: false, with_date: false)
|
109
|
-
when :ref_undated_long
|
110
|
-
to_s(with_language_code: :none, stage_format_long: true, with_date: false)
|
111
|
-
else
|
112
|
-
raise Errors::WrongFormat, "#{format} is not available"
|
145
|
+
if %i(amd cor).include?(@type&.type) && (@base.base.nil? && !@base.edition || (!@base.base.nil? && !@base.base.edition))
|
146
|
+
raise Errors::NoEditionError, "Base document must have edition"
|
113
147
|
end
|
148
|
+
(@tctype && Renderer::UrnTc || @type == :dir && Renderer::UrnDir || Pubid::Iso::Renderer::Urn).new(get_params).render
|
114
149
|
end
|
115
150
|
|
116
151
|
# Renders pubid identifier
|
117
152
|
#
|
118
153
|
# @param lang [:french,:russian] use language specific renderer
|
119
154
|
# @param with_date [Boolean] render identifier with date
|
120
|
-
# @param with_language_code [:iso,:single] use iso format or single language code for rendering
|
121
155
|
# @param with_edition [Boolean] render identifier with edition
|
122
156
|
# @param stage_format_long [Boolean] render with long or short stage format
|
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
|
159
|
+
# Format options are:
|
160
|
+
# :ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
|
161
|
+
# :ref_num_long -- instance reference number long: 2 letter language code + long form (DAmd) + dated
|
162
|
+
# :ref_dated -- reference dated: no language code + short form (DAM) + dated
|
163
|
+
# :ref_dated_long -- reference dated long: no language code + short form (DAM) + dated
|
164
|
+
# :ref_undated -- reference undated: no language code + short form (DAM) + undated
|
165
|
+
# :ref_undated_long -- reference undated long: 1 letter language code + long form (DAmd) + undated
|
123
166
|
# @return [String] pubid identifier
|
124
|
-
def to_s(lang: nil, with_date: true,
|
125
|
-
with_edition:
|
167
|
+
def to_s(lang: nil, with_date: true,
|
168
|
+
with_edition: false, with_prf: false,
|
169
|
+
format: :ref_dated_long)
|
170
|
+
with_language_code = nil
|
171
|
+
stage_format_long = nil
|
172
|
+
if format
|
173
|
+
case format
|
174
|
+
when :ref_num_short
|
175
|
+
with_language_code = :single
|
176
|
+
stage_format_long = false
|
177
|
+
when :ref_num_long
|
178
|
+
with_language_code = :iso
|
179
|
+
stage_format_long = true
|
180
|
+
when :ref_dated
|
181
|
+
with_language_code = :none
|
182
|
+
stage_format_long = false
|
183
|
+
when :ref_dated_long
|
184
|
+
with_language_code = :none
|
185
|
+
stage_format_long = true
|
186
|
+
when :ref_undated
|
187
|
+
with_language_code = :none
|
188
|
+
stage_format_long = false
|
189
|
+
with_date = false
|
190
|
+
when :ref_undated_long
|
191
|
+
with_language_code = :none
|
192
|
+
stage_format_long = true
|
193
|
+
with_date = false
|
194
|
+
else
|
195
|
+
raise Errors::WrongFormat, "#{format} is not available"
|
196
|
+
end
|
197
|
+
end
|
126
198
|
case lang
|
127
199
|
when :french
|
128
200
|
Renderer::French.new(get_params)
|
@@ -131,16 +203,27 @@ module Pubid::Iso
|
|
131
203
|
else
|
132
204
|
if @tctype
|
133
205
|
Renderer::Tc.new(get_params)
|
134
|
-
elsif @type ==
|
206
|
+
elsif @type == :dir
|
135
207
|
Renderer::Dir.new(get_params)
|
136
208
|
else
|
137
209
|
self.class.get_renderer_class.new(get_params)
|
138
210
|
end
|
139
211
|
end.render(with_date: with_date, with_language_code: with_language_code, with_edition: with_edition,
|
140
|
-
stage_format_long: stage_format_long) +
|
141
|
-
if @joint_document && @type !=
|
212
|
+
stage_format_long: stage_format_long, with_prf: with_prf) +
|
213
|
+
if @joint_document && @type != :dir
|
142
214
|
"|#{@joint_document}"
|
143
215
|
end.to_s
|
144
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
|
145
228
|
end
|
146
229
|
end
|
@@ -1,24 +1,56 @@
|
|
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
|
-
|
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
|
17
|
-
|
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}"
|
47
|
+
else
|
48
|
+
"#{stage} #{type}"
|
49
|
+
end
|
18
50
|
else
|
19
|
-
|
20
|
-
|
21
|
-
|
51
|
+
# when only type or stage
|
52
|
+
"#{type}#{stage}"
|
53
|
+
end
|
22
54
|
end
|
23
55
|
|
24
56
|
def render_short_stage(stage)
|
@@ -30,20 +62,10 @@ module Pubid::Iso::Renderer
|
|
30
62
|
end
|
31
63
|
end
|
32
64
|
|
33
|
-
def
|
34
|
-
if
|
35
|
-
" #{type}"
|
36
|
-
else
|
37
|
-
"/#{type}"
|
38
|
-
end
|
39
|
-
end
|
65
|
+
def render_stage(stage, opts, _params)
|
66
|
+
return if stage.nil? || (stage.abbr == "PRF" and !opts[:with_prf]) || stage.abbr == "IS"
|
40
67
|
|
41
|
-
|
42
|
-
if params[:copublisher]
|
43
|
-
" #{stage.abbr}"
|
44
|
-
else
|
45
|
-
"/#{stage.abbr}"
|
46
|
-
end
|
68
|
+
stage.abbr
|
47
69
|
end
|
48
70
|
|
49
71
|
def render_edition(edition, opts, _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] ==
|
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] ==
|
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
|
-
|
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}
|
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
|
data/lib/pubid/iso/stage.rb
CHANGED
@@ -4,30 +4,103 @@ module Pubid::Iso
|
|
4
4
|
|
5
5
|
STAGES = { PWI: "00.00",
|
6
6
|
NP: "10.00",
|
7
|
-
AWI:
|
8
|
-
WD:
|
7
|
+
AWI: %w[20.00 10.99],
|
8
|
+
WD: %w[20.20 20.60 20.98 20.99],
|
9
9
|
CD: "30.00",
|
10
10
|
DIS: "40.00",
|
11
11
|
FDIS: "50.00",
|
12
|
-
PRF: "
|
13
|
-
IS: "60.
|
12
|
+
PRF: "60.00",
|
13
|
+
IS: "60.60" }.freeze
|
14
|
+
|
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
|
14
37
|
|
15
38
|
# @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
|
16
|
-
# @param harmonized_code [HarmonizedStageCode]
|
39
|
+
# @param harmonized_code [String, Float, HarmonizedStageCode]
|
17
40
|
def initialize(abbr: nil, harmonized_code: nil)
|
18
|
-
@abbr = abbr
|
19
|
-
@harmonized_code = harmonized_code
|
41
|
+
@abbr = abbr&.to_s
|
20
42
|
|
21
43
|
if harmonized_code
|
22
|
-
|
23
|
-
|
44
|
+
@harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
|
45
|
+
harmonized_code
|
46
|
+
else
|
47
|
+
HarmonizedStageCode.new(*harmonized_code.to_s.split("."))
|
48
|
+
end
|
49
|
+
@abbr ||= lookup_abbr(@harmonized_code.to_s) || lookup_abbr("#{@harmonized_code.stage}.00")
|
24
50
|
end
|
25
51
|
|
26
52
|
if abbr
|
27
|
-
raise Errors::
|
53
|
+
raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_sym)
|
54
|
+
|
55
|
+
@harmonized_code ||= HarmonizedStageCode.new(*lookup_code(abbr).split("."))
|
56
|
+
end
|
57
|
+
end
|
28
58
|
|
29
|
-
|
59
|
+
# Lookup for abbreviated code by numeric stage code
|
60
|
+
# @param lookup_code [String] stage code, e.g. "00.00", "20.20"
|
61
|
+
def lookup_abbr(lookup_code)
|
62
|
+
STAGES.each do |abbr, codes|
|
63
|
+
case codes
|
64
|
+
when Array
|
65
|
+
codes.each do |code|
|
66
|
+
return abbr if code == lookup_code
|
67
|
+
end
|
68
|
+
when lookup_code
|
69
|
+
return abbr
|
70
|
+
end
|
30
71
|
end
|
72
|
+
|
73
|
+
nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def lookup_code(lookup_abbr)
|
77
|
+
code = STAGES[lookup_abbr.to_sym]
|
78
|
+
code.is_a?(Array) ? code.first : code
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.parse(stage)
|
82
|
+
if /\A[\d.]+\z/.match?(stage)
|
83
|
+
Stage.new(harmonized_code: stage)
|
84
|
+
else
|
85
|
+
raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String)
|
86
|
+
|
87
|
+
Stage.new(abbr: stage)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# Compares one stage with another
|
92
|
+
def ==(other)
|
93
|
+
other&.harmonized_code == harmonized_code
|
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]
|
31
104
|
end
|
32
105
|
end
|
33
106
|
end
|
data/lib/pubid/iso/supplement.rb
CHANGED
@@ -2,14 +2,15 @@ module Pubid::Iso
|
|
2
2
|
class Supplement < Pubid::Core::Supplement
|
3
3
|
attr_accessor :stage, :publisher, :edition, :iteration
|
4
4
|
|
5
|
-
# @param stage [Stage] stage, e.g. "PWI", "NP"
|
6
|
-
# @param publisher [String] publisher, e.g. "ISO", "IEC"
|
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" (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
|
-
@stage =
|
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&.
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
data/lib/pubid/iso/version.rb
CHANGED
data/lib/pubid/iso.rb
CHANGED
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.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-
|
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:
|