pubid-iso 0.1.7 → 0.1.8
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 +0 -1
- data/lib/pubid/iso/corrigendum.rb +0 -1
- data/lib/pubid/iso/identifier.rb +39 -159
- data/lib/pubid/iso/parser.rb +28 -56
- data/lib/pubid/iso/renderer/dir.rb +33 -0
- data/lib/pubid/iso/renderer/french.rb +24 -0
- data/lib/pubid/iso/renderer/russian.rb +61 -0
- data/lib/pubid/iso/renderer/tc.rb +30 -0
- data/lib/pubid/iso/renderer/urn-dir.rb +35 -0
- data/lib/pubid/iso/renderer/urn-tc.rb +24 -0
- data/lib/pubid/iso/supplement.rb +10 -23
- data/lib/pubid/iso/transformer.rb +36 -9
- data/lib/pubid/iso/version.rb +1 -1
- data/lib/pubid/iso.rb +7 -3
- metadata +22 -5
- data/lib/pubid/iso/identifier/french.rb +0 -24
- data/lib/pubid/iso/identifier/russian.rb +0 -49
- data/lib/pubid/iso/urn.rb +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 583ae9e428707932e9c3bc08eb9b726ea3e1f90dbf8c9fdba05e7b12e98302a2
|
4
|
+
data.tar.gz: 2fc723a9027e6bd49c6643b07618dcb68d38295846488c2f34513260f145ca57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f623fd9c0dadc20861cfed1c9a8ed788f5a5122d50835913689c69df5e67b1671141f7ad09af16e1bfccc186bc7c6144104f44c911561c910dea7d9c5b6d715e
|
7
|
+
data.tar.gz: e48de733a3ade64447d41ddd29b170eb13c1c60281b4f1d5cc27882f64a710706e9df87c001a827fd0ccc082843b882b7c78c69b5ff9a57649c1234a5f3af66f
|
data/lib/pubid/iso/amendment.rb
CHANGED
data/lib/pubid/iso/identifier.rb
CHANGED
@@ -1,190 +1,70 @@
|
|
1
1
|
module Pubid::Iso
|
2
|
-
class Identifier
|
3
|
-
attr_accessor :
|
4
|
-
:
|
5
|
-
:amendment, :amendment_version, :amendment_number,
|
6
|
-
:corrigendum, :corrigendum_version, :corrigendum_number,
|
2
|
+
class Identifier < Pubid::Core::Identifier
|
3
|
+
attr_accessor :stage, :substage,
|
4
|
+
:iteration, :supplements,
|
7
5
|
:amendment_stage, :corrigendum_stage, :joint_document,
|
8
6
|
:tctype, :sctype, :wgtype, :tcnumber, :scnumber, :wgnumber,
|
9
|
-
:urn_stage
|
7
|
+
:urn_stage, :dir, :dirtype, :supplement
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
def initialize(amendment: nil, amendment_number: nil, amendment_version: nil,
|
19
|
-
amendment_stage: nil,
|
20
|
-
corrigendum: nil, corrigendum_number: nil, corrigendum_version: nil,
|
21
|
-
corrigendum_stage: nil, **opts)
|
22
|
-
if amendment_version
|
23
|
-
@amendment = Amendment.new(number: amendment_number,
|
24
|
-
version: amendment_version,
|
25
|
-
stage: amendment_stage)
|
26
|
-
end
|
27
|
-
if corrigendum_version
|
28
|
-
@corrigendum = Corrigendum.new(number: corrigendum_number,
|
29
|
-
version: corrigendum_version,
|
30
|
-
stage: corrigendum_stage)
|
31
|
-
end
|
32
|
-
|
33
|
-
opts.each { |key, value| send("#{key}=", value.is_a?(Array) && value || value.to_s) }
|
34
|
-
end
|
35
|
-
|
36
|
-
def get_params
|
37
|
-
instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
|
38
|
-
end
|
39
|
-
|
40
|
-
def urn
|
41
|
-
Urn.new(**get_params)
|
9
|
+
def initialize(**opts)
|
10
|
+
super
|
11
|
+
# if supplement
|
12
|
+
# @supplement = Supplement.new(number: supplement[:year],
|
13
|
+
# publisher: supplement[:publisher],
|
14
|
+
# edition: supplement[:edition])
|
15
|
+
# end
|
42
16
|
end
|
43
17
|
|
44
18
|
def self.parse_from_title(title)
|
45
19
|
title.split.reverse.inject(title) do |acc, part|
|
46
20
|
return parse(acc)
|
47
|
-
rescue Pubid::
|
21
|
+
rescue Pubid::Core::Errors::ParseError
|
48
22
|
# delete parts from the title until it's parseable
|
49
23
|
acc.reverse.sub(part.reverse, "").reverse.strip
|
50
24
|
end
|
51
25
|
end
|
52
26
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# otherwise it's hash
|
57
|
-
if params.is_a?(Array)
|
58
|
-
new(
|
59
|
-
**(
|
60
|
-
params.inject({}) do |r, i|
|
61
|
-
result = r
|
62
|
-
i.map {|k, v| Transformer.new.apply(k => v).to_a.first }.each do |k, v|
|
63
|
-
result = result.merge(k => r.key?(k) ? [v, r[k]] : v)
|
64
|
-
end
|
65
|
-
result
|
66
|
-
end
|
67
|
-
)
|
68
|
-
)
|
69
|
-
else
|
70
|
-
new(**params.map do |k, v|
|
71
|
-
Transformer.new.apply(k => v).to_a.first
|
72
|
-
end.to_h)
|
27
|
+
class << self
|
28
|
+
def get_amendment_class
|
29
|
+
Pubid::Iso::Amendment
|
73
30
|
end
|
74
|
-
# merge values repeating keys into array (for copublishers)
|
75
31
|
|
76
|
-
|
77
|
-
|
78
|
-
rescue Parslet::ParseFailed => failure
|
79
|
-
raise Pubid::Iso::Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
80
|
-
end
|
81
|
-
|
82
|
-
def to_s(lang: nil, with_date: true, with_language_code: :iso)
|
83
|
-
# @pubid_language = lang
|
84
|
-
case lang
|
85
|
-
when :french
|
86
|
-
French.new(**get_params)
|
87
|
-
when :russian
|
88
|
-
Russian.new(**get_params)
|
89
|
-
else
|
90
|
-
self
|
91
|
-
end.identifier(with_date, with_language_code) + (@joint_document && "|#{@joint_document}").to_s
|
92
|
-
end
|
93
|
-
|
94
|
-
def identifier(with_date, with_language_code)
|
95
|
-
if @tctype
|
96
|
-
"#{originator} #{tctype} #{tcnumber}#{sctype}#{wgtype} N#{number}"
|
97
|
-
else
|
98
|
-
"#{originator}#{type}#{stage} #{number}#{part}#{iteration}"\
|
99
|
-
"#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
|
32
|
+
def get_corrigendum_class
|
33
|
+
Pubid::Iso::Corrigendum
|
100
34
|
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def tctype
|
104
|
-
return @tctype.join("/") if @tctype.is_a?(Array)
|
105
|
-
|
106
|
-
@tctype
|
107
|
-
end
|
108
35
|
|
109
|
-
|
110
|
-
|
111
|
-
def sctype
|
112
|
-
return unless @sctype
|
113
|
-
|
114
|
-
if @wgnumber || !@wgtype
|
115
|
-
"/#{@sctype} #{@scnumber}"
|
116
|
-
else
|
117
|
-
"/#{@sctype}"
|
36
|
+
def get_parser_class
|
37
|
+
Parser
|
118
38
|
end
|
119
|
-
end
|
120
39
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
if @wgnumber
|
125
|
-
"/#{@wgtype} #{@wgnumber}"
|
126
|
-
else
|
127
|
-
"/#{@wgtype} #{@scnumber}"
|
40
|
+
def get_transformer_class
|
41
|
+
Transformer
|
128
42
|
end
|
129
43
|
end
|
130
44
|
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
(!@copublisher.is_a?(Array) && [@copublisher]) || @copublisher
|
45
|
+
def urn
|
46
|
+
(@tctype && Renderer::UrnTc || @dir && Renderer::UrnDir || Pubid::Core::Renderer::Urn).new(get_params).render
|
135
47
|
end
|
136
48
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
49
|
+
def to_s(lang: nil, with_date: true, with_language_code: :iso)
|
50
|
+
# @pubid_language = lang
|
51
|
+
case lang
|
52
|
+
when :french
|
53
|
+
Renderer::French.new(get_params)
|
54
|
+
when :russian
|
55
|
+
Renderer::Russian.new(get_params)
|
144
56
|
else
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
def stage
|
150
|
-
"#{(@copublisher && ' ') || '/'}#{@stage}" if @stage
|
151
|
-
end
|
152
|
-
|
153
|
-
def part
|
154
|
-
"-#{@part}" if @part
|
155
|
-
end
|
156
|
-
|
157
|
-
def rendered_year
|
158
|
-
@year && ":#{@year}"
|
159
|
-
end
|
160
|
-
|
161
|
-
def type
|
162
|
-
"#{(@copublisher && ' ') || '/'}#{@type}" if @type
|
163
|
-
end
|
164
|
-
|
165
|
-
def edition
|
166
|
-
" ED#{@edition}" if @edition
|
167
|
-
end
|
168
|
-
|
169
|
-
def iteration
|
170
|
-
".#{@iteration}" if @iteration
|
171
|
-
end
|
172
|
-
|
173
|
-
def supplements
|
174
|
-
result = @amendment&.version && @amendment.render_pubid || ""
|
175
|
-
|
176
|
-
result + (@corrigendum&.version && @corrigendum.render_pubid || "")
|
177
|
-
end
|
178
|
-
|
179
|
-
def language(with_language_code = :iso)
|
180
|
-
if @language
|
181
|
-
if with_language_code == :single
|
182
|
-
"(#{LANGUAGES[@language]})"
|
57
|
+
if @tctype
|
58
|
+
Renderer::Tc.new(get_params)
|
59
|
+
elsif @dir
|
60
|
+
Renderer::Dir.new(get_params)
|
183
61
|
else
|
184
|
-
|
62
|
+
self.class.get_renderer_class.new(get_params)
|
185
63
|
end
|
186
|
-
end
|
64
|
+
end.render(with_date: with_date, with_language_code: with_language_code) +
|
65
|
+
if @joint_document && !@dir
|
66
|
+
"|#{@joint_document}"
|
67
|
+
end.to_s
|
187
68
|
end
|
188
|
-
|
189
69
|
end
|
190
70
|
end
|
data/lib/pubid/iso/parser.rb
CHANGED
@@ -1,31 +1,7 @@
|
|
1
|
-
# from https://github.com/relaton/relaton-iso/issues/47#issuecomment-512251416
|
2
|
-
# ISO {num}-{docpart}:{year} - docpart and year are optional. docpart is [\w-]+
|
3
|
-
# ISO/{stage} {num}-{docpart}:{year} or ISO/{subprefix} {stage} {num}:{year} - stages are WD, CD, DIS, FDIS, AWI
|
4
|
-
# ISO/{subprefix} {stage} {num}-{docpart}:{year} - subpefixes are IEC, IEEE, IEC/IEEE, TR, R. Any other?
|
5
|
-
# ISO {num}:{year}/{correction} {cornum}:{coryear} - corrections are Amd, DAmd, Cor. coryear is optional
|
6
|
-
# ISO {num}:{year}/{corstage} {correction} {cornum}:{coryear} - corstages are CD, NP, AWI, PRF, WD, DIS. Any others?
|
7
|
-
|
8
1
|
module Pubid::Iso
|
9
|
-
|
10
|
-
# ISO/IEC/IEEE 15289:2019
|
11
|
-
#
|
12
|
-
# Stage 10: NP (non-public)
|
13
|
-
# Stage 20: WD (non-public)
|
14
|
-
# Stage 30: CD
|
15
|
-
# Stage 40: DIS
|
16
|
-
# Stage 50: FDIS
|
17
|
-
# Stage 50.60: PRF ("proof") (non-public)
|
18
|
-
# Stage 60: IS
|
19
|
-
class Parser < Parslet::Parser
|
20
|
-
rule(:space) { str(" ") }
|
21
|
-
rule(:space?) { space.maybe }
|
22
|
-
|
23
|
-
rule(:digits) do
|
24
|
-
match('\d').repeat(1)
|
25
|
-
end
|
26
|
-
|
2
|
+
class Parser < Pubid::Core::Parser
|
27
3
|
rule(:stage) do
|
28
|
-
Russian::STAGE.values.reduce(
|
4
|
+
Renderer::Russian::STAGE.values.reduce(
|
29
5
|
# other stages
|
30
6
|
str("NP") | str("WD") | str("CD") | str("DIS") | str("FDIS") | str("PRF") |
|
31
7
|
str("IS") | str("AWI") | str("PWI") |
|
@@ -35,18 +11,9 @@ module Pubid::Iso
|
|
35
11
|
end
|
36
12
|
end
|
37
13
|
|
38
|
-
# TYPES = {
|
39
|
-
# "TS" => "technical-specification",
|
40
|
-
# "TR" => "technical-report",
|
41
|
-
# "PAS" => "publicly-available-specification",
|
42
|
-
# "Guide" => "guide",
|
43
|
-
# }.freeze
|
44
|
-
# DATA|GUIDE|ISP|IWA|PAS|R|TR|TS|TTA
|
45
|
-
# # type = "data" / "guide" / "isp" / "iwa" /
|
46
|
-
# # "pas" / "r" / "tr" / "ts" / "tta"
|
47
14
|
rule(:type) do
|
48
15
|
(
|
49
|
-
Russian::TYPE.values.reduce(
|
16
|
+
Renderer::Russian::TYPE.values.reduce(
|
50
17
|
str("DATA") | str("ISP") | str("IWA") | str("R") | str("TTA") |
|
51
18
|
str("TS") | str("TR") | str("PAS") | str("Guide") | str("GUIDE")) do |acc, type|
|
52
19
|
acc | str(type)
|
@@ -76,22 +43,13 @@ module Pubid::Iso
|
|
76
43
|
str("CSC/SP") | str("CSC/FIN") | str("JAG")
|
77
44
|
end
|
78
45
|
|
79
|
-
rule(:year) do
|
80
|
-
match('\d').repeat(4, 4).as(:year)
|
81
|
-
end
|
82
|
-
|
83
46
|
rule(:part) do
|
84
47
|
(str("-") | str("/")) >> space? >>
|
85
48
|
(str("Amd") | str("Cor")).absent? >> (match['[\dA-Z]'] | str("-")).repeat(1).as(:part)
|
86
49
|
end
|
87
50
|
|
88
|
-
rule(:originator) do
|
89
|
-
organization.as(:publisher) >>
|
90
|
-
(space? >> str("/") >> organization.as(:copublisher)).repeat
|
91
|
-
end
|
92
|
-
|
93
51
|
rule(:organization) do
|
94
|
-
Russian::PUBLISHER.values.reduce(
|
52
|
+
Renderer::Russian::PUBLISHER.values.reduce(
|
95
53
|
str("IEC") | str("IEEE") | str("CIW") | str("SAE") |
|
96
54
|
str("CIE") | str("ASME") | str("ASTM") | str("OECD") | str("ISO") |
|
97
55
|
str("IWA") | str("HL7") | str("CEI")) do |acc, publisher|
|
@@ -109,21 +67,21 @@ module Pubid::Iso
|
|
109
67
|
end
|
110
68
|
|
111
69
|
rule(:amendment) do
|
112
|
-
(str("/") >> stage.as(:
|
70
|
+
((str("/") >> stage.as(:stage)).maybe >>
|
113
71
|
(str("/") | space).maybe >>
|
114
|
-
(str("Amd") | str("AMD") | str("AM"))
|
72
|
+
(str("Amd") | str("AMD") | str("AM")) >>
|
115
73
|
(space | str(".")) >>
|
116
|
-
digits.as(:
|
117
|
-
(str(":") >> digits.as(:
|
74
|
+
digits.as(:version) >>
|
75
|
+
(str(":") >> digits.as(:number)).maybe).as(:amendments)
|
118
76
|
end
|
119
77
|
|
120
78
|
rule(:corrigendum) do
|
121
|
-
(str("/") >> stage.as(:
|
79
|
+
((str("/") >> stage.as(:stage)).maybe >>
|
122
80
|
(str("/") | space).maybe >>
|
123
|
-
(str("Cor") | str("COR"))
|
81
|
+
(str("Cor") | str("COR")) >>
|
124
82
|
(space | str(".")) >>
|
125
|
-
digits.as(:
|
126
|
-
(str(":") >> digits.as(:
|
83
|
+
digits.as(:version) >>
|
84
|
+
(str(":") >> digits.as(:number)).maybe).as(:corrigendums)
|
127
85
|
end
|
128
86
|
|
129
87
|
rule(:language) do
|
@@ -148,7 +106,20 @@ module Pubid::Iso
|
|
148
106
|
wgtype.as(:wgtype) >> space >> digits.as(:wgnumber)) |
|
149
107
|
(sctype.as(:sctype) >> (space | str("/") >> wgtype.as(:wgtype) >> space) >> digits.as(:scnumber))
|
150
108
|
)).maybe >>
|
151
|
-
str("
|
109
|
+
space >> str("N") >> space? >> digits.as(:number)
|
110
|
+
end
|
111
|
+
|
112
|
+
rule(:dir_supplement_edition) do
|
113
|
+
space >> (str("Edition") | str("Ed")) >> space >> digits.as(:edition)
|
114
|
+
end
|
115
|
+
|
116
|
+
rule(:dir_document_body) do
|
117
|
+
((str("DIR") | str("Directives Part") | str("Directives, Part") | str("Directives,")).as(:dir) >> space).maybe >>
|
118
|
+
(str("JTC").as(:dirtype) >> space).maybe >>
|
119
|
+
(digits.as(:number) >> (str(":") >> year).maybe).maybe >>
|
120
|
+
(str(" -- Consolidated").maybe >> (space? >> (organization.as(:publisher) >> space).maybe >>
|
121
|
+
(str("SUP") | str("Supplement")) >> (str(":") >> year).maybe >>
|
122
|
+
dir_supplement_edition.maybe).as(:supplement)).maybe
|
152
123
|
end
|
153
124
|
|
154
125
|
rule(:std_document_body) do
|
@@ -176,7 +147,8 @@ module Pubid::Iso
|
|
176
147
|
(guide_prefix.as(:type) >> space).maybe >>
|
177
148
|
(stage.as(:stage) >> space).maybe >>
|
178
149
|
originator >> (space | str("/")) >>
|
179
|
-
(tc_document_body | std_document_body
|
150
|
+
(tc_document_body | std_document_body | (dir_document_body >>
|
151
|
+
(str(" + ") >> (originator >> space >> dir_document_body).as(:joint_document)).maybe))
|
180
152
|
end
|
181
153
|
|
182
154
|
rule(:root) { identifier }
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class Dir < Pubid::Core::Renderer::Base
|
3
|
+
|
4
|
+
def render_identifier(params)
|
5
|
+
res = ("%{publisher}%{copublisher} DIR%{dirtype}%{number}%{year}%{supplement}" % params)
|
6
|
+
|
7
|
+
if params.key?(:joint_document)
|
8
|
+
joint_params = prerender_params(params[:joint_document], {})
|
9
|
+
joint_params.default = ""
|
10
|
+
res += (" + %{publisher}%{copublisher}%{dirtype}%{number}%{year}%{supplement}" % joint_params)
|
11
|
+
end
|
12
|
+
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_number(number, _opts, _params)
|
17
|
+
" #{number}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_dirtype(dirtype, _opts, _params)
|
21
|
+
" #{dirtype}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def render_supplement(supplement, _opts, _params)
|
25
|
+
if supplement.publisher && supplement.publisher != ""
|
26
|
+
" #{supplement.publisher} SUP"
|
27
|
+
else
|
28
|
+
" SUP"
|
29
|
+
end + (supplement.number && ":#{supplement.number}" || "") +
|
30
|
+
(supplement.edition && " Edition #{supplement.edition}" || "")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class French < Pubid::Core::Renderer::Base
|
3
|
+
def render_identifier(params)
|
4
|
+
if params[:type] == " Guide"
|
5
|
+
params[:type] = ""
|
6
|
+
"Guide #{super(params)}"
|
7
|
+
else
|
8
|
+
super
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_copublisher(copublisher, opts, params)
|
13
|
+
"/#{copublisher.sub("IEC", "CEI")}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_corrigendums(corrigendums, _opts, _params)
|
17
|
+
super.gsub(" ", ".")
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_amendments(amendments, _opts, _params)
|
21
|
+
super.gsub(" ", ".")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class Russian < Pubid::Core::Renderer::Base
|
3
|
+
PUBLISHER = { "ISO" => "ИСО", "IEC" => "МЭК" }.freeze
|
4
|
+
STAGE = { "FDIS" => "ОПМС",
|
5
|
+
"DIS" => "ПМС",
|
6
|
+
"NP" => "НП",
|
7
|
+
"AWI" => "АВИ",
|
8
|
+
"CD" => "КПК",
|
9
|
+
"PD" => "ПД",
|
10
|
+
"FPD" => "ФПД",
|
11
|
+
|
12
|
+
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
TYPE = { "Guide" => "Руководство",
|
16
|
+
"TS" => "ТС",
|
17
|
+
"TR" => "ТО",
|
18
|
+
"ISP" => "ИСП",
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
def render_identifier(params)
|
22
|
+
if params[:type] == " Guide"
|
23
|
+
params[:type] = ""
|
24
|
+
"Руководство #{super(params)}"
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def render_publisher(publisher, _opts, _params)
|
31
|
+
PUBLISHER[publisher]
|
32
|
+
end
|
33
|
+
|
34
|
+
def render_copublisher(copublisher, _opts, _params)
|
35
|
+
# (!@copublisher.is_a?(Array) && [@copublisher]) || @copublisher
|
36
|
+
if copublisher.is_a?(Array)
|
37
|
+
copublisher.map(&:to_s).sort.map do |copublisher|
|
38
|
+
"/#{PUBLISHER[copublisher].gsub('-', '/')}"
|
39
|
+
end.join
|
40
|
+
else
|
41
|
+
"/#{PUBLISHER[copublisher]}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def render_stage(stage, _opts, params)
|
46
|
+
if params[:copublisher]
|
47
|
+
" #{STAGE[stage]}"
|
48
|
+
else
|
49
|
+
"/#{STAGE[stage]}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_corrigendums(corrigendums, _opts, _params)
|
54
|
+
super.gsub(" ", ".")
|
55
|
+
end
|
56
|
+
|
57
|
+
def render_amendments(amendments, _opts, _params)
|
58
|
+
super.gsub(" ", ".")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class Tc < Pubid::Core::Renderer::Base
|
3
|
+
|
4
|
+
def render_identifier(params)
|
5
|
+
"%{publisher}%{copublisher} %{tctype} %{tcnumber}%{sctype}%{wgtype} N%{number}" % params
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_tctype(tctype, _opts, _params)
|
9
|
+
tctype.is_a?(Array) && tctype.join("/") || tctype
|
10
|
+
end
|
11
|
+
|
12
|
+
# TC 184/SC/WG 4 - no wg number
|
13
|
+
# TC 184/SC 4/WG 12 - separate sc and wg number
|
14
|
+
def render_sctype(sctype, _opts, params)
|
15
|
+
if params[:wgnumber] || !params[:wgtype]
|
16
|
+
"/#{sctype} #{params[:scnumber]}"
|
17
|
+
else
|
18
|
+
"/#{sctype}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_wgtype(wgtype, _opts, params)
|
23
|
+
if params[:wgnumber]
|
24
|
+
"/#{wgtype} #{params[:wgnumber]}"
|
25
|
+
else
|
26
|
+
"/#{wgtype} #{params[:scnumber]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class UrnDir < Pubid::Core::Renderer::Urn
|
3
|
+
|
4
|
+
def render_identifier(params)
|
5
|
+
res = ("urn:iso:doc:%{publisher}%{copublisher}:dir%{dirtype}%{number}%{year}%{supplement}" % params)
|
6
|
+
|
7
|
+
if params.key?(:joint_document)
|
8
|
+
joint_params = prerender_params(
|
9
|
+
params[:joint_document].transform_values { |value| value.is_a?(Parslet::Slice) && value.to_s || value }, {}
|
10
|
+
)
|
11
|
+
joint_params.default = ""
|
12
|
+
res += (":%{publisher}%{copublisher}%{dirtype}%{number}%{supplement}" % joint_params)
|
13
|
+
end
|
14
|
+
|
15
|
+
res
|
16
|
+
end
|
17
|
+
|
18
|
+
def render_number(number, _opts, _params)
|
19
|
+
":#{number}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def render_dirtype(dirtype, _opts, _params)
|
23
|
+
":#{dirtype.downcase}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def render_supplement(supplement, _opts, _params)
|
27
|
+
if supplement.publisher && supplement.publisher != ""
|
28
|
+
":sup:#{supplement.publisher.downcase}"
|
29
|
+
else
|
30
|
+
":sup"
|
31
|
+
end + (supplement.number && ":#{supplement.number}" || "") +
|
32
|
+
(supplement.edition && ":ed-#{supplement.edition}" || "")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Pubid::Iso::Renderer
|
2
|
+
class UrnTc < Pubid::Core::Renderer::Urn
|
3
|
+
|
4
|
+
def render_identifier(params)
|
5
|
+
"urn:iso:doc:%{publisher}%{copublisher}:%{tctype}:%{tcnumber}%{sctype}%{wgtype}:%{number}" % params
|
6
|
+
end
|
7
|
+
|
8
|
+
def render_tctype(tctype, _opts, _params)
|
9
|
+
(tctype.is_a?(Array) && tctype.join(":") || tctype).downcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_sctype(sctype, _opts, params)
|
13
|
+
":#{sctype.downcase}:#{params[:scnumber]}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_wgtype(wgtype, _opts, params)
|
17
|
+
if params[:wgnumber]
|
18
|
+
":#{wgtype.downcase}:#{params[:wgnumber]}"
|
19
|
+
else
|
20
|
+
":#{wgtype.downcase}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/pubid/iso/supplement.rb
CHANGED
@@ -1,37 +1,24 @@
|
|
1
1
|
module Pubid::Iso
|
2
|
-
class Supplement
|
3
|
-
attr_accessor :
|
2
|
+
class Supplement < Pubid::Core::Supplement
|
3
|
+
attr_accessor :stage, :publisher, :edition
|
4
4
|
|
5
|
-
def initialize(version
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
other.version == version && (number.nil? || other.number == number) && (stage.nil? || other.stage == stage)
|
5
|
+
def initialize(stage: nil, version: nil, publisher: nil, edition: nil, **args)
|
6
|
+
super(version: version, **args)
|
7
|
+
@stage = stage
|
8
|
+
@publisher = publisher.to_s
|
9
|
+
@edition = edition
|
11
10
|
end
|
12
11
|
|
13
12
|
def render_pubid_stage
|
14
13
|
((@stage && @stage) || "")
|
15
14
|
end
|
16
15
|
|
17
|
-
def render_pubid_number
|
18
|
-
if @number
|
19
|
-
"#{@version}:#{@number}"
|
20
|
-
else
|
21
|
-
"#{@version}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
16
|
def render_urn_stage
|
26
|
-
((@stage && ":stage-#{sprintf('%05.2f', Urn::STAGES[@stage.to_sym])}") || "")
|
17
|
+
((@stage && ":stage-#{sprintf('%05.2f', Pubid::Core::Renderer::Urn::STAGES[@stage.to_sym])}") || "")
|
27
18
|
end
|
28
19
|
|
29
|
-
def
|
30
|
-
|
31
|
-
":#{@number}:v#{@version}"
|
32
|
-
else
|
33
|
-
":#{@version}:v1"
|
34
|
-
end
|
20
|
+
def <=>(other)
|
21
|
+
(super == 0) && ((stage.nil? || stage == other.stage) && 0 || -1) || super
|
35
22
|
end
|
36
23
|
end
|
37
24
|
end
|
@@ -8,12 +8,18 @@ module Pubid::Iso
|
|
8
8
|
{ stage: convert_stage(context[:stage]) }
|
9
9
|
end
|
10
10
|
|
11
|
-
rule(
|
12
|
-
|
11
|
+
rule(amendments: subtree(:amendments)) do |context|
|
12
|
+
if context[:amendments].key?(:stage)
|
13
|
+
context[:amendments][:stage] = convert_stage(context[:amendments][:stage])
|
14
|
+
end
|
15
|
+
context
|
13
16
|
end
|
14
|
-
|
15
|
-
rule(
|
16
|
-
|
17
|
+
#
|
18
|
+
rule(corrigendums: subtree(:corrigendums)) do |context|
|
19
|
+
if context[:corrigendums].key?(:stage)
|
20
|
+
context[:corrigendums][:stage] = convert_stage(context[:corrigendums][:stage])
|
21
|
+
end
|
22
|
+
context
|
17
23
|
end
|
18
24
|
|
19
25
|
rule(language: simple(:language)) do |context|
|
@@ -27,7 +33,7 @@ module Pubid::Iso
|
|
27
33
|
end
|
28
34
|
|
29
35
|
rule(type: simple(:type)) do
|
30
|
-
russian_type = Russian::TYPE.key(type.to_s)
|
36
|
+
russian_type = Renderer::Russian::TYPE.key(type.to_s)
|
31
37
|
{ type: russian_type&.to_s ||
|
32
38
|
case type
|
33
39
|
# XXX: can't put 2 alternative Russian translations to dictionary, temporary hack
|
@@ -44,7 +50,7 @@ module Pubid::Iso
|
|
44
50
|
end
|
45
51
|
|
46
52
|
rule(copublisher: simple(:copublisher)) do
|
47
|
-
russian_copublisher = Russian::PUBLISHER.key(copublisher.to_s)
|
53
|
+
russian_copublisher = Renderer::Russian::PUBLISHER.key(copublisher.to_s)
|
48
54
|
{ copublisher: russian_copublisher&.to_s ||
|
49
55
|
case copublisher
|
50
56
|
when "CEI"
|
@@ -56,12 +62,33 @@ module Pubid::Iso
|
|
56
62
|
end
|
57
63
|
|
58
64
|
rule(publisher: simple(:publisher)) do
|
59
|
-
russian_publisher = Russian::PUBLISHER.key(publisher.to_s)
|
65
|
+
russian_publisher = Renderer::Russian::PUBLISHER.key(publisher.to_s)
|
60
66
|
{ publisher: russian_publisher&.to_s || publisher }
|
61
67
|
end
|
62
68
|
|
69
|
+
# rule(year: simple(:year)) do
|
70
|
+
# { year: year.to_i }
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
rule(publisher: simple(:publisher), supplement: subtree(:supplement)) do |context|
|
74
|
+
context[:supplement] =
|
75
|
+
Supplement.new(number: context[:supplement][:year],
|
76
|
+
publisher: context[:supplement][:publisher],
|
77
|
+
edition: context[:supplement][:edition])
|
78
|
+
context
|
79
|
+
end
|
80
|
+
|
81
|
+
rule(supplement: subtree(:supplement)) do |context|
|
82
|
+
context[:supplement] =
|
83
|
+
Supplement.new(number: context[:supplement][:year],
|
84
|
+
publisher: context[:supplement][:publisher],
|
85
|
+
edition: context[:supplement][:edition])
|
86
|
+
context
|
87
|
+
end
|
88
|
+
|
89
|
+
|
63
90
|
def self.convert_stage(code)
|
64
|
-
russian_code = Russian::STAGE.key(code.to_s)
|
91
|
+
russian_code = Renderer::Russian::STAGE.key(code.to_s)
|
65
92
|
return russian_code.to_s if russian_code
|
66
93
|
|
67
94
|
case code
|
data/lib/pubid/iso/version.rb
CHANGED
data/lib/pubid/iso.rb
CHANGED
@@ -8,6 +8,7 @@ module Pubid
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
require "pubid-core"
|
11
12
|
require_relative "iso/errors"
|
12
13
|
require_relative "iso/parser"
|
13
14
|
require_relative "iso/transformer"
|
@@ -15,6 +16,9 @@ require_relative "iso/supplement"
|
|
15
16
|
require_relative "iso/amendment"
|
16
17
|
require_relative "iso/corrigendum"
|
17
18
|
require_relative "iso/identifier"
|
18
|
-
require_relative "iso/
|
19
|
-
require_relative "iso/
|
20
|
-
require_relative "iso/
|
19
|
+
require_relative "iso/renderer/french"
|
20
|
+
require_relative "iso/renderer/russian"
|
21
|
+
require_relative "iso/renderer/tc"
|
22
|
+
require_relative "iso/renderer/urn-tc"
|
23
|
+
require_relative "iso/renderer/dir"
|
24
|
+
require_relative "iso/renderer/urn-dir"
|
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.1.
|
4
|
+
version: 0.1.8
|
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-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pubid-core
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.2'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.2'
|
97
111
|
description: Library to generate, parse and manipulate ISO PubID.
|
98
112
|
email:
|
99
113
|
- open.source@ribose.com
|
@@ -111,12 +125,15 @@ files:
|
|
111
125
|
- lib/pubid/iso/corrigendum.rb
|
112
126
|
- lib/pubid/iso/errors.rb
|
113
127
|
- lib/pubid/iso/identifier.rb
|
114
|
-
- lib/pubid/iso/identifier/french.rb
|
115
|
-
- lib/pubid/iso/identifier/russian.rb
|
116
128
|
- lib/pubid/iso/parser.rb
|
129
|
+
- lib/pubid/iso/renderer/dir.rb
|
130
|
+
- lib/pubid/iso/renderer/french.rb
|
131
|
+
- lib/pubid/iso/renderer/russian.rb
|
132
|
+
- lib/pubid/iso/renderer/tc.rb
|
133
|
+
- lib/pubid/iso/renderer/urn-dir.rb
|
134
|
+
- lib/pubid/iso/renderer/urn-tc.rb
|
117
135
|
- lib/pubid/iso/supplement.rb
|
118
136
|
- lib/pubid/iso/transformer.rb
|
119
|
-
- lib/pubid/iso/urn.rb
|
120
137
|
- lib/pubid/iso/version.rb
|
121
138
|
homepage: https://github.com/metanorma/pubid-iso
|
122
139
|
licenses:
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Pubid::Iso
|
2
|
-
class French < Identifier
|
3
|
-
def initialize(**opts)
|
4
|
-
opts.each { |key, value| send("#{key}=", value) }
|
5
|
-
end
|
6
|
-
|
7
|
-
def identifier(with_date, with_language_code)
|
8
|
-
if @type == "Guide"
|
9
|
-
"Guide #{originator}#{stage} #{number}#{part}#{iteration}"\
|
10
|
-
"#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
|
11
|
-
else
|
12
|
-
super
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def copublisher
|
17
|
-
super.map { |copublisher| copublisher.sub("IEC", "CEI") }
|
18
|
-
end
|
19
|
-
|
20
|
-
def supplements
|
21
|
-
super.gsub(" ", ".")
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module Pubid::Iso
|
2
|
-
class Russian < Identifier
|
3
|
-
PUBLISHER = { "ISO" => "ИСО", "IEC" => "МЭК" }.freeze
|
4
|
-
STAGE = { "FDIS" => "ОПМС",
|
5
|
-
"DIS" => "ПМС",
|
6
|
-
"NP" => "НП",
|
7
|
-
"AWI" => "АВИ",
|
8
|
-
"CD" => "КПК",
|
9
|
-
"PD" => "ПД",
|
10
|
-
"FPD" => "ФПД",
|
11
|
-
|
12
|
-
|
13
|
-
}.freeze
|
14
|
-
TYPE = { "Guide" => "Руководство",
|
15
|
-
"TS" => "ТС",
|
16
|
-
"TR" => "ТО",
|
17
|
-
"ISP" => "ИСП",
|
18
|
-
}.freeze
|
19
|
-
|
20
|
-
def initialize(**opts)
|
21
|
-
opts.each { |key, value| send("#{key}=", value) }
|
22
|
-
end
|
23
|
-
|
24
|
-
def identifier(with_date, with_language_code)
|
25
|
-
if @type == "Guide"
|
26
|
-
"Руководство #{originator}#{stage} #{number}#{part}#{iteration}"\
|
27
|
-
"#{with_date && rendered_year || ''}#{edition}#{supplements}#{language(with_language_code)}"
|
28
|
-
else
|
29
|
-
super
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def publisher
|
34
|
-
PUBLISHER[@publisher]
|
35
|
-
end
|
36
|
-
|
37
|
-
def copublisher
|
38
|
-
super&.map { |copublisher| PUBLISHER[copublisher] }
|
39
|
-
end
|
40
|
-
|
41
|
-
def stage
|
42
|
-
"#{(@copublisher && ' ') || '/'}#{STAGE[@stage]}" if @stage
|
43
|
-
end
|
44
|
-
|
45
|
-
def supplements
|
46
|
-
super.gsub(" ", ".")
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/pubid/iso/urn.rb
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
module Pubid::Iso
|
2
|
-
class Urn < Identifier
|
3
|
-
|
4
|
-
STAGES = { PWI: 0,
|
5
|
-
NP: 10,
|
6
|
-
AWI: 20,
|
7
|
-
WD: 20.20,
|
8
|
-
CD: 30,
|
9
|
-
DIS: 40,
|
10
|
-
FDIS: 50,
|
11
|
-
PRF: 50,
|
12
|
-
IS: 60 }.freeze
|
13
|
-
|
14
|
-
def initialize(**opts)
|
15
|
-
opts.each { |key, value| send("#{key}=", value) }
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s
|
19
|
-
# docidentifier = originator [":" type] ":" docnumber [":" partnumber]
|
20
|
-
# [[":" status] ":" edition]
|
21
|
-
# [":" docversion] [":" language]
|
22
|
-
|
23
|
-
if tctype
|
24
|
-
"urn:iso:doc:#{originator}:#{tctype.downcase}:#{tcnumber}#{sctype}#{wgtype}:#{number}"
|
25
|
-
else
|
26
|
-
"urn:iso:std:#{originator}#{type}:#{number}#{part}#{stage}#{edition}#{supplement}#{language}"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def tctype
|
31
|
-
return @tctype.join(":") if @tctype.is_a?(Array)
|
32
|
-
|
33
|
-
@tctype
|
34
|
-
end
|
35
|
-
|
36
|
-
def sctype
|
37
|
-
return unless @sctype
|
38
|
-
|
39
|
-
":#{@sctype.downcase}:#{@scnumber}"
|
40
|
-
end
|
41
|
-
|
42
|
-
def wgtype
|
43
|
-
return unless @wgtype
|
44
|
-
|
45
|
-
if @wgnumber
|
46
|
-
":#{@wgtype.downcase}:#{@wgnumber}"
|
47
|
-
else
|
48
|
-
":#{@wgtype.downcase}"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def part
|
53
|
-
":-#{@part}" if @part
|
54
|
-
end
|
55
|
-
|
56
|
-
def render_stage(stage)
|
57
|
-
return ":stage-#{sprintf('%05.2f', stage)}#{iteration}" if stage.is_a?(Float)
|
58
|
-
|
59
|
-
":stage-#{sprintf('%05.2f', STAGES[stage.to_sym])}#{iteration}"
|
60
|
-
end
|
61
|
-
|
62
|
-
def stage
|
63
|
-
return render_stage(@urn_stage) if @urn_stage
|
64
|
-
|
65
|
-
return render_stage(@stage) if @stage
|
66
|
-
|
67
|
-
render_stage(@corrigendum_stage) if @corrigendum_stage
|
68
|
-
end
|
69
|
-
|
70
|
-
def originator
|
71
|
-
# originator = "iso" / "iso-iec" / "iso-cie" / "iso-astm" /
|
72
|
-
# "iso-ieee" / "iec"
|
73
|
-
|
74
|
-
if @copublisher
|
75
|
-
@copublisher = [@copublisher] unless @copublisher.is_a?(Array)
|
76
|
-
@publisher.downcase + @copublisher.map(&:to_s).sort.map do |copublisher|
|
77
|
-
"-#{copublisher.downcase.gsub('/', '-')}"
|
78
|
-
end.join
|
79
|
-
else
|
80
|
-
@publisher.downcase
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def edition
|
85
|
-
":ed-#{@edition}" if @edition
|
86
|
-
end
|
87
|
-
|
88
|
-
def iteration
|
89
|
-
".v#{@iteration}" if @iteration
|
90
|
-
end
|
91
|
-
|
92
|
-
def type
|
93
|
-
# type = "data" / "guide" / "isp" / "iwa" /
|
94
|
-
# "pas" / "r" / "tr" / "ts" / "tta"
|
95
|
-
if @type
|
96
|
-
":#{@type.downcase}"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
def supplement
|
101
|
-
result = @amendment&.render_urn || ""
|
102
|
-
|
103
|
-
result += @corrigendum&.render_urn || ""
|
104
|
-
|
105
|
-
result
|
106
|
-
end
|
107
|
-
|
108
|
-
def language
|
109
|
-
if @language
|
110
|
-
":#{@language}"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|