nist-pubid 0.1.2 → 0.1.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: 0eda4fda43009a4ec9c9cdd35c0abcada305c5c9868d246b4df0c324f84ea326
4
- data.tar.gz: 1392bed11a8b5d05126e6eb368fa650f013f4aac7a9c78d05f319b6e785bb42f
3
+ metadata.gz: 48d1d54a6499cb679c33cfa2a7cc2a682b6b41e9c66aab0c301375c5df28e3f3
4
+ data.tar.gz: 64fa186792b6564f8afc4f2388f4e2859b04dbcdca5f7cd00e40b192c7f9fc4a
5
5
  SHA512:
6
- metadata.gz: 13a9854c8b67b0c7fc5202306501d8ec9d61ede0b73de2afbaefc8373fb7f798b7f7baa0caca9e6ab256bd6a929c55f09376ff2728465300d7d6098d929c2cad
7
- data.tar.gz: d6e3685000eea4ccf494fc4b1ade59b5002a561bdc9597c9a11b7ae738d730461f3297b60b2f66a98b23ff4670c1c2cdc899562f409a6063e4c609096f73ea97
6
+ metadata.gz: 25197a16bbaa8b4799d0279cf19303de616da1e34452997df576be22cb459aa3b00f538af680d9fa37330d6c7358587d56173ab2bc10f57755774537185c205e
7
+ data.tar.gz: 3e6ae4db9939f1f415ae56ec5aba095a41706157143740a6412d78b560cf850854a779104b22edbc278234fc657ed3289aaf1ab832ef909d58b9d465ec86170b
@@ -0,0 +1,46 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - '*'
7
+ workflow_dispatch:
8
+ inputs:
9
+ next_version:
10
+ description: |
11
+ Next release version. Possible values: x.y.z, major, minor, patch or pre|rc|etc
12
+ required: true
13
+ default: 'skip'
14
+
15
+ jobs:
16
+ release:
17
+ runs-on: ubuntu-18.04
18
+ steps:
19
+ - uses: actions/checkout@v1
20
+
21
+ - uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: '2.6'
24
+ bundler-cache: true
25
+
26
+ - run: bundle exec rake
27
+
28
+ - run: gem install gem-release
29
+
30
+ - run: |
31
+ git config user.name github-actions
32
+ git config user.email github-actions@github.com
33
+ - if: github.event_name == 'workflow_dispatch' && github.event.inputs.next_version != 'skip'
34
+ run: gem bump --version ${{ github.event.inputs.next_version }} --tag --push
35
+
36
+ - name: Publish to rubygems.org
37
+ env:
38
+ RUBYGEMS_API_KEY: ${{secrets.METANORMA_CI_RUBYGEMS_API_KEY}}
39
+ run: |
40
+ gem install gem-release
41
+ cat > ~/.gem/credentials << EOF
42
+ ---
43
+ :rubygems_api_key: ${RUBYGEMS_API_KEY}
44
+ EOF
45
+ chmod 0600 ~/.gem/credentials
46
+ gem release
@@ -40,11 +40,10 @@ module NistPubid
40
40
  attr_accessor :serie, :code, :revision, :publisher, :version, :volume,
41
41
  :part, :addendum, :stage, :translation, :update, :edition
42
42
 
43
- def initialize(publisher:, serie:, docnumber:, stage: nil, **opts)
43
+ def initialize(publisher:, serie:, docnumber:, **opts)
44
44
  @publisher = Publisher.new(publisher: publisher)
45
45
  @serie = Serie.new(serie: serie)
46
46
  @code = docnumber
47
- @stage = Stage.new(stage: stage)
48
47
  opts.each { |key, value| send("#{key}=", value) }
49
48
  end
50
49
 
@@ -52,7 +51,7 @@ module NistPubid
52
51
  matches = {
53
52
  publisher: match(Publisher.regexp, code) || "NIST",
54
53
  serie: match(Serie.regexp, code)&.gsub(/\./, " "),
55
- stage: match(Stage.regexp, code),
54
+ stage: Stage.parse(code),
56
55
  docnumber: match(/(?<=\.|\s)[0-9-]{3,}[A-Z]?/, code),
57
56
  part: /(?<=(\.))?pt(?(1)-)([A-Z\d]+)/.match(code)&.[](2),
58
57
  volume: /(?<=(\.))?v(?(1)-)(\d+)/.match(code)&.[](2),
@@ -60,11 +59,13 @@ module NistPubid
60
59
  revision: /(?<=[^a-z])(?<=(\.))?(?:r(?(1)-)|Rev\.\s)(\d+)/
61
60
  .match(code)&.[](2),
62
61
  addendum: match(/(?<=(\.))?(add(?(1)-)\d+|Addendum)/, code),
63
- translation: match(/(?<=\()\w{3}(?=\))/, code),
64
62
  update: match(/(?<=Upd\s)([\d:]+)/, code),
65
63
  edition: /(?<=[^a-z])(?<=(\.))?(?:e(?(1)-)|Ed\.\s)(\d+)/
66
64
  .match(code)&.[](2),
67
65
  }
66
+ code = code.gsub(matches[:stage].original_code, "") unless matches[:stage].nil?
67
+ matches[:translation] = match(/(?<=\()\w{3}(?=\))/, code)
68
+
68
69
  new(**matches)
69
70
  end
70
71
 
@@ -73,9 +74,11 @@ module NistPubid
73
74
  end
74
75
 
75
76
  def to_s(format)
76
- result = "#{render_serie(format)}#{stage.to_s(format)}"\
77
- "#{code}#{render_part(format)}#{render_edition(format)}"\
78
- "#{render_update(format)}#{render_translation(format)}"
77
+ result = render_serie(format)
78
+ result += " " unless format == :short || stage.nil?
79
+ result += "#{stage&.to_s(format)}"\
80
+ " #{code}#{render_part(format)}#{render_edition(format)}"\
81
+ "#{render_update(format)}#{render_translation(format)}"
79
82
  result = render_addendum(result, format)
80
83
 
81
84
  return result.gsub(" ", ".") if format == :mr
@@ -84,9 +87,9 @@ module NistPubid
84
87
  end
85
88
 
86
89
  def render_serie(format)
87
- return "#{serie.to_s(format)} " if %i[mr short].include?(format)
90
+ return serie.to_s(format) if %i[mr short].include?(format)
88
91
 
89
- "#{publisher.to_s(format)} #{serie.to_s(format)} "
92
+ "#{publisher.to_s(format)} #{serie.to_s(format)}"
90
93
  end
91
94
 
92
95
  def render_part(format)
@@ -18,7 +18,7 @@ module NistPubid
18
18
  end
19
19
 
20
20
  def self.regexp
21
- /(#{(SERIES["long"].keys + SERIES["mr"].values + ["NISTIR"]).join('|')})(?=\.|\s)/
21
+ /(#{(SERIES["long"].keys + SERIES["mr"].values + ["NISTIR"]).join('|')})(?=\.|\s|\()/
22
22
  end
23
23
  end
24
24
  end
@@ -2,21 +2,36 @@ STAGES = YAML.load_file(File.join(File.dirname(__FILE__), "../../stages.yaml"))
2
2
 
3
3
  module NistPubid
4
4
  class Stage
5
- attr_accessor :stage
5
+ attr_accessor :stage, :original_code
6
6
 
7
- def initialize(stage:)
8
- @stage = stage
7
+ def initialize(original_code)
8
+ self.original_code = original_code
9
+ @stage = self.class.regexp.match(original_code)&.[](1)
9
10
  end
10
11
 
11
- def to_s(format)
12
- return "" if @stage.nil?
13
- return "#{@stage} " if %i[short mr].include?(format)
12
+ def to_s(format = :short)
13
+ return "" if nil?
14
14
 
15
- "#{STAGES[@stage]} "
15
+ case format
16
+ when :short
17
+ "(#{@stage})"
18
+ when :mr
19
+ @stage
20
+ else
21
+ STAGES[@stage]
22
+ end
23
+ end
24
+
25
+ def self.parse(code)
26
+ new(regexp.match(code)&.to_s)
16
27
  end
17
28
 
18
29
  def self.regexp
19
- /(#{STAGES.keys.join('|')})(?=\.|\s)/
30
+ /\((#{STAGES.keys.join('|')})\)/
31
+ end
32
+
33
+ def nil?
34
+ @stage.nil?
20
35
  end
21
36
  end
22
37
  end
@@ -1,3 +1,3 @@
1
1
  module NistPubid
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
data/stages.yaml CHANGED
@@ -2,4 +2,4 @@ IPD: Initial Public Draft
2
2
  2PD: Second Public Draft
3
3
  FPD: Final Public Draft
4
4
  WD: Work-in-Progress Draft
5
- PreD: Preliminary Draft
5
+ PRD: Preliminary Draft
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nist-pubid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.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: 2021-12-08 00:00:00.000000000 Z
11
+ date: 2021-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -48,6 +48,7 @@ extra_rdoc_files:
48
48
  - LICENSE.txt
49
49
  files:
50
50
  - ".github/workflows/rake.yml"
51
+ - ".github/workflows/release.yml"
51
52
  - ".rspec"
52
53
  - ".rubocop.yml"
53
54
  - Gemfile