pubid-core 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pubid/core/errors.rb +3 -0
- data/lib/pubid/core/harmonized_stage_code.rb +79 -0
- data/lib/pubid/core/renderer/base.rb +0 -4
- data/lib/pubid/core/stage.rb +98 -0
- data/lib/pubid/core/version.rb +1 -1
- data/lib/pubid/core.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe1c8b6b0226decbdfd993caaf75ad8e673ea91c86a78c4fa380d82ac8119d1c
|
4
|
+
data.tar.gz: 5d07cdca4cdaf9febed8cb1e2d1bc18ffc503d6ad09359cb2002e4aaae13a2cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7db091d747e05faab9c3cfb4ef42f3e65064e027cd5875eb888c5397852a286f03388da9941491a5eca184c00cdcf30a74b3185254e4343aee82b597abf9c0
|
7
|
+
data.tar.gz: 3fceacbe396c2c8f627fd602f95132667162742e0d274f7fe649f323ef81c43e3684ad42fc626c8a841c41e1a81ce570b077a530685a9445a9b4eb92e21ce8e7
|
data/lib/pubid/core/errors.rb
CHANGED
@@ -0,0 +1,79 @@
|
|
1
|
+
module Pubid::Core
|
2
|
+
class HarmonizedStageCode
|
3
|
+
include Comparable
|
4
|
+
# attr_accessor :stage, :substage
|
5
|
+
attr_accessor :stages
|
6
|
+
|
7
|
+
DESCRIPTIONS = STAGES_CONFIG["codes_description"]
|
8
|
+
DRAFT_STAGES = STAGES_CONFIG["draft_codes"]
|
9
|
+
CANCELED_STAGES = STAGES_CONFIG["canceled_codes"]
|
10
|
+
PUBLISHED_STAGES = STAGES_CONFIG["published_codes"]
|
11
|
+
STAGES_NAMES = STAGES_CONFIG["stage_codes"]
|
12
|
+
SUBSTAGES_NAMES = STAGES_CONFIG["substage_codes"]
|
13
|
+
|
14
|
+
# @param stage_or_code [String,Array<String>] stage number or whole harmonized code with substage
|
15
|
+
# or list or stages for fuzzy stages eg. "10", 10, "20.20", ["10.20", "20.20"]
|
16
|
+
# or stage name eg. "proposal", "approval"
|
17
|
+
# @param substage [Integer, String] eg. "00", 0
|
18
|
+
# or substage name eg. "registration", "start_of_main_action"
|
19
|
+
def initialize(stage_or_code, substage = "00")
|
20
|
+
@stages = if stage_or_code.is_a?(Array)
|
21
|
+
stage_or_code
|
22
|
+
elsif stage_or_code.is_a?(String) && DESCRIPTIONS.key?(stage_or_code)
|
23
|
+
[stage_or_code]
|
24
|
+
# when stage is stage name
|
25
|
+
elsif STAGES_NAMES.key?(stage_or_code.to_s)
|
26
|
+
["#{STAGES_NAMES[stage_or_code.to_s]}.#{SUBSTAGES_NAMES[substage.to_s]}"]
|
27
|
+
else
|
28
|
+
# stage is number
|
29
|
+
["#{stage_or_code}.#{substage}"]
|
30
|
+
end
|
31
|
+
validate_stages
|
32
|
+
end
|
33
|
+
|
34
|
+
def validate_stages
|
35
|
+
@stages.each do |stage|
|
36
|
+
# raise an error when stage is wrong
|
37
|
+
raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(stage)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
if fuzzy?
|
43
|
+
return "draft" if @stages.all? { |s| DRAFT_STAGES.include?(s) || CANCELED_STAGES.include?(s) }
|
44
|
+
|
45
|
+
return "published" if @stages.all? { |s| PUBLISHED_STAGES.include?(s) }
|
46
|
+
|
47
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render fuzzy stages"
|
48
|
+
else
|
49
|
+
@stages.first
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def ==(other)
|
54
|
+
(stages & other.stages) == other.stages
|
55
|
+
end
|
56
|
+
|
57
|
+
def fuzzy?
|
58
|
+
@stages.length > 1
|
59
|
+
end
|
60
|
+
|
61
|
+
def stage
|
62
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render stage for fuzzy stages" if fuzzy?
|
63
|
+
|
64
|
+
return nil if @stages.empty?
|
65
|
+
|
66
|
+
@stages.first.split(".").first
|
67
|
+
end
|
68
|
+
|
69
|
+
def substage
|
70
|
+
raise Errors::HarmonizedStageRenderingError, "cannot render substage for fuzzy stages" if fuzzy?
|
71
|
+
|
72
|
+
@stages.first.split(".").last
|
73
|
+
end
|
74
|
+
|
75
|
+
def description
|
76
|
+
DESCRIPTIONS[to_s]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Pubid::Core
|
2
|
+
class Stage
|
3
|
+
attr_accessor :abbr, :harmonized_code
|
4
|
+
|
5
|
+
STAGES = STAGES_CONFIG["abbreviations"]
|
6
|
+
|
7
|
+
# @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
|
8
|
+
# @param harmonized_code [String, Float, HarmonizedStageCode]
|
9
|
+
def initialize(abbr: nil, harmonized_code: nil)
|
10
|
+
@abbr = abbr&.to_s
|
11
|
+
|
12
|
+
if harmonized_code
|
13
|
+
@harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
|
14
|
+
harmonized_code
|
15
|
+
else
|
16
|
+
HarmonizedStageCode.new(harmonized_code)
|
17
|
+
end
|
18
|
+
@abbr ||= lookup_abbr(@harmonized_code.stages)
|
19
|
+
end
|
20
|
+
|
21
|
+
if abbr
|
22
|
+
raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_s)
|
23
|
+
|
24
|
+
@harmonized_code ||= HarmonizedStageCode.new(lookup_code(abbr))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Lookup for abbreviated code by numeric stage code
|
29
|
+
# @param lookup_code [String, Array] stage code or array of stage codes,
|
30
|
+
# e.g. "00.00", "20.20", ["00.00", "00.20"]
|
31
|
+
def lookup_abbr(lookup_code)
|
32
|
+
lookup_code = lookup_code.first if lookup_code.is_a?(Array) && lookup_code.count == 1
|
33
|
+
|
34
|
+
STAGES.each do |abbr, codes|
|
35
|
+
case codes
|
36
|
+
when Array
|
37
|
+
if lookup_code.is_a?(Array)
|
38
|
+
return abbr if codes == lookup_code
|
39
|
+
else
|
40
|
+
return abbr if codes.include?(lookup_code)
|
41
|
+
end
|
42
|
+
# codes.each do |code|
|
43
|
+
# return abbr if code == lookup_code
|
44
|
+
# end
|
45
|
+
when lookup_code
|
46
|
+
return abbr
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def lookup_code(lookup_abbr)
|
54
|
+
STAGES[lookup_abbr.to_s]
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.parse(stage)
|
58
|
+
if /\A[\d.]+\z/.match?(stage)
|
59
|
+
Stage.new(harmonized_code: stage)
|
60
|
+
else
|
61
|
+
raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String) || stage.is_a?(Parslet::Slice)
|
62
|
+
|
63
|
+
Stage.new(abbr: stage.to_s)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# @return [Boolean] true if stage exists
|
68
|
+
def self.has_stage?(stage)
|
69
|
+
if stage.is_a?(Stage)
|
70
|
+
STAGES.key?(stage.abbr.to_sym)
|
71
|
+
else
|
72
|
+
STAGES.key?(stage.to_s) || /\A[\d.]+\z/.match?(stage)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# Compares one stage with another
|
77
|
+
def ==(other)
|
78
|
+
other&.harmonized_code == harmonized_code
|
79
|
+
end
|
80
|
+
|
81
|
+
# Return stage name, eg. "Draft International Standard" for "DIS"
|
82
|
+
def name
|
83
|
+
STAGES_CONFIG["names"][abbr.to_s]
|
84
|
+
end
|
85
|
+
|
86
|
+
# @param with_prf [Boolean]
|
87
|
+
# @return [Boolean] false if there are output for abbreviation should be produced
|
88
|
+
def empty_abbr?(with_prf: false)
|
89
|
+
return true if abbr == "PRF" && !with_prf
|
90
|
+
|
91
|
+
abbr.nil?
|
92
|
+
end
|
93
|
+
|
94
|
+
def to_s(opts = {})
|
95
|
+
abbr unless empty_abbr?(**opts)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/pubid/core/version.rb
CHANGED
data/lib/pubid/core.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pubid-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -68,10 +68,12 @@ files:
|
|
68
68
|
- lib/pubid/core/amendment.rb
|
69
69
|
- lib/pubid/core/corrigendum.rb
|
70
70
|
- lib/pubid/core/errors.rb
|
71
|
+
- lib/pubid/core/harmonized_stage_code.rb
|
71
72
|
- lib/pubid/core/identifier.rb
|
72
73
|
- lib/pubid/core/parser.rb
|
73
74
|
- lib/pubid/core/renderer/base.rb
|
74
75
|
- lib/pubid/core/renderer/urn.rb
|
76
|
+
- lib/pubid/core/stage.rb
|
75
77
|
- lib/pubid/core/supplement.rb
|
76
78
|
- lib/pubid/core/transformer.rb
|
77
79
|
- lib/pubid/core/version.rb
|