pubid-ieee 0.1.1
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 +7 -0
- data/LICENSE.txt +25 -0
- data/README.adoc +127 -0
- data/lib/pubid/ieee/errors.rb +6 -0
- data/lib/pubid/ieee/identifier/base.rb +311 -0
- data/lib/pubid/ieee/identifier.rb +46 -0
- data/lib/pubid/ieee/parser.rb +399 -0
- data/lib/pubid/ieee/transformer.rb +40 -0
- data/lib/pubid/ieee/type.rb +42 -0
- data/lib/pubid/ieee/version.rb +5 -0
- data/lib/pubid/ieee.rb +19 -0
- data/lib/pubid-ieee.rb +1 -0
- data/update_codes.yaml +53 -0
- metadata +155 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9302100f8fc58e3b1c356d866a982f830a8c3331257ee7069e9c1160d347abe7
|
4
|
+
data.tar.gz: bd327f07a78a631284ea36d0962ff6ecbbe3dbb917e25152643b43e6882202a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24de2e26b1e31b1547f0f557cbc3ddc0414a7a5dc37bc0c8ca31e697cfb11a214372e9923c23e26f2221822752a0556be5183e097ee79ba3ce6b2d614cd55c5b
|
7
|
+
data.tar.gz: 828523c08cd2bcca2229e00120f2c309cae15281f9984123574b0e8eb575c988bc0dfc2d91711a33c8e6234023f3313e2c2b5ce21ced35d9c8b810052c5e4f7f
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
BSD 2-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2018, Ribose
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
= IEEE publication identifiers ("IEEE PubID")
|
2
|
+
|
3
|
+
== Purpose
|
4
|
+
|
5
|
+
Implements a mechanism to parse and utilize IEEE publication identifers.
|
6
|
+
|
7
|
+
== Historic identifier patterns
|
8
|
+
|
9
|
+
There are at least two major "pattern series" of identifiers due to historical reasons: old (type I) and new (type II).
|
10
|
+
This implementation attempts to support both types of publication identifier patterns.
|
11
|
+
|
12
|
+
== Use cases to support
|
13
|
+
|
14
|
+
* analyze a pattern of type I idetifier
|
15
|
+
* parse type II idetifier into components
|
16
|
+
* generate a filename from the components similar to type I pattern
|
17
|
+
|
18
|
+
== Elements of the PubID
|
19
|
+
|
20
|
+
=== Publisher
|
21
|
+
|
22
|
+
|===
|
23
|
+
| Name | Abbrev
|
24
|
+
|
25
|
+
| Institute of Electrical and Electronics Engineers
|
26
|
+
| IEEE
|
27
|
+
|
28
|
+
|===
|
29
|
+
|
30
|
+
=== Report number
|
31
|
+
|
32
|
+
`{number}` - is a set of one or more digits and optional letters
|
33
|
+
|
34
|
+
=== Part
|
35
|
+
|
36
|
+
`{part}` - is a set of digits and optional letters; starts with a digit; if a letter or letters are present then they are in the end; optional
|
37
|
+
|
38
|
+
=== Subpart
|
39
|
+
|
40
|
+
`{subpart}` - is a set of digits and optional letters; optional, many subparts are possible
|
41
|
+
|
42
|
+
=== Year
|
43
|
+
|
44
|
+
`{year}` - is a set of 4 digits; optional
|
45
|
+
|
46
|
+
=== Corrigendum & Amendment
|
47
|
+
|
48
|
+
`{cor}` - is a corrigendum or an amendments with the pattern `Cor {cornum}-{year}` or `Amd {cornum}:{year}` where {cornum} is a set of digits; optional
|
49
|
+
|
50
|
+
== Type I pattern
|
51
|
+
|
52
|
+
[source]
|
53
|
+
----
|
54
|
+
{publisher} {type} {series} {number}{part}.{subpart}{year} {edition}/{conform}/{correction}
|
55
|
+
----
|
56
|
+
|
57
|
+
* `{publisher}` IEEE
|
58
|
+
* `{type}` one of the values: `Standard`, `Std`, `Draft`, `Draft Standard`, `Draft Supplement` ^*^
|
59
|
+
* `{series}` one of the values: `ISO/IEC`, `ISO/IEC/IEEE` ^*^
|
60
|
+
* `{number}` set of digits optionally prefixed with uppercase letter and optionally suffixed with letter
|
61
|
+
* `{part}` from 1 to 2 digits prefixed with `.` or `-` and optionally suffixed with up to 4 letters ^*^
|
62
|
+
* `{subpart}` 1 digit optionally suffixed with a letter ^*^
|
63
|
+
* `{year}` 4 digits prefixed with `-`, `:`, ` - `, or breakspace ^*^
|
64
|
+
* `{edition}` prefix `Edition` followed by a reference in brackets or prefix `First edition` followed by date in format `YYYY-MM-DD` ^*^
|
65
|
+
* `{conform}` prefix `Conformance` followed by 2 digits, dash, and 4 digits year ^*^
|
66
|
+
* `{correction}` prefix `Cor` optionally followed by breakspace, or prefix `Amd` followed by `.`, followed by from 1 to 2 digits, dash and 4 digits year ^*^
|
67
|
+
|
68
|
+
(*) - optional
|
69
|
+
|
70
|
+
An identifier can be composed of 2 other identifiers with breakspace delimiter. Only the first identifier needs to cnatain puplisher, for the secont it's optional
|
71
|
+
|
72
|
+
Following RegEx expression parses 100% of identifiers from the type I https://xml2rfc.tools.ietf.org/public/rfc/bibxml-ieee/[dataset]:
|
73
|
+
[source,regex]
|
74
|
+
|
75
|
+
----
|
76
|
+
{
|
77
|
+
^IEEE\s
|
78
|
+
((?<type1>Standard|Std|Draft(\sStandard|\sSupplement)?)\s)?
|
79
|
+
((?<series>ISO\/IEC(\/IEEE)?)\s)?
|
80
|
+
(?<number1>[A-Z]?\d+[[:alpha:]]?)
|
81
|
+
([.-](?<part1>\d{1,2}(?!\d)[[:alpha:]]{0,4}))?
|
82
|
+
(\.(?<subpart1>\d[[:alpha:]]?))?
|
83
|
+
(?<year1>([-:]|\s-\s|,\s)\d{4})?
|
84
|
+
(\s(IEEE\s(?<type2>Std)\s)?(?<number2>[A-Z]?\d+[[:alpha:]]?)
|
85
|
+
([.-](?<part2>\d{1,2}(?!\d)[[:alpha:]]{0,4}))?
|
86
|
+
([.](?<subpart2>\d[[:alpha:]]?))?
|
87
|
+
(?<year2>([-:.]|_-|\s-\s|,\s)\d{4})?)?
|
88
|
+
(\s(?<edition>Edition(\s\([^)]+\))?|First\sedition\s[\d-]+))?
|
89
|
+
(\/(?<conform>Conformance\d{2})-(?<confyear>\d{4}))?
|
90
|
+
(\/(?<correction>(Cor\s?|(Amd\.)\d{1,2})
|
91
|
+
(?<coryear>(:|-|:-)\d{4}))?$
|
92
|
+
}x
|
93
|
+
----
|
94
|
+
|
95
|
+
== Pasing PubID elements from type II identifiers
|
96
|
+
|
97
|
+
To parse PubID elements from the type II pattern identifiers we can use a RegEx expression:
|
98
|
+
|
99
|
+
[source,regex]
|
100
|
+
----
|
101
|
+
{
|
102
|
+
^IEEE\s(?<number1>\w+(\.[A-Z]\d|\sHBK)?)
|
103
|
+
(?<part1>(\.|\s)\d{1,4}[[:alpha:],]{0,7}|-\d?[A-Z]+|-\d(?=[-.]))?
|
104
|
+
(?<subpart11>\.\d{1,3}[a-z]?|-\d{5}[a-z]?|-\d+(?=[-:_]))?
|
105
|
+
(?<subpart12>\.\d|-\d+(?=-))?
|
106
|
+
(?<year1>([-:.]|_-|\s-)\d{4})?
|
107
|
+
(\/(?<number2>([A-Z]?\d+[a-z]?|Conformance\d+))
|
108
|
+
((\.|-)(?<part2>\d{1,3}[a-z]?)(?!\d))?
|
109
|
+
(\.(?<subpart21>\d{1,2}))?)?
|
110
|
+
(\/(?<number3>\d+)(\.(?<part3>\d))?)?
|
111
|
+
(?<year2>([-:.]|_-|\s-)\d{4})?
|
112
|
+
((\/|_|-|\s\/)(?<correction>(Cor|(?i)Amd(?-i))(\s|\.|\.\s)?\d{1,2})
|
113
|
+
(?<coryear>(:|-|:-|_[A-Z][a-z]{2}_)\d{4}(-\d{4})?)?)?$
|
114
|
+
}x
|
115
|
+
----
|
116
|
+
|
117
|
+
This RegEx expession covers 99% of the identifiers from the type II bibxml-ieee https://xml2rfc.tools.ietf.org/public/rfc/bibxml-ieee-new/[dataset].
|
118
|
+
|
119
|
+
== File name generator
|
120
|
+
|
121
|
+
For type I identifiers file names are generated by replacing symbols `/`, `\`, `,`, `'`, `"`, `(`, `)`, and breakspace with symbol `_`. Sequences of multiple sybols `_` should be squized to one symbol.
|
122
|
+
|
123
|
+
For type II identifiers it needs to parse PubID elements than join the elements in order:
|
124
|
+
|
125
|
+
----
|
126
|
+
IEEE.{number1}_{part1}.{subpart11}.{subpart12}-{year1}_{number2}_{part2}.{subpart21}_{number3}_{part3}-{year2}_{correction}-{coryear}
|
127
|
+
----
|
@@ -0,0 +1,311 @@
|
|
1
|
+
require 'date'
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
UPDATE_CODES = YAML.load_file(File.join(File.dirname(__FILE__), "../../../../update_codes.yaml"))
|
5
|
+
|
6
|
+
module Pubid::Ieee
|
7
|
+
module Identifier
|
8
|
+
class Base < Pubid::Core::Identifier::Base
|
9
|
+
attr_accessor :number, :publisher, :copublisher, :stage, :part, :subpart,
|
10
|
+
:edition, :draft, :redline, :year, :month, :type, :alternative,
|
11
|
+
:draft_status, :revision, :adoption_year, :amendment, :supersedes,
|
12
|
+
:corrigendum, :corrigendum_comment, :reaffirmed, :incorporates,
|
13
|
+
:supplement, :proposal, :iso_identifier, :iso_amendment
|
14
|
+
|
15
|
+
def initialize(publisher: "IEEE", number: nil, stage: nil, subpart: nil, edition: nil,
|
16
|
+
draft: nil, redline: nil, month: nil, revision: nil,
|
17
|
+
iso_identifier: nil, type: :std, alternative: nil, draft_status: nil, adoption_year: nil,
|
18
|
+
amendment: nil, supersedes: nil, corrigendum: nil, corrigendum_comment: nil, reaffirmed: nil,
|
19
|
+
incorporates: nil, supplement: nil, proposal: nil, iso_amendment: nil, **opts)
|
20
|
+
|
21
|
+
super(**opts.merge(number: number, publisher: publisher))#.merge(amendments: amendments, corrigendums: corrigendums))
|
22
|
+
|
23
|
+
@edition = edition if edition
|
24
|
+
|
25
|
+
@proposal = @number.to_s[0] == "P"
|
26
|
+
@revision = revision
|
27
|
+
if iso_identifier
|
28
|
+
@iso_identifier = Pubid::Iso::Identifier.parse(iso_identifier)
|
29
|
+
elsif draft# && type != :p
|
30
|
+
@type = Type.new(:draft)
|
31
|
+
elsif type
|
32
|
+
if type.is_a?(Symbol)
|
33
|
+
@type = Type.new(type)
|
34
|
+
else
|
35
|
+
@type = Type.parse(type)
|
36
|
+
end
|
37
|
+
else
|
38
|
+
@type = Type.new
|
39
|
+
end
|
40
|
+
|
41
|
+
@stage = stage
|
42
|
+
@subpart = subpart
|
43
|
+
@draft = draft
|
44
|
+
@redline = redline
|
45
|
+
@month = month
|
46
|
+
@revision = revision
|
47
|
+
@amendment = amendment
|
48
|
+
@corrigendum = corrigendum
|
49
|
+
@corrigendum_comment = corrigendum_comment
|
50
|
+
@alternative = alternative
|
51
|
+
@draft_status = draft_status
|
52
|
+
@adoption_year = adoption_year
|
53
|
+
@supersedes = supersedes
|
54
|
+
@reaffirmed = reaffirmed
|
55
|
+
@incorporates = incorporates
|
56
|
+
@supplement = supplement
|
57
|
+
@proposal = proposal
|
58
|
+
@iso_amendment = iso_amendment
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.type
|
62
|
+
{ key: :std, title: "Standard" }
|
63
|
+
end
|
64
|
+
|
65
|
+
# convert parameters comes from parser to
|
66
|
+
def set_values(hash)
|
67
|
+
hash.each { |key, value| send("#{key}=", value.is_a?(Parslet::Slice) && value.to_s || value) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.add_missing_bracket(code)
|
71
|
+
code.count("(") > code.count(")") ? "#{code})" : code
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.update_old_code(code)
|
75
|
+
UPDATE_CODES.each do |from, to|
|
76
|
+
code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to)
|
77
|
+
end
|
78
|
+
code
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def self.parse(code)
|
83
|
+
parsed = Parser.new.parse(update_old_code(code))
|
84
|
+
transform(parsed)
|
85
|
+
|
86
|
+
rescue Parslet::ParseFailed => failure
|
87
|
+
raise Pubid::Ieee::Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.transform(params)
|
91
|
+
identifier_params = params.map do |k, v|
|
92
|
+
get_transformer_class.new.apply(k => v)
|
93
|
+
end.inject({}, :merge)
|
94
|
+
|
95
|
+
Identifier.create(**Identifier.convert_parser_parameters(**identifier_params))
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.get_transformer_class
|
99
|
+
Transformer
|
100
|
+
end
|
101
|
+
|
102
|
+
# @param [:short, :full] format
|
103
|
+
def to_s(format = :short, with_trademark: false)
|
104
|
+
if @iso_identifier
|
105
|
+
"#{@iso_identifier.to_s(format: :ref_num_short)}#{iso_amendment}#{dual_identifier}"
|
106
|
+
else
|
107
|
+
"#{identifier(format)}#{with_trademark ? trademark(@number) : ''}#{parameters}#{adoption}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def trademark(number)
|
112
|
+
%w(802 2030).include?(number.to_s) ? "\u00AE" : "\u2122"
|
113
|
+
end
|
114
|
+
|
115
|
+
def iso_amendment
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
def dual_identifier
|
120
|
+
@number ? " (#{identifier})#{parameters}" : "#{identifier}#{parameters}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def publisher
|
124
|
+
"#{@publisher}#{copublisher} " if @publisher && @number
|
125
|
+
end
|
126
|
+
|
127
|
+
def identifier(format = :short)
|
128
|
+
"#{publisher}#{draft_status(format)}#{type(format)}#{number}#{part}"\
|
129
|
+
"#{subpart}#{year}#{revision_date}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def parameters
|
133
|
+
"#{corrigendum}#{draft}#{edition}#{alternative}#{supersedes}"\
|
134
|
+
"#{reaffirmed}#{incorporates}#{supplement}#{revision}#{amendment}#{redline}"
|
135
|
+
end
|
136
|
+
|
137
|
+
def copublisher
|
138
|
+
return "" unless @copublisher
|
139
|
+
|
140
|
+
if @copublisher.is_a?(Array)
|
141
|
+
@copublisher&.map { |c| "/#{c}" }&.join
|
142
|
+
else
|
143
|
+
"/#{@copublisher}"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def part
|
148
|
+
"#{@part}" if @part
|
149
|
+
end
|
150
|
+
|
151
|
+
def subpart
|
152
|
+
@subpart if @subpart && !@subpart.to_s.empty?
|
153
|
+
end
|
154
|
+
|
155
|
+
def type(format)
|
156
|
+
return unless @type
|
157
|
+
|
158
|
+
@type.to_s(@publisher != "IEEE" ? :alternative : format)
|
159
|
+
end
|
160
|
+
|
161
|
+
def year
|
162
|
+
return "" if @month
|
163
|
+
return "" unless @year
|
164
|
+
|
165
|
+
if @corrigendum_comment
|
166
|
+
@corrigendum_comment.year
|
167
|
+
elsif @reaffirmed && @reaffirmed.key?(:reaffirmation_of)
|
168
|
+
@reaffirmed[:reaffirmation_of].year
|
169
|
+
else
|
170
|
+
"-#{@year}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def alternative
|
175
|
+
if @alternative
|
176
|
+
if @alternative.is_a?(Array)
|
177
|
+
" (#{@alternative.map { |a| self.class.new(**Identifier.convert_parser_parameters(**a)) }.join(', ')})"
|
178
|
+
else
|
179
|
+
" (#{self.class.new(**Identifier.convert_parser_parameters(**@alternative))})"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def edition
|
185
|
+
return "" unless @edition
|
186
|
+
|
187
|
+
result = ""
|
188
|
+
if @edition[:version]
|
189
|
+
result += @edition[:version] == "First" ? " Edition 1.0 " : " Edition #{@edition[:version]} "
|
190
|
+
end
|
191
|
+
|
192
|
+
if @edition[:year]
|
193
|
+
result += if @edition[:version]
|
194
|
+
"#{@edition[:year]}"
|
195
|
+
else
|
196
|
+
" #{@edition[:year]} Edition"
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
if @edition[:month]
|
201
|
+
month = @edition[:month]
|
202
|
+
month = Date.parse(@edition[:month]).month if month.to_i.zero?
|
203
|
+
result += "-#{sprintf('%02d', month)}"
|
204
|
+
end
|
205
|
+
result += "-#{@edition[:day]}" if @edition[:day]
|
206
|
+
result
|
207
|
+
end
|
208
|
+
|
209
|
+
def draft
|
210
|
+
return "" unless @draft
|
211
|
+
|
212
|
+
@draft = Identifier.merge_parameters(@draft) if @draft.is_a?(Array)
|
213
|
+
|
214
|
+
result = "/D#{@draft[:version].is_a?(Array) ? @draft[:version].join('D') : @draft[:version]}"
|
215
|
+
result += ".#{@draft[:revision]}" if @draft[:revision]
|
216
|
+
result += ", #{@draft[:month]}" if @draft[:month]
|
217
|
+
result += " #{@draft[:day]}," if @draft[:day]
|
218
|
+
result += " #{@draft[:year]}" if @draft[:year]
|
219
|
+
result
|
220
|
+
end
|
221
|
+
|
222
|
+
def draft_status(format)
|
223
|
+
"#{@draft_status} " if @draft_status && format == :full
|
224
|
+
end
|
225
|
+
|
226
|
+
def revision
|
227
|
+
" (Revision of #{@revision.join(' and ')})" if @revision
|
228
|
+
end
|
229
|
+
|
230
|
+
def revision_date
|
231
|
+
return nil unless @month
|
232
|
+
", #{@month} #{@year}"
|
233
|
+
end
|
234
|
+
|
235
|
+
def amendment
|
236
|
+
return unless @amendment || @iso_amendment
|
237
|
+
|
238
|
+
if @iso_amendment
|
239
|
+
if @iso_amendment[:year]
|
240
|
+
return "/Amd#{@iso_amendment[:version]}-#{@iso_amendment[:year]}"
|
241
|
+
else
|
242
|
+
return "/Amd#{@iso_amendment[:version]}"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
return " (Amendment to #{@amendment})" unless @amendment.is_a?(Array)
|
247
|
+
|
248
|
+
result = " (Amendment to #{@amendment.first} as amended by "
|
249
|
+
result += if @amendment.length > 2
|
250
|
+
"#{@amendment[1..-2].map(&:to_s).join(', ')}, and #{@amendment[-1]}"
|
251
|
+
else
|
252
|
+
@amendment.last.to_s
|
253
|
+
end
|
254
|
+
|
255
|
+
"#{result})"
|
256
|
+
end
|
257
|
+
|
258
|
+
def redline
|
259
|
+
" - Redline" if @redline
|
260
|
+
end
|
261
|
+
|
262
|
+
def adoption
|
263
|
+
if @adoption_year
|
264
|
+
adoption_id = dup
|
265
|
+
adoption_id.year = @adoption_year
|
266
|
+
" (Adoption of #{adoption_id.identifier})"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def supersedes
|
271
|
+
return unless @supersedes
|
272
|
+
|
273
|
+
if @supersedes.length > 2
|
274
|
+
" (Supersedes #{@supersedes.join(', ')})"
|
275
|
+
else
|
276
|
+
" (Supersedes #{@supersedes.join(' and ')})"
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
def corrigendum
|
281
|
+
if @corrigendum.nil?
|
282
|
+
(@year && @corrigendum_comment && "/Cor 1-#{@year}") || ""
|
283
|
+
else
|
284
|
+
if @corrigendum[:year]
|
285
|
+
"/Cor #{@corrigendum[:version]}-#{@corrigendum[:year]}"
|
286
|
+
else
|
287
|
+
"/Cor #{@corrigendum[:version]}"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def reaffirmed
|
293
|
+
return unless @reaffirmed
|
294
|
+
|
295
|
+
return " (Reaffirmed #{@year})" if @reaffirmed.key?(:reaffirmation_of)
|
296
|
+
|
297
|
+
" (Reaffirmed #{@reaffirmed[:year]})" if @reaffirmed[:year]
|
298
|
+
end
|
299
|
+
|
300
|
+
def incorporates
|
301
|
+
# " (Supersedes #{@supersedes.join(', ')})"
|
302
|
+
|
303
|
+
" (Incorporates #{@incorporates.join(', and ')})" if @incorporates
|
304
|
+
end
|
305
|
+
|
306
|
+
def supplement
|
307
|
+
" (Supplement to #{@supplement})" if @supplement
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pubid::Ieee
|
2
|
+
module Identifier
|
3
|
+
class << self
|
4
|
+
include Pubid::Core::Identifier
|
5
|
+
|
6
|
+
def parse(*args)
|
7
|
+
Base.parse(*args)
|
8
|
+
end
|
9
|
+
|
10
|
+
def convert_parser_parameters(type_status: nil, parameters: nil,
|
11
|
+
organizations: { publisher: "IEEE" }, **args)
|
12
|
+
res = [organizations, type_status, parameters].inject({}) do |result, data|
|
13
|
+
result.merge(
|
14
|
+
case data
|
15
|
+
when Hash
|
16
|
+
data.transform_values do |v|
|
17
|
+
(v.is_a?(Array) && v.first.is_a?(Hash) && merge_parameters(v)) || v
|
18
|
+
end
|
19
|
+
when Array
|
20
|
+
merge_parameters(data)
|
21
|
+
else
|
22
|
+
{}
|
23
|
+
end
|
24
|
+
)
|
25
|
+
end
|
26
|
+
res.merge(args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def merge_parameters(params)
|
30
|
+
return params unless params.is_a?(Array)
|
31
|
+
|
32
|
+
result = {}
|
33
|
+
params.each do |item|
|
34
|
+
item.each do |key, value|
|
35
|
+
if result.key?(key)
|
36
|
+
result[key] = result[key].is_a?(Array) ? result[key] << value : [result[key], value]
|
37
|
+
else
|
38
|
+
result[key] = value
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,399 @@
|
|
1
|
+
require "pubid-iso"
|
2
|
+
|
3
|
+
module Pubid::Ieee
|
4
|
+
class Parser < Parslet::Parser
|
5
|
+
rule(:digits) do
|
6
|
+
match('\d').repeat(1)
|
7
|
+
end
|
8
|
+
|
9
|
+
rule(:space) { str(" ") }
|
10
|
+
rule(:space?) { space.maybe }
|
11
|
+
rule(:comma) { str(", ") }
|
12
|
+
rule(:comma?) { comma.maybe }
|
13
|
+
rule(:comma_space) { comma | space }
|
14
|
+
rule(:dash) { str("-") }
|
15
|
+
rule(:dot) { str(".") }
|
16
|
+
rule(:words_digits) { match('[\dA-Za-z]').repeat(1) }
|
17
|
+
rule(:words) { match("[A-Za-z]").repeat(1) }
|
18
|
+
rule(:words?) { words.maybe }
|
19
|
+
rule(:year_digits) { (str("19") | str("20")) >> match('\d').repeat(2, 2) }
|
20
|
+
|
21
|
+
rule(:month_digits) do
|
22
|
+
match('\d').repeat(2, 2)
|
23
|
+
end
|
24
|
+
|
25
|
+
rule(:day_digits) do
|
26
|
+
match('\d').repeat(2, 2)
|
27
|
+
end
|
28
|
+
|
29
|
+
rule(:year) do
|
30
|
+
# -2014, April 2015
|
31
|
+
dash >> year_digits.as(:adoption_year) >> publication_date |
|
32
|
+
(dot | dash) >> year_digits.as(:year) >> str("(E)").maybe
|
33
|
+
end
|
34
|
+
|
35
|
+
rule(:organization) do
|
36
|
+
str("IEEE") | str("AIEE") | str("ANSI") | str("ASA") | str("NCTA") |
|
37
|
+
str("IEC") | str("ISO") | str("ASTM") | str("NACE") | str("NSF")
|
38
|
+
end
|
39
|
+
|
40
|
+
rule(:number) do
|
41
|
+
str("D").absent? >> ((digits | match("[A-Z]")).repeat(1) >> match("[a-z]").maybe).as(:number)
|
42
|
+
end
|
43
|
+
|
44
|
+
rule(:type) do
|
45
|
+
str("Std") | str("STD") | str("Standard")
|
46
|
+
end
|
47
|
+
|
48
|
+
rule(:comma_month_year) do
|
49
|
+
comma >> words.as(:month) >> space >> year_digits.as(:year)
|
50
|
+
end
|
51
|
+
|
52
|
+
rule(:edition) do
|
53
|
+
(comma >> year_digits.as(:year) >> str(" Edition")) |
|
54
|
+
((space | dash) >> str("Edition ") >> (digits >> dot >> digits).as(:version) >> (str(" - ") | space) >>
|
55
|
+
year_digits.as(:year) >> (dash >>
|
56
|
+
month_digits.as(:month)).maybe) |
|
57
|
+
#, February 2018 (E)
|
58
|
+
(comma_month_year >> str("(E)")) |
|
59
|
+
# (comma_month_year >> space? >> str("(E)")) |
|
60
|
+
# comma_month_year |
|
61
|
+
# First edition 2002-11-01
|
62
|
+
space >> str("First").as(:version) >>
|
63
|
+
str(" edition ") >>
|
64
|
+
year_digits.as(:year) >> dash >>
|
65
|
+
month_digits.as(:month) >> (dash >>
|
66
|
+
day_digits.as(:day)).maybe
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
rule(:draft_status) do
|
71
|
+
(str("Active Unapproved") | str("Unapproved") | str("Approved")).as(:draft_status)
|
72
|
+
end
|
73
|
+
|
74
|
+
rule(:draft_prefix) do
|
75
|
+
space? >> str("/") | str("_") | dash | space
|
76
|
+
end
|
77
|
+
|
78
|
+
rule(:draft_date) do
|
79
|
+
((space? >> comma | space) >> words.as(:month)).maybe >>
|
80
|
+
(
|
81
|
+
((space >> digits.as(:day)).maybe >> comma >> year_digits.as(:year)) |
|
82
|
+
(comma_space >> match('\d').repeat(2, 4).as(:year))
|
83
|
+
)
|
84
|
+
end
|
85
|
+
|
86
|
+
rule(:draft_version) do
|
87
|
+
# for D1D2
|
88
|
+
(str("D") >> digits.as(:version)).repeat(2) |
|
89
|
+
# for DD3, D3Q
|
90
|
+
(str("D") >> words_digits.as(:version)).repeat(1, 1)
|
91
|
+
end
|
92
|
+
|
93
|
+
rule(:draft) do
|
94
|
+
# /D14, April 2020
|
95
|
+
# /D7 November, 2019
|
96
|
+
(draft_prefix >> draft_version >>
|
97
|
+
((dot | str("r")) >> (digits >> words?).as(:revision)).maybe >>
|
98
|
+
draft_date.maybe).as(:draft)
|
99
|
+
end
|
100
|
+
|
101
|
+
rule(:part) do
|
102
|
+
((dot | dash) >> words_digits).as(:part)
|
103
|
+
end
|
104
|
+
|
105
|
+
rule(:subpart) do
|
106
|
+
(dot | dash) >> match('[\da-z]').repeat(1)
|
107
|
+
end
|
108
|
+
|
109
|
+
rule(:part_subpart_year) do
|
110
|
+
# 802.15.22.3-2020
|
111
|
+
# 1073.1.1.1-2004
|
112
|
+
(part >> subpart.repeat(2, 2).as(:subpart) >> year) |
|
113
|
+
# C57.12.00-1993
|
114
|
+
(part >> subpart.as(:subpart) >> year) |
|
115
|
+
# N42.44-2008
|
116
|
+
# 1244-5.2000
|
117
|
+
# 11073-40102-2020
|
118
|
+
# C37.0781-1972
|
119
|
+
(part >> year) |
|
120
|
+
# C57.19.101
|
121
|
+
(part >> subpart.as(:subpart)) |
|
122
|
+
# IEC 62525-Edition 1.0 - 2007
|
123
|
+
edition.as(:edition) |
|
124
|
+
# IEEE P11073-10101
|
125
|
+
# IEEE P11073-10420/D4D5
|
126
|
+
# IEEE Unapproved Draft Std P11073-20601a/D13, Jan 2010
|
127
|
+
# XXX: hack to avoid being partially parsed by year
|
128
|
+
(dash >> match('[\dA-Za-z]').repeat(5, 6)).as(:part) |
|
129
|
+
# 581.1978
|
130
|
+
year |
|
131
|
+
# 61691-6
|
132
|
+
part
|
133
|
+
end
|
134
|
+
|
135
|
+
rule(:dual_pubids) do
|
136
|
+
space? >>
|
137
|
+
(
|
138
|
+
(str("(") >> (iso_identifier >> iso_parameters).as(:alternative) >> str(")") |
|
139
|
+
str("(") >> (parameters(organizations >> space?).as(:alternative) >> str(", ").maybe).repeat(1) >> str(")")) |
|
140
|
+
((str("and ") | str("/ ") | space) >> identifier_no_params.as(:alternative)) |
|
141
|
+
(str("/") >> identifier_with_organization.as(:alternative)) |
|
142
|
+
# should have an organization when no brackets
|
143
|
+
identifier_with_organization.as(:alternative)
|
144
|
+
)
|
145
|
+
end
|
146
|
+
|
147
|
+
rule(:dual_pubid_without_parameters) do
|
148
|
+
space? >>
|
149
|
+
(
|
150
|
+
(str("(") >> (iso_identifier >> iso_parameters).as(:alternative) >> str(")") |
|
151
|
+
str("(") >> (identifier_no_params.as(:alternative) >> str(", ").maybe).repeat(1) >> str(")"))# |
|
152
|
+
#identifier_no_params.as(:alternative)
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
156
|
+
rule(:revision) do
|
157
|
+
(str("Revision ") >> (str("of") | str("to")) >> space >>
|
158
|
+
(identifier_without_dual_pubids.as(:identifier) >> str(" and ").maybe).repeat(1)
|
159
|
+
).as(:revision)
|
160
|
+
end
|
161
|
+
|
162
|
+
rule(:previous_amendments) do
|
163
|
+
# IEEE P802.3bp/D3.4, April 2016 (Amendment of IEEE Std 802.3-2015 as amended by IEEE Std 802.3bw-2015,
|
164
|
+
# IEEE Std 802.3by-201X, and IEEE Std 802.3bq-201X)
|
165
|
+
str(",").maybe >> str(" as amended by ") >>
|
166
|
+
(identifier_inside_brackets.as(:identifier) >> (str(", ") >> str("and ").maybe).maybe).repeat(1)
|
167
|
+
end
|
168
|
+
|
169
|
+
# match everything before "," or ")" or " as"
|
170
|
+
rule(:identifier_inside_brackets) do
|
171
|
+
((str(" as") | str(")") | str(",")).absent? >> any).repeat(1) >>
|
172
|
+
(str(", ") >> year_digits >> str(" Edition")).maybe
|
173
|
+
end
|
174
|
+
|
175
|
+
rule(:amendment) do
|
176
|
+
(str("Amendment ") >> (str("of") | str("to")) >> space >>
|
177
|
+
identifier_inside_brackets.as(:identifier) >> previous_amendments.maybe).as(:amendment)
|
178
|
+
end
|
179
|
+
|
180
|
+
rule(:number_prefix) do
|
181
|
+
((str("No") | str("no")) >> (str(". ") | dot | space)).maybe
|
182
|
+
end
|
183
|
+
|
184
|
+
rule(:redline) do
|
185
|
+
str(" - ") >> str("Redline").as(:redline)
|
186
|
+
end
|
187
|
+
|
188
|
+
rule(:publication_date) do
|
189
|
+
comma_month_year
|
190
|
+
end
|
191
|
+
|
192
|
+
rule(:supersedes) do
|
193
|
+
(str("Supersedes ") >> (identifier_without_dual_pubids.as(:identifier) >>
|
194
|
+
(str(" and ") | str(" ")).maybe).repeat(1)).as(:supersedes)
|
195
|
+
end
|
196
|
+
|
197
|
+
rule(:incorporates) do
|
198
|
+
(
|
199
|
+
match("[Ii]") >> (str("ncorporates ") | str("ncorporating ")) >>
|
200
|
+
(identifier_without_dual_pubids.as(:identifier) >> str(", and ").maybe).repeat(1)
|
201
|
+
).as(:incorporates)
|
202
|
+
end
|
203
|
+
|
204
|
+
rule(:supplement) do
|
205
|
+
(str("Supplement") >> str("s").maybe >> str(" to ") >> identifier_without_dual_pubids.as(:identifier)).as(:supplement)
|
206
|
+
end
|
207
|
+
|
208
|
+
rule(:additional_parameters) do
|
209
|
+
(space? >> str("(") >> (
|
210
|
+
(reaffirmed | revision | amendment | supersedes | corrigendum_comment| incorporates | supplement) >>
|
211
|
+
((str("/") | str(",")) >> space?).maybe).repeat >> str(")").maybe
|
212
|
+
).repeat >> redline.maybe
|
213
|
+
end
|
214
|
+
|
215
|
+
# Hack to exclude dual_pubids parsing for revisions and supersedes
|
216
|
+
# otherwise extra identifiers parsed as dual PubIDs to the main identifier
|
217
|
+
def parameters(atom, without_dual_pubids: false, skip_parameters: false)
|
218
|
+
atom >>
|
219
|
+
((draft_status >> space).maybe >> (str("Draft ").maybe >>
|
220
|
+
type.as(:type) >> space.maybe).maybe).as(:type_status) >>
|
221
|
+
number_prefix >> number >>
|
222
|
+
(
|
223
|
+
# IEEE P2410-D4, July 2019
|
224
|
+
(draft |
|
225
|
+
part_subpart_year.maybe >> corrigendum.maybe >> draft.maybe >> iso_amendment.maybe
|
226
|
+
) >>
|
227
|
+
if skip_parameters
|
228
|
+
str("")
|
229
|
+
else
|
230
|
+
publication_date.maybe
|
231
|
+
end >>
|
232
|
+
if skip_parameters
|
233
|
+
str("")
|
234
|
+
else
|
235
|
+
edition.as(:edition).maybe
|
236
|
+
end >>
|
237
|
+
# dual-PubIDs
|
238
|
+
((without_dual_pubids && str("")) || dual_pubids.maybe) >>
|
239
|
+
if skip_parameters
|
240
|
+
str("")
|
241
|
+
else
|
242
|
+
additional_parameters.maybe
|
243
|
+
end
|
244
|
+
).as(:parameters)
|
245
|
+
end
|
246
|
+
|
247
|
+
rule(:reaffirmed) do
|
248
|
+
(
|
249
|
+
(str("Reaffirmed ") >> year_digits.as(:year) |
|
250
|
+
str("Reaffirmation of ") >> identifier.as(:identifier).as(:reaffirmation_of))
|
251
|
+
).as(:reaffirmed)
|
252
|
+
end
|
253
|
+
|
254
|
+
rule(:corrigendum_prefix) do
|
255
|
+
(str("_") | str("/") | str("-")) >> str("Cor") >> (str("-") | dot.maybe >> space?)
|
256
|
+
end
|
257
|
+
|
258
|
+
rule(:corrigendum) do
|
259
|
+
# IEEE 1672-2006/Cor 1-2008
|
260
|
+
(
|
261
|
+
corrigendum_prefix >> digits.as(:version) >> ((dash | str(":")) >> year_digits.as(:year)).maybe
|
262
|
+
).as(:corrigendum)
|
263
|
+
end
|
264
|
+
|
265
|
+
rule(:corrigendum_comment) do
|
266
|
+
((str("Corrigendum to ") | str("Corrigenda ") >> (str("to ") | str("of "))) >>
|
267
|
+
identifier.as(:identifier)).as(:corrigendum_comment)
|
268
|
+
end
|
269
|
+
|
270
|
+
rule(:iso_amendment_prefix) do
|
271
|
+
str("/") >> str("Amd")
|
272
|
+
end
|
273
|
+
|
274
|
+
rule(:iso_amendment) do
|
275
|
+
# IEEE 1672-2006/Cor 1-2008
|
276
|
+
(iso_amendment_prefix >> digits.as(:version) >> (dash >> year_digits.as(:year)).maybe).as(:iso_amendment)
|
277
|
+
end
|
278
|
+
|
279
|
+
rule(:organizations) do
|
280
|
+
(organization.as(:publisher) >> (str("/") >> space? >> organization.as(:copublisher)).repeat)
|
281
|
+
.as(:organizations)
|
282
|
+
end
|
283
|
+
|
284
|
+
rule(:identifier_with_organization) do
|
285
|
+
parameters(organizations >> space?)
|
286
|
+
end
|
287
|
+
|
288
|
+
rule(:identifier_with_org_no_params) do
|
289
|
+
iso_identifier | parameters(organizations >> space?, skip_parameters: true)
|
290
|
+
end
|
291
|
+
|
292
|
+
rule(:identifier_no_params) do
|
293
|
+
parameters((organizations >> space).maybe, skip_parameters: true, without_dual_pubids: true)
|
294
|
+
end
|
295
|
+
|
296
|
+
rule(:iso_part) do
|
297
|
+
(str("-") | str("/")) >> str(" ").maybe >>
|
298
|
+
# (str("-") >> iso_parser.stage).absent? >>
|
299
|
+
((match('\d') | str("A")) >>
|
300
|
+
((str("-") >> iso_parser.typed_stage).absent? >>
|
301
|
+
(match['\d[A-Z]'] | str("-"))).repeat).as(:part)
|
302
|
+
end
|
303
|
+
|
304
|
+
rule(:iso_part_stage_iteration) do
|
305
|
+
iso_part >>
|
306
|
+
(str("-") >> iso_parser.typed_stage.as(:stage)) >> iso_parser.iteration.maybe
|
307
|
+
end
|
308
|
+
|
309
|
+
rule(:iso_stage_part_iteration) do
|
310
|
+
# don't consume draft from IEEE format
|
311
|
+
((str("-") | str("/")) >> (str("D") >> digits).absent? >> (iso_parser.typed_stage.as(:stage) | iso_parser.stage.as(:stage))) >>
|
312
|
+
iso_part.maybe >> iso_parser.iteration.maybe
|
313
|
+
end
|
314
|
+
|
315
|
+
# add rule when don't have stage
|
316
|
+
#
|
317
|
+
rule(:iso_part_iteration) do
|
318
|
+
iso_part >> iso_parser.iteration.maybe
|
319
|
+
end
|
320
|
+
|
321
|
+
rule(:iso_part_stage_iteration_matcher) do
|
322
|
+
# consumes "/"
|
323
|
+
iso_stage_part_iteration |
|
324
|
+
iso_part_stage_iteration |
|
325
|
+
iso_part_iteration
|
326
|
+
|
327
|
+
end
|
328
|
+
|
329
|
+
rule(:iso_identifier) do
|
330
|
+
# Pubid::Iso::Parser.new.identifier.as(:iso_identifier)
|
331
|
+
# Withdrawn e.g: WD/ISO 10360-5:2000
|
332
|
+
# for French and Russian PubIDs starting with Guide type
|
333
|
+
((iso_parser.guide_prefix.as(:type) >> str(" ")).maybe >>
|
334
|
+
(iso_parser.typed_stage.as(:stage) >> str(" ")).maybe >>
|
335
|
+
iso_parser.originator >> ((str(" ") | str("/")) >>
|
336
|
+
# for ISO/FDIS
|
337
|
+
(iso_parser.type | iso_parser.typed_stage.as(:stage))).maybe >>
|
338
|
+
# for ISO/IEC WD TS 25025
|
339
|
+
str(" ").maybe >> ((iso_parser.typed_stage.as(:stage) | iso_parser.stage.as(:stage) | iso_parser.type) >> str(" ")).maybe >>
|
340
|
+
(str("P").maybe >> iso_parser.digits).as(:number) >>
|
341
|
+
# for identifiers like ISO 5537/IDF 26
|
342
|
+
(str("|") >> (str("IDF") >> str(" ") >> digits).as(:joint_document)).maybe >>
|
343
|
+
iso_part_stage_iteration_matcher.maybe >>
|
344
|
+
(str(" ").maybe >> str(":") >> iso_parser.year).maybe >>
|
345
|
+
# stage before amendment
|
346
|
+
(
|
347
|
+
# stage before corrigendum
|
348
|
+
iso_parser.supplement.maybe) >>
|
349
|
+
iso_parser.language.maybe).as(:iso_identifier)
|
350
|
+
end
|
351
|
+
|
352
|
+
rule(:iso_parameters) do
|
353
|
+
iso_amendment.maybe >> (dual_pubid_without_parameters.maybe >>
|
354
|
+
(publication_date >> space? >> str("(E)").maybe).maybe >>
|
355
|
+
edition.as(:edition).maybe >> draft.maybe >> additional_parameters).as(:parameters)
|
356
|
+
end
|
357
|
+
|
358
|
+
rule(:identifier_before_edition) do
|
359
|
+
((str(" Edition")).absent? >> any).repeat(1)
|
360
|
+
end
|
361
|
+
|
362
|
+
rule(:identifier) do
|
363
|
+
iso_or_ieee_identifier
|
364
|
+
# (identifier_before_edition.as(:iso_identifier).as(:iso_identifier) >> iso_parameters) |
|
365
|
+
end
|
366
|
+
|
367
|
+
rule(:ieee_without_prefix) do
|
368
|
+
(str("IEEE").as(:publisher).as(:organizations) >> space) >>
|
369
|
+
digits.as(:number) >> str(".").absent? >> year.as(:parameters)
|
370
|
+
end
|
371
|
+
|
372
|
+
rule(:iso_or_ieee_identifier) do
|
373
|
+
ieee_without_prefix |
|
374
|
+
(iso_identifier >> iso_parameters) |
|
375
|
+
# (iso identifier) >> space >> (ieee identifier) ?
|
376
|
+
iso_identifier >> space >> parameters((organizations >> space).maybe) | iso_identifier |
|
377
|
+
parameters((organizations >> space).maybe)
|
378
|
+
end
|
379
|
+
|
380
|
+
rule(:parameters_with_optional_organizations) do
|
381
|
+
parameters((organizations >> space).maybe)
|
382
|
+
end
|
383
|
+
|
384
|
+
rule(:identifier_without_dual_pubids) do
|
385
|
+
iso_identifier >> iso_parameters |
|
386
|
+
parameters((organizations >> space).maybe, without_dual_pubids: true)
|
387
|
+
end
|
388
|
+
|
389
|
+
rule(:identifier_without_parameters) do
|
390
|
+
parameters((organizations >> space).maybe, skip_parameters: true)
|
391
|
+
end
|
392
|
+
|
393
|
+
rule(:root) { identifier }
|
394
|
+
|
395
|
+
def iso_parser
|
396
|
+
Pubid::Iso::Parser.new
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Pubid::Ieee
|
2
|
+
class Transformer < Parslet::Transform
|
3
|
+
rule(month: simple(:month), year: simple(:year)) do |date|
|
4
|
+
update_month_year(date[:month], date[:year])
|
5
|
+
end
|
6
|
+
|
7
|
+
rule(month: simple(:month), year: simple(:year), day: simple(:day)) do |date|
|
8
|
+
update_month_year(date[:month], date[:year]).merge({ day: date[:day] })
|
9
|
+
end
|
10
|
+
|
11
|
+
rule(identifier: subtree(:identifier)) do |data|
|
12
|
+
if data[:identifier].is_a?(Parslet::Slice)
|
13
|
+
Identifier::Base.transform(Identifier.convert_parser_parameters(**Parser.new.iso_or_ieee_identifier.parse(data[:identifier].to_s)))
|
14
|
+
else
|
15
|
+
Identifier::Base.transform(Identifier.convert_parser_parameters(**data[:identifier]))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.update_month_year(month, year)
|
20
|
+
{ year: if year.length == 2
|
21
|
+
case year.to_i
|
22
|
+
when 0..25 then "20#{year}"
|
23
|
+
when 26..99 then "19#{year}"
|
24
|
+
end
|
25
|
+
else
|
26
|
+
year
|
27
|
+
end,
|
28
|
+
month: Date.parse(month).strftime("%B") }
|
29
|
+
end
|
30
|
+
|
31
|
+
rule(type: simple(:type)) do
|
32
|
+
{ type: case type
|
33
|
+
when "Standard"
|
34
|
+
:std
|
35
|
+
else
|
36
|
+
type
|
37
|
+
end }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pubid::Ieee
|
2
|
+
class Type
|
3
|
+
attr_accessor :type
|
4
|
+
|
5
|
+
TYPE_NAMES = {
|
6
|
+
std: {
|
7
|
+
long: "Standard",
|
8
|
+
full: "Std ",
|
9
|
+
short: "Std ",
|
10
|
+
match: %w[STD Std Standard],
|
11
|
+
alternative: "",
|
12
|
+
},
|
13
|
+
draft: {
|
14
|
+
full: "Draft Std ",
|
15
|
+
short: "Draft Std ",
|
16
|
+
match: %w[Draft],
|
17
|
+
alternative: "Draft ",
|
18
|
+
},
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
# Create new type
|
22
|
+
# @param type [Symbol]
|
23
|
+
def initialize(type = :std)
|
24
|
+
type = type.to_s.downcase.to_sym unless type.is_a?(Symbol)
|
25
|
+
|
26
|
+
raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type)
|
27
|
+
|
28
|
+
@type = type
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.parse(type_string)
|
32
|
+
TYPE_NAMES.each do |type, values|
|
33
|
+
return new(type) if values[:match].include?(type_string)
|
34
|
+
end
|
35
|
+
raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type"
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s(format = :short)
|
39
|
+
TYPE_NAMES[type][format]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/pubid/ieee.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "parslet"
|
2
|
+
|
3
|
+
module Pubid
|
4
|
+
module Ieee
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require_relative "ieee/errors"
|
10
|
+
require_relative "ieee/parser"
|
11
|
+
require_relative "ieee/transformer"
|
12
|
+
require_relative "ieee/type"
|
13
|
+
require_relative "ieee/identifier"
|
14
|
+
require_relative "ieee/identifier/base"
|
15
|
+
|
16
|
+
config = Pubid::Core::Configuration.new
|
17
|
+
config.default_type = Pubid::Ieee::Identifier::Base
|
18
|
+
config.types = [Pubid::Ieee::Identifier::Base]
|
19
|
+
Pubid::Ieee::Identifier.set_config(config)
|
data/lib/pubid-ieee.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "pubid/ieee"
|
data/update_codes.yaml
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
IEEE Unapproved Draft Std PC37.110/D911Oct 07: IEEE Unapproved Draft Std PC37.110/D711, Oct 07
|
2
|
+
IEEE C57.139/D14June 2010: IEEE C57.139/D14, June 2010
|
3
|
+
IEEE P1653.5/D7d1 November, 2019: IEEE P1653.5/D7.1 November, 2019
|
4
|
+
IEEE P1017/D062012: P1017/D062012, Jun 2012
|
5
|
+
IEEP62.42.1/D3, October 2014: IEEE P62.42.1/D3, October 2014
|
6
|
+
IEEE P802.11ajD8.0, August 2017: IEEE P802.11aj/D8.0, August 2017
|
7
|
+
IEEE P802.11ajD9.0, November 2017: IEEE P802.11aj/D9.0, November 2017
|
8
|
+
"IEC 62529:2012(E) (IEEE Std 1641-2010": IEC 62529:2012(E) (IEEE Std 1641-2010)
|
9
|
+
"IEC 62529:2012(E) (IEEE Std 1641-2010 - Redline": IEC 62529:2012(E) (IEEE Std 1641-2010) - Redline
|
10
|
+
IEEE IEEE P1453/D3, June 2011: IEEE P1453/D3, June 2011
|
11
|
+
AIEE No 1E -1957: AIEE No 1E-1957
|
12
|
+
A.I.E.E. No. 15 May-1928: AIEE No 15-192805
|
13
|
+
AIEE No 45 -1951: AIEE No 45-1951
|
14
|
+
AIEE No. 2-June 1929: AIEE No 2-192906
|
15
|
+
AIEE No. 25-1952 (Supercedes AIEE No. 25-1945): AIEE No 25-1952 (Supercedes AIEE No. 25-1945)
|
16
|
+
AIEE No.1-1962 (Supersedes June 1957 issue): AIEE No 1-1962 (Supersedes AIEE No 1-195706)
|
17
|
+
AIEE Nos 72 and 73 - 1932: AIEE No 72-1932 and AIEE No 73-1932
|
18
|
+
EEE Std 1671.1-2017 (Revision of IEEE Std 1671.1&#8208;2009): IEEE Std 1671.1-2017 (Revision of IEEE Std 1671.1-2009)
|
19
|
+
EEE Std 1671.1-2017 (Revision of IEEE Std 1671.1-2009): IEEE Std 1671.1-2017 (Revision of IEEE Std 1671.1-2009)
|
20
|
+
EEE Std 488.2-1992: IEEE Std 488.2-1992
|
21
|
+
EEE Std 802.3br-2016 (Amendment to IEEE Std 802.3-2015 as amended by IEEE St802.3bw-2015, IEEE Std 802.3by-2016, IEEE Std 802.3bq-2016, and IEEE Std 802.3bp-2016): IEEE Std 802.3br-2016 (Amendment to IEEE Std 802.3-2015 as amended by IEEE Std 802.3bw-2015, IEEE Std 802.3by-2016, IEEE Std 802.3bq-2016, and IEEE Std 802.3bp-2016)
|
22
|
+
IEEE Std 336-2010 (Revision of EEE Std 336-2005): IEEE Std 336-2010 (Revision of IEEE Std 336-2005)
|
23
|
+
IEEE Std 356-2020 (Revision of IEEE Std 356?2010): IEEE Std 356-2020 (Revision of IEEE Std 356-2010)
|
24
|
+
IEEE Std 356-2020 (Revision of IEEE Std 356?2010) - Redline: IEEE Std 356-2020 (Revision of IEEE Std 356-2010) - Redline
|
25
|
+
IEEE Std Std 1139-2008: IEEE Std 1139-2008
|
26
|
+
IEEE/ ASTM SI 10-2010 (Revision of IEEE/ASTM SI 10-2002): IEEE/ASTM SI 10-2010 (Revision of IEEE/ASTM SI 10-2002)
|
27
|
+
"IEEE Std 24748-3:2012": IEEE 24748-3:2012
|
28
|
+
"ISO/IEC/IEEE P24765/D3:2017": ISO/IEC/IEEE P24765:2017/D3
|
29
|
+
ISO/IEC/IEEE FDIS P24765 FDIS, October 2016: ISO/IEC/IEEE FDIS P24765, October 2016
|
30
|
+
ISO/IEC/IEEE P15289 FDIS, February 2019: ISO/IEC/IEEE FDIS P15289, February 2019
|
31
|
+
ISO/IEC/IEEE P26515 FDIS, May 2018: ISO/IEC/IEEE FDIS P26515, May 2018
|
32
|
+
IEEE Std Std 1139-2008: IEEE Std 1139-2008
|
33
|
+
IEC/IEEE P60214-2, FDIS 2018: IEC/IEEE FDIS P60214-2-2018(E)
|
34
|
+
IEC/IEEE P62582-6, FDIS 2018: IEC/IEEE FDIS P62582-6-2018(E)
|
35
|
+
ISO/IEC DIS P26511.2, May 2017: ISO/IEC DIS P26511-2, May 2017
|
36
|
+
ISO/IEC/IEEE P90003_FDIS, August 2018: ISO/IEC/IEEE FDIS P90003, August 2018
|
37
|
+
ISO/IEC/IEEE P29119-1/FDIS, September 2021: ISO/IEC/IEEE FDIS P29119-1, September 2021
|
38
|
+
ISO/IEC/IEEE/ P12207-2/D3_FDIS, July 2020: ISO/IEC/IEEE FDIS P12207-2/D3, July 2020
|
39
|
+
ISO/IEC/IEEE/ P21841/FDIS, April 2019: ISO/IEC/IEEE FDIS P21841, April 2019
|
40
|
+
ISO/IEC/IEEE/ P24748-3/DIS, August 2019: ISO/IEC/IEEE DIS P24748-3, August 2019
|
41
|
+
IEEE Std 1018-2013 (Revison of IEEE Std 1018-2004): IEEE Std 1018-2013 (Revision of IEEE Std 1018-2004)
|
42
|
+
IEEE Std 1018-2013 (Revison of IEEE Std 1018-2004) - Redline: IEEE Std 1018-2013 (Revision of IEEE Std 1018-2004) - Redline
|
43
|
+
IEEE SId 342-1973 (ANSI C37.0731-1973): IEEE Std 342-1973 (ANSI C37.0731-1973)
|
44
|
+
P1484.12.3/D1, September2019: IEEE P1484.12.3/D1, September 2019
|
45
|
+
P1073.1.3.4/D3.0: IEEE P1073.1.3.4/D3.0
|
46
|
+
P1936.1, 2020: IEEE P1936.1, January 2020
|
47
|
+
P20000-2, D1 December 2012: IEEE P20000-2/D1, December 2012
|
48
|
+
ISO/IEC/IEEE 8802-22.2:2015/Amd.2:2017(E): ISO/IEC/IEEE 8802-22:2015/Amd.2:2017(E)
|
49
|
+
IEEE 1070-1995: IEEE No 1070-1995
|
50
|
+
IEEE 278-1967: IEEE No 278-1967
|
51
|
+
IEEE 730-1989: IEEE No 730-1989
|
52
|
+
IEEE 751-1991: IEEE No 751-1991
|
53
|
+
IEEE 1023-2020 (Revision of IEEE Std 1023-2004): IEEE No 1023-2020 (Revision of IEEE Std 1023-2004)
|
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pubid-ieee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ribose Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '13.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lightly
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: parslet
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pubid-iso
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.5.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.5.2
|
111
|
+
description: Library to generate, parse and manipulate IEEE PubID.
|
112
|
+
email:
|
113
|
+
- open.source@ribose.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files:
|
117
|
+
- README.adoc
|
118
|
+
- LICENSE.txt
|
119
|
+
files:
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.adoc
|
122
|
+
- lib/pubid-ieee.rb
|
123
|
+
- lib/pubid/ieee.rb
|
124
|
+
- lib/pubid/ieee/errors.rb
|
125
|
+
- lib/pubid/ieee/identifier.rb
|
126
|
+
- lib/pubid/ieee/identifier/base.rb
|
127
|
+
- lib/pubid/ieee/parser.rb
|
128
|
+
- lib/pubid/ieee/transformer.rb
|
129
|
+
- lib/pubid/ieee/type.rb
|
130
|
+
- lib/pubid/ieee/version.rb
|
131
|
+
- update_codes.yaml
|
132
|
+
homepage: https://github.com/metanorma/pubid-ieee
|
133
|
+
licenses:
|
134
|
+
- BSD-2-Clause
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 2.5.0
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubygems_version: 3.0.3.1
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Library to generate, parse and manipulate IEEE PubID.
|
155
|
+
test_files: []
|