pubid-nist 0.2.1 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 385c609c6c253b90710e676e371d6466951a0a4146d0791ad6a16a299a9190d0
4
- data.tar.gz: 3bdf39dc5fecc613eca35cbf74f6026e4e8771c1f89c584406a88c680fbc1f22
3
+ metadata.gz: c7f76d8947ccd706282e78b94eb9c4284671b866acc1630c08a1fdd398dbd73e
4
+ data.tar.gz: 01dfd5d1e8afbe479916a906566406f2d3a7d8d3235053a86be6d0cf1c09de5c
5
5
  SHA512:
6
- metadata.gz: 7c6282be01f402f63283faed9d7a227bc8ed06e77569c7371c50b71566f3ce38e1f04f13a228df4997140858fa7c1c65c147730465fad7231d5930e31cd594f6
7
- data.tar.gz: 07f422c88625fac8bfc24599db548ab0d4e33230f25376a435c6c2731469704c1d75930362f9a03ee0c82d4d3d3a0a64ad21b2a7d41ed1df409b9c30da5efc97
6
+ metadata.gz: 051144f72ccff63f56b875f2bb843750b14b86d3b9014f27ecd15cfd61e084052df6ae44be931a2c9b7a7e63dee3e03a927e4c6123cf6ff3727cb134fcb43340
7
+ data.tar.gz: 7b26bc1e82271f82286079bda318834594dc93eca2ef6e3569109e2323d47c06708404aed1f1dd02aead5a1d03d60efe14d900556696976945fa4778fd2a032a
@@ -4,83 +4,6 @@ require "json"
4
4
 
5
5
  UPDATE_CODES = YAML.load_file(File.join(File.dirname(__FILE__), "../../../update_codes.yaml"))
6
6
 
7
- REVISION_DESC = {
8
- long: ", Revision ",
9
- abbrev: ", Rev. ",
10
- short: "r",
11
- mr: "r",
12
- }.freeze
13
-
14
- VERSION_DESC = {
15
- long: ", Version ",
16
- abbrev: ", Ver. ",
17
- short: "ver",
18
- mr: "ver",
19
- }.freeze
20
-
21
- VOLUME_DESC = {
22
- long: ", Volume ",
23
- abbrev: ", Vol. ",
24
- short: "v",
25
- mr: "v",
26
- }.freeze
27
-
28
- PART_DESC = {
29
- long: " Part ",
30
- abbrev: " Pt. ",
31
- short: "pt",
32
- mr: "pt",
33
- }.freeze
34
-
35
- EDITION_DESC = {
36
- long: " Edition ",
37
- abbrev: " Ed. ",
38
- short: "e",
39
- mr: "e",
40
- }.freeze
41
-
42
- SUPPLEMENT_DESC = {
43
- long: " Supplement ",
44
- abbrev: " Suppl. ",
45
- short: "sup",
46
- mr: "sup",
47
- }.freeze
48
-
49
- SECTION_DESC = {
50
- long: " Section ",
51
- abbrev: " Sec. ",
52
- short: "sec",
53
- mr: "sec",
54
- }.freeze
55
-
56
- APPENDIX_DESC = {
57
- long: " Appendix ",
58
- abbrev: " App. ",
59
- short: "app",
60
- mr: "app",
61
- }.freeze
62
-
63
- ERRATA_DESC = {
64
- long: " Errata ",
65
- abbrev: " Err. ",
66
- short: "err",
67
- mr: "err",
68
- }.freeze
69
-
70
- INDEX_DESC = {
71
- long: " Index ",
72
- abbrev: " Index. ",
73
- short: "indx",
74
- mr: "indx",
75
- }.freeze
76
-
77
- INSERT_DESC = {
78
- long: " Insert ",
79
- abbrev: " Ins. ",
80
- short: "ins",
81
- mr: "ins",
82
- }.freeze
83
-
84
7
  module Pubid::Nist
85
8
  class Identifier < Pubid::Core::Identifier::Base
86
9
  attr_accessor :serie, :code, :revision, :publisher, :version, :volume,
@@ -93,7 +16,7 @@ module Pubid::Nist
93
16
  @publisher = publisher.is_a?(Publisher) ? publisher : Publisher.new(publisher: publisher)
94
17
  @serie = serie.is_a?(Serie) ? serie : Serie.new(serie: serie)
95
18
  @code = number
96
- @stage = Stage.new(stage.to_s) if stage
19
+ @stage = Stage.new(**stage) if stage
97
20
  @supplement = (supplement.is_a?(Array) && "") || supplement
98
21
  @edition = parse_edition(edition_month, edition_year, edition_day) if edition_month || edition_year
99
22
  @update = update
@@ -148,25 +71,11 @@ module Pubid::Nist
148
71
  code
149
72
  end
150
73
 
151
- # def to_s(format = :short)
152
- # result = render_serie(format)
153
- # result += " " unless format == :short || stage.nil?
154
- # result += "#{stage&.to_s(format)}"\
155
- # " #{code}#{render_part(format)}#{render_edition(format)}"\
156
- # "#{render_localities(format)}"\
157
- # "#{render_update(format)}#{render_translation(format)}"
158
- # result = render_addendum(result, format)
159
- #
160
- # return result.gsub(" ", ".") if format == :mr
161
- #
162
- # result
163
- # end
164
-
165
- def to_s(format = :short)
166
- self.class.get_renderer_class.new(get_params).render(format: format)
74
+ # @param without_edition [Boolean] render pubid without rendering edition
75
+ def to_s(format = :short, without_edition: false)
76
+ self.class.get_renderer_class.new(get_params).render(format: format, without_edition: without_edition)
167
77
  end
168
78
 
169
-
170
79
  def to_json(*args)
171
80
  result = {
172
81
  styles: {
@@ -184,104 +93,6 @@ module Pubid::Nist
184
93
  result.to_json(*args)
185
94
  end
186
95
 
187
- def render_serie(format)
188
- if serie.to_s(format).include?(publisher.to_s(format))
189
- return serie.to_s(format)
190
- end
191
-
192
- "#{publisher.to_s(format)} #{serie.to_s(format)}"
193
- end
194
-
195
- def render_part(format)
196
- result = ""
197
- result += "#{VOLUME_DESC[format]}#{volume}" unless volume.nil?
198
- result += "#{PART_DESC[format]}#{part}" unless part.nil?
199
- result
200
- end
201
-
202
- def render_edition(format)
203
- result = ""
204
-
205
- result += "#{EDITION_DESC[format]}#{edition.to_s}" unless edition.nil?
206
- result += "#{REVISION_DESC[format]}#{revision == '' ? '1' : revision}" if revision
207
- result += "#{VERSION_DESC[format]}#{version}" unless version.nil?
208
- result
209
- end
210
-
211
- def render_localities(format)
212
- result = ""
213
- result += "#{SUPPLEMENT_DESC[format]}#{supplement}" unless supplement.nil?
214
- result += "#{SECTION_DESC[format]}#{section}" unless section.nil?
215
- result += "#{APPENDIX_DESC[format]}" unless appendix.nil?
216
- result += "#{ERRATA_DESC[format]}" unless errata.nil?
217
- result += INDEX_DESC[format] unless index.nil?
218
- result += INSERT_DESC[format] unless insert.nil?
219
-
220
- result
221
- end
222
-
223
- def render_update(format)
224
- return "" if update_year.nil?
225
-
226
- if update_month && update_number.nil?
227
- @update_number = "1"
228
- end
229
-
230
- if update_year&.length == 2
231
- @update_year = "19#{update_year}"
232
- end
233
-
234
- if update_number.match?(/\d+/)
235
- update_text = update_number
236
- update_text += "-#{update_year}" if update_year && !update_year.empty?
237
- if update_month
238
- date = Date.parse("01/#{update_month}/#{update_year}")
239
- update_text += sprintf("%02d", date.month)
240
- end
241
- else
242
- update_text = "1"
243
- end
244
-
245
- case format
246
- when :long
247
- " Update #{update_text}"
248
- when :abbrev
249
- " Upd. #{update_text}"
250
- when :short
251
- "/Upd#{update_text}"
252
- when :mr
253
- ".u#{update_text}"
254
- end
255
- end
256
-
257
- def render_translation(format)
258
- return "" if translation.nil?
259
-
260
- case format
261
- when :long, :abbrev
262
- " (#{translation.upcase})"
263
- when :mr
264
- ".#{translation}"
265
- when :short
266
- "(#{translation})"
267
- end
268
- end
269
-
270
- def render_addendum(input, format)
271
- return input unless addendum
272
-
273
- case format
274
- when :long
275
- "Addendum to #{input}"
276
- when :abbrev
277
- "Add. to #{input}"
278
- when :short
279
- "#{input} Add."
280
- when :mr
281
- "#{input}.add-1"
282
- end
283
- end
284
-
285
96
  class << self
286
97
  def create(**opts)
287
98
  new(**opts)
@@ -2,14 +2,15 @@ module Pubid::Nist
2
2
  module Parsers
3
3
  class Default < Pubid::Core::Parser
4
4
  rule(:identifier) do
5
- stage.maybe >> (str(" ") | str(".")) >> report_number >> parts.repeat
5
+ old_stage.maybe >> (str(" ") | str(".")) >> report_number >>
6
+ parts.repeat >> draft.maybe >> stage.maybe >> translation.maybe
6
7
  end
7
8
 
8
9
  rule(:month_letters) { match('[A-Za-z]').repeat(3, 3) }
9
10
  rule(:number_suffix) { match("[aA-Z]") }
10
11
 
11
12
  rule(:parts) do
12
- (edition | revision | version | volume | part | update | addendum | translation |
13
+ (edition | revision | version | volume | part | update | addendum |
13
14
  supplement | errata | index | insert | section | appendix)
14
15
  end
15
16
 
@@ -33,10 +34,17 @@ module Pubid::Nist
33
34
  (str("insert") | str("ins")).as(:insert)
34
35
  end
35
36
 
37
+ rule(:old_stage) do
38
+ (str("(") >> (array_to_str(STAGES["id"].keys.map(&:upcase)).as(:id) >>
39
+ array_to_str(STAGES["type"].keys.map(&:upcase)).as(:type)).as(:stage) >> str(")"))
40
+ end
41
+
36
42
  rule(:stage) do
37
- (str("(") >> (STAGES.keys.reduce do |acc, s|
38
- (acc.is_a?(String) ? str(acc) : acc) | str(s)
39
- end).as(:stage) >> str(")"))
43
+ (space >> (array_to_str(STAGES["id"].keys).as(:id) >> array_to_str(STAGES["type"].keys).as(:type)).as(:stage))
44
+ end
45
+
46
+ rule(:draft) do
47
+ space >> str("(Draft)").as(:draft)
40
48
  end
41
49
 
42
50
  rule(:digits_with_suffix) do
@@ -80,7 +88,7 @@ module Pubid::Nist
80
88
 
81
89
  rule(:translation) do
82
90
  (str("(") >> match('\w').repeat(3, 3).as(:translation) >> str(")")) |
83
- (str(".") >> match('\w').repeat(3, 3).as(:translation))
91
+ ((str(".") | space) >> match('\w').repeat(3, 3).as(:translation))
84
92
  end
85
93
 
86
94
  rule(:edition_prefixes) { str("e") }
@@ -3,6 +3,7 @@ require_relative "nbs_hb"
3
3
  module Pubid::Nist
4
4
  module Parsers
5
5
  class NistHb < NbsHb
6
+ rule(:number_suffix) { match("[a-zA-Z]") }
6
7
  end
7
8
  end
8
9
  end
@@ -7,9 +7,16 @@ module Pubid::Nist
7
7
  end
8
8
 
9
9
  def render_identifier(params, opts)
10
- result = "%{serie}%{stage}%{code}%{volume}%{part}%{edition}%{revision}%{version}"\
11
- "%{supplement}%{section}%{appendix}%{errata}%{index}%{insert}%{update}"\
12
- "%{translation}" % params
10
+ result = case opts[:format]
11
+ when :short, :mr
12
+ "%{serie}%{code}%{volume}%{part}%{edition}%{revision}%{version}"\
13
+ "%{supplement}%{section}%{appendix}%{errata}%{index}%{insert}%{update}"\
14
+ "%{stage}%{translation}" % params
15
+ else
16
+ "%{serie}%{stage}%{code}%{volume}%{part}%{edition}%{revision}%{version}"\
17
+ "%{supplement}%{section}%{appendix}%{errata}%{index}%{insert}%{update}"\
18
+ "%{translation}" % params
19
+ end
13
20
 
14
21
  if params[:addendum] && !params[:addendum].empty?
15
22
  case opts[:format]
@@ -40,6 +47,8 @@ module Pubid::Nist
40
47
  end
41
48
 
42
49
  def render_edition(edition, opts, _params)
50
+ return if opts[:without_edition]
51
+
43
52
  case opts[:format]
44
53
  when :long
45
54
  " Edition "
@@ -109,7 +118,7 @@ module Pubid::Nist
109
118
  when :mr
110
119
  ".#{translation}"
111
120
  when :short
112
- "(#{translation})"
121
+ " #{translation}"
113
122
  end
114
123
  end
115
124
 
@@ -2,10 +2,10 @@ STAGES = YAML.load_file(File.join(File.dirname(__FILE__), "../../../stages.yaml"
2
2
 
3
3
  module Pubid::Nist
4
4
  class Stage
5
- attr_accessor :stage
5
+ attr_accessor :id, :type
6
6
 
7
- def initialize(stage)
8
- @stage = stage
7
+ def initialize(id:, type:)
8
+ @id, @type = id.to_s.downcase, type.to_s.downcase
9
9
  end
10
10
 
11
11
  def to_s(format = :short)
@@ -13,16 +13,16 @@ module Pubid::Nist
13
13
 
14
14
  case format
15
15
  when :short
16
- "(#{@stage})"
16
+ " #{@id}#{@type}"
17
17
  when :mr
18
- @stage
18
+ "#{@id}#{@type}"
19
19
  else
20
- STAGES[@stage]
20
+ "#{STAGES['id'][@id]} #{STAGES['type'][@type]}"
21
21
  end
22
22
  end
23
23
 
24
24
  def nil?
25
- @stage.nil?
25
+ @id.nil? && @type.nil?
26
26
  end
27
27
  end
28
28
  end
@@ -26,5 +26,18 @@ module Pubid::Nist
26
26
  rule(update: subtree(:update)) do |context|
27
27
  { update: Update.new(**context[:update]) }
28
28
  end
29
+
30
+ rule(stage: subtree(:stage)) do |context|
31
+ case context[:stage][:id]
32
+ when "1"
33
+ { stage: { id: "i", type: context[:stage][:type] } }
34
+ else
35
+ { stage: context[:stage] }
36
+ end
37
+ end
38
+
39
+ rule(draft: subtree(:draft)) do |context|
40
+ { stage: { id: "i", type: "prd"} }
41
+ end
29
42
  end
30
43
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Nist
3
- VERSION = "0.2.1".freeze
3
+ VERSION = "0.2.3".freeze
4
4
  end
5
5
  end
data/stages.yaml CHANGED
@@ -1,5 +1,16 @@
1
- IPD: Initial Public Draft
2
- 2PD: Second Public Draft
3
- FPD: Final Public Draft
4
- WD: Work-in-Progress Draft
5
- PRD: Preliminary Draft
1
+ id:
2
+ i: Initial
3
+ F: Final
4
+ "1": Initial
5
+ "2": Second
6
+ "3": Third
7
+ "4": Fourth
8
+ "5": Fifth
9
+ "6": Sixth
10
+ "7": Seventh
11
+ "8": Eight
12
+ "9": Ninth
13
+ type:
14
+ pd: Public Draft
15
+ wd: Work-in-Progress Draft
16
+ prd: Preliminary Draft
data/update_codes.yaml CHANGED
@@ -13,15 +13,19 @@ NIST CSWP: CSRC White Paper
13
13
  NIST SP 800-56ar: NIST SP 800-56Ar1
14
14
  NIST.LCIRC: NIST.LC
15
15
  NBS.LCIRC: NBS.LC
16
+ NIST LCIRC: NIST LC
17
+ NBS LCIRC: NBS LC
16
18
  NIST SP 800-57Pt3r1: NIST SP 800-57pt3r1
17
19
  NISTIR: NIST IR
18
20
  NIST FIPS: FIPS PUB
19
21
  NIST.CSWP.01162020pt: NIST.CSWP.01162020(por)
20
- NBS FIPS 11-1-Sep30: NBS FIPS 11-1-Sep30/1977
21
- FIPS PUB 54-1-Jan15: FIPS PUB 54-1
22
- FIPS PUB 54-1-Jan17: FIPS PUB 54-1-Jan17/1991
22
+ /^NBS FIPS 11-1-Sep30$/: NBS FIPS 11-1-Sep30/1977
23
+ /^NBS FIPS 89-Sep1$/: NBS FIPS 89-Sep1981
24
+ /^FIPS PUB 54-1-Jan15$/: FIPS PUB 54-1
25
+ /^FIPS PUB 54-1-Jan17$/: FIPS PUB 54-1-Jan17/1991
23
26
  NBS CRPL c4-4: NBS CRPL 4-4
24
- NIST AMS 300-8r1 (February 2021 update): NIST AMS 300-8r1/Upd1-201502
27
+ NIST AMS 300-8r1 (February 2021 update): NIST AMS 300-8r1/Upd1-202102
28
+ NIST AMS 300-8r1/upd: NIST AMS 300-8r1/Upd1-202102
25
29
  NIST IR 8115r1-upd: NIST IR 8115r1/Upd1-202103
26
30
  NIST SP 500-300-upd: NIST SP 500-300/Upd1-202105
27
31
  NIST TN 2150-upd: NIST TN 2150/Upd1-202102
@@ -32,6 +36,7 @@ NBS.HB.28p11969: NBS.HB.28-1969pt1
32
36
  NIST HB 105-1-1990: NIST HB 105-1r1990
33
37
  NBS.FIPS.100-1-1991: NIST.FIPS.100-1-1991
34
38
  NBS.LC.1088sp: NBS.LC.1088.spa
39
+ NBS LC 1088sp: NBS LC 1088 spa
35
40
  #NBS.LC.145r11/1925: NBS.LC.145/Upd1-192511
36
41
  #NBS.LC.118sup12/1926: NBS.LC.118sup/Upd1-192612
37
42
  NIST SP 955 Suppl.: NIST SP 955sup
@@ -41,7 +46,9 @@ NIST FIPS 54-Jan15: NIST FIPS 54
41
46
  NBS report ;: NBS RPT
42
47
  NBS TN 467p1adde1: NBS TN 467pt1-add
43
48
  NIST SP 1011-II-1.0: NIST SP 1011v2ver1.0
49
+ NIST SP 1011-II-1 0: NIST SP 1011v2ver1.0
44
50
  NIST SP 1011-I-2.0: NIST SP 1011v1ver2.0
51
+ NIST SP 1011-I-2 0: NIST SP 1011v1ver2.0
45
52
  NIST SP 500-281-v1.0: NIST SP 500-281v1.0
46
53
  NIST IR 8259Aes: NIST IR 8259A(spa)
47
54
  NIST IR 8259Apt: NIST IR 8259A(por)
@@ -50,8 +57,33 @@ NIST IR 8115r1/upd: NIST IR 8115r1/Upd1-2021
50
57
  NBS CS v: NBS CSM v
51
58
  NIST SP 800-57p1r2006: NIST SP 800-57pt1r1
52
59
  NIST SP 800-57p1r2007: NIST SP 800-57pt1r2
60
+ NIST SP 500-268v1 1: NIST SP 500-268v1.1
61
+ NIST SP 500-270v1 1: NIST SP 500-270v1.1
62
+ NIST SP 500-280v2 1: NIST SP 500-280v2.1
63
+ NIST SP 500-281-v1 0: NIST SP 500-281v1.0
64
+ NIST SP 800-63v1 0 1: NIST SP 800-63v1.0.1
65
+ NIST SP 800-63v1 0 2: NIST SP 800-63v1.0.2
66
+ NIST SP 955 Suppl: NIST SP 955sup
67
+ NIST SP 984 4: NIST SP 984-4
68
+ NISTPUB 0413171251: NIST TN 1648-2009
69
+ NIST IR 8286C-draft: NIST IR 8286C (Draft)
70
+ NIST SP 800-140Cr1-draft2: NIST SP 800-140Cr1 2pd
71
+ NIST SP 800-140Dr1-draft2: NIST SP 800-140Dr1 2pd
72
+ NIST SP 800-219-draft: NIST SP 800-219 (Draft)
73
+ NIST IR 8270-draft2: NIST IR 8270 2pd
74
+ NIST HB 135e2022-upd1: NIST HB 135e2022/Upd1-202205
75
+ NIST SP 1900-206-upd1: NIST SP 1900-206/Upd1-202202
76
+ NIST TN 2207-upd1: NIST TN 2207/Upd1-202205
77
+ NIST IR 8290-upd1: NIST IR 8290/Upd1-202205
78
+ NIST IR 8413-upd1: NIST IR 8413/Upd1-202207
79
+ NIST IR 85-3273-37-upd1: NIST IR 85-3273-37/Upd1-202205
80
+ NIST IR 8352-draft: NIST IR 8352 (Draft)
81
+ NIST SP 1273-draft: NIST SP 1273 (Draft)
82
+ NIST IR 8323-draft: NIST IR 8323 (Draft)
53
83
  /NBS CRPL-F-B(?=\d+)/: "NBS CRPL-F-B "
54
84
  /NBS[.\s]CS[.\s]e/: "NBS CS-E "
85
+ NBS NSRDS: NSRDS-NBS
86
+ nist ir: NIST IR
55
87
  /(?<=\d)es/: (spa)
56
88
  /(?<=\d)chi/: (zho)
57
89
  /(?<=\d)viet/: (vie)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid-nist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake