pubid-core 1.9.0 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pubid/core/configuration.rb +9 -1
- data/lib/pubid/core/errors.rb +1 -0
- data/lib/pubid/core/harmonized_stage_code.rb +19 -4
- data/lib/pubid/core/identifier/base.rb +24 -17
- data/lib/pubid/core/identifier.rb +4 -5
- data/lib/pubid/core/stage.rb +9 -2
- data/lib/pubid/core/typed_stage.rb +42 -0
- data/lib/pubid/core/version.rb +1 -1
- data/lib/pubid/core.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 135dbda350a5a305c463d0e56ed56303ad0a95dca7cbc6a74c38e66e37ae7780
|
4
|
+
data.tar.gz: cf8b5afc99d6d4876d1aefd8fd21d95732f6cd26fefb18a9b4f1c4c2552a25ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3401aa6d8c5ad4ab9e82361d2ec67b84976ddb47e661afb3f54ca3538388740acba8960c948520c49b0be8e4fb6781c37cea0d016ccd2d56044d1e2bf843c328
|
7
|
+
data.tar.gz: f231d49c157d57b0d346ff9e246bd7cbe04b8ed770ac5b2c2b808f9c2ae8ff570f8d5b69649d94df35d5f239b5cdf15aa892775a85b0c0f9282a0090305ec33a
|
@@ -1,10 +1,18 @@
|
|
1
1
|
module Pubid::Core
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :stages, :default_type, :type_class, :types, :type_names, :stage_class
|
3
|
+
attr_accessor :stages, :default_type, :type_class, :types, :type_names, :stage_class, :typed_stage_class
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@type_class = Pubid::Core::Type
|
7
7
|
@stage_class = Pubid::Core::Stage
|
8
|
+
@typed_stage_class = Pubid::Core::TypedStage
|
9
|
+
@types = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def typed_stages
|
13
|
+
types.inject({}) do |res, type|
|
14
|
+
res.merge(type::TYPED_STAGES)
|
15
|
+
end
|
8
16
|
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/pubid/core/errors.rb
CHANGED
@@ -2,20 +2,26 @@ module Pubid::Core
|
|
2
2
|
class HarmonizedStageCode
|
3
3
|
include Comparable
|
4
4
|
# attr_accessor :stage, :substage
|
5
|
-
attr_accessor :config, :stages
|
5
|
+
attr_accessor :config, :stages, :harmonized_typed_stages
|
6
6
|
|
7
7
|
# @param stage_or_code [String,Array<String>] stage number or whole harmonized code with substage
|
8
8
|
# or list or stages for fuzzy stages eg. "10", 10, "20.20", ["10.20", "20.20"]
|
9
9
|
# or stage name eg. "proposal", "approval"
|
10
|
+
# or typed stages eg. :dtr, :fdis
|
10
11
|
# @param substage [Integer, String] eg. "00", 0
|
11
12
|
# or substage name eg. "registration", "start_of_main_action"
|
12
13
|
def initialize(stage_or_code, substage = "00", config:)
|
13
14
|
@config = config
|
14
15
|
@stages = if stage_or_code.is_a?(Array)
|
15
16
|
stage_or_code
|
16
|
-
elsif stage_or_code.is_a?(String) &&
|
17
|
+
elsif stage_or_code.is_a?(String) && (
|
18
|
+
config.stages["codes_description"].key?(stage_or_code) ||
|
19
|
+
harmonized_typed_stages.include?(stage_or_code))
|
17
20
|
[stage_or_code]
|
18
|
-
|
21
|
+
# when stage is typed stage
|
22
|
+
elsif stage_or_code.is_a?(Symbol) && config.typed_stages.key?(stage_or_code)
|
23
|
+
config.typed_stages[stage_or_code][:harmonized_stages]
|
24
|
+
# when stage is stage name
|
19
25
|
elsif config.stages["stage_codes"]&.key?(stage_or_code.to_s)
|
20
26
|
["#{config.stages["stage_codes"][stage_or_code.to_s]}.#{config.stages["substage_codes"][substage.to_s]}"]
|
21
27
|
else
|
@@ -25,10 +31,19 @@ module Pubid::Core
|
|
25
31
|
validate_stages
|
26
32
|
end
|
27
33
|
|
34
|
+
def harmonized_typed_stages
|
35
|
+
@harmonized_typed_stages ||= config.typed_stages.values.map { |v| v[:harmonized_stages] }.flatten
|
36
|
+
end
|
37
|
+
|
28
38
|
def validate_stages
|
29
39
|
@stages.each do |stage|
|
30
40
|
# raise an error when stage is wrong
|
31
|
-
|
41
|
+
next if config.stages["codes_description"].key?(stage)
|
42
|
+
|
43
|
+
# check typed stages if no stages in config
|
44
|
+
next if harmonized_typed_stages.include?(stage)
|
45
|
+
|
46
|
+
raise Errors::HarmonizedStageCodeInvalidError
|
32
47
|
end
|
33
48
|
end
|
34
49
|
|
@@ -3,7 +3,7 @@ module Pubid::Core
|
|
3
3
|
class Base
|
4
4
|
attr_accessor :number, :publisher, :copublisher, :part,
|
5
5
|
:type, :year, :edition, :language, :amendments,
|
6
|
-
:corrigendums, :stage
|
6
|
+
:corrigendums, :stage
|
7
7
|
|
8
8
|
TYPED_STAGES = {}.freeze
|
9
9
|
|
@@ -54,7 +54,7 @@ module Pubid::Core
|
|
54
54
|
@edition = edition.to_i if edition
|
55
55
|
@language = language.to_s if language
|
56
56
|
|
57
|
-
@
|
57
|
+
@stage = resolve_stage(stage) if stage
|
58
58
|
end
|
59
59
|
|
60
60
|
# @return [String] Rendered URN identifier
|
@@ -86,8 +86,8 @@ module Pubid::Core
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def typed_stage_abbrev
|
89
|
-
if
|
90
|
-
return
|
89
|
+
if stage.is_a?(TypedStage)
|
90
|
+
return stage.to_s
|
91
91
|
end
|
92
92
|
|
93
93
|
stage ? "#{stage.abbr} #{self.class.type[:key].to_s.upcase}" : self.class.type[:key].to_s.upcase
|
@@ -95,8 +95,8 @@ module Pubid::Core
|
|
95
95
|
|
96
96
|
# Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
|
97
97
|
def typed_stage_name
|
98
|
-
if self.class::TYPED_STAGES.key?(typed_stage)
|
99
|
-
return self.class::TYPED_STAGES[typed_stage][:name]
|
98
|
+
if self.class::TYPED_STAGES.key?(stage&.typed_stage)
|
99
|
+
return self.class::TYPED_STAGES[stage.typed_stage][:name]
|
100
100
|
end
|
101
101
|
|
102
102
|
stage ? "#{stage.name} #{self.class.type[:title]}" : self.class.type[:title]
|
@@ -106,9 +106,14 @@ module Pubid::Core
|
|
106
106
|
# @return [[nil, Stage], [Symbol, Stage]] typed stage and stage values
|
107
107
|
def resolve_stage(stage)
|
108
108
|
if stage.is_a?(Stage)
|
109
|
-
return [nil, stage] if stage.abbr
|
109
|
+
# return [nil, stage] if stage.abbr
|
110
|
+
# return stage if stage.abbr
|
110
111
|
|
111
|
-
return [self.class.resolve_typed_stage(stage.harmonized_code), stage]
|
112
|
+
# return [self.class.resolve_typed_stage(stage.harmonized_code), stage]
|
113
|
+
unless stage.abbr
|
114
|
+
stage.typed_stage = self.class.resolve_typed_stage(stage.harmonized_code)
|
115
|
+
end
|
116
|
+
return stage
|
112
117
|
# @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
|
113
118
|
end
|
114
119
|
|
@@ -120,10 +125,10 @@ module Pubid::Core
|
|
120
125
|
# resolve typed stage when harmonized code provided as stage
|
121
126
|
# or stage abbreviation was not resolved
|
122
127
|
if /\A[\d.]+\z/.match?(stage) || parsed_stage.empty_abbr?(with_prf: true)
|
123
|
-
|
128
|
+
parsed_stage.typed_stage = self.class.resolve_typed_stage(parsed_stage.harmonized_code)
|
124
129
|
end
|
125
130
|
|
126
|
-
|
131
|
+
parsed_stage
|
127
132
|
|
128
133
|
# from IEC
|
129
134
|
# @typed_stage = self.class::TYPED_STAGES[@typed_stage][:abbr] if @typed_stage
|
@@ -239,10 +244,12 @@ module Pubid::Core
|
|
239
244
|
# @return [[Symbol, Stage]] typed stage and stage with assigned harmonized codes
|
240
245
|
def find_typed_stage(typed_stage)
|
241
246
|
if typed_stage.is_a?(Symbol)
|
242
|
-
return
|
243
|
-
|
244
|
-
|
245
|
-
|
247
|
+
return get_identifier
|
248
|
+
.build_typed_stage(
|
249
|
+
harmonized_code:
|
250
|
+
get_identifier.build_harmonized_stage_code(self::TYPED_STAGES[typed_stage][:harmonized_stages]),
|
251
|
+
abbr: typed_stage,
|
252
|
+
)
|
246
253
|
end
|
247
254
|
|
248
255
|
typed_stage = self::TYPED_STAGES.find do |_, v|
|
@@ -255,9 +262,9 @@ module Pubid::Core
|
|
255
262
|
end
|
256
263
|
end
|
257
264
|
|
258
|
-
|
259
|
-
|
260
|
-
|
265
|
+
get_identifier.build_typed_stage(harmonized_code:
|
266
|
+
get_identifier.build_harmonized_stage_code(typed_stage[1][:harmonized_stages]),
|
267
|
+
abbr: typed_stage.first)
|
261
268
|
end
|
262
269
|
|
263
270
|
# Resolve typed stage using stage harmonized stage code
|
@@ -7,11 +7,6 @@ module Pubid::Core
|
|
7
7
|
# @see Pubid::Identifier::Base.initialize for available options
|
8
8
|
def create(**opts)
|
9
9
|
resolve_identifier(opts)
|
10
|
-
# resolve_identifier(
|
11
|
-
# opts[:type],
|
12
|
-
# opts[:stage],
|
13
|
-
# opts.reject { |k, _v| [:type, :stage].include?(k) },
|
14
|
-
# )
|
15
10
|
end
|
16
11
|
|
17
12
|
# @param typed_stage_or_stage [String] typed stage or stage
|
@@ -62,5 +57,9 @@ module Pubid::Core
|
|
62
57
|
def build_harmonized_stage_code(stage_or_code, substage = "00")
|
63
58
|
HarmonizedStageCode.new(stage_or_code, substage, config: @config)
|
64
59
|
end
|
60
|
+
|
61
|
+
def build_typed_stage(**args)
|
62
|
+
@config.typed_stage_class.new(config: @config, **args)
|
63
|
+
end
|
65
64
|
end
|
66
65
|
end
|
data/lib/pubid/core/stage.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Pubid::Core
|
2
2
|
class Stage
|
3
|
-
attr_accessor :config, :abbr, :harmonized_code
|
3
|
+
attr_accessor :config, :abbr, :harmonized_code, :typed_stage
|
4
4
|
|
5
5
|
# @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
|
6
6
|
# @param harmonized_code [String, Float, HarmonizedStageCode]
|
7
7
|
# @param config [Configuration]
|
8
|
-
def initialize(config:, abbr: nil, harmonized_code: nil)
|
8
|
+
def initialize(config:, abbr: nil, harmonized_code: nil, typed_stage: nil)
|
9
9
|
@config = config
|
10
10
|
@abbr = abbr&.to_s
|
11
|
+
@typed_stage = typed_stage
|
11
12
|
|
12
13
|
if harmonized_code
|
13
14
|
@harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
|
@@ -75,6 +76,12 @@ module Pubid::Core
|
|
75
76
|
|
76
77
|
# Compares one stage with another
|
77
78
|
def ==(other)
|
79
|
+
return false unless other
|
80
|
+
|
81
|
+
unless other.is_a?(self.class)
|
82
|
+
return false
|
83
|
+
# other = self.class.parse(other, config: config)
|
84
|
+
end
|
78
85
|
other&.harmonized_code == harmonized_code
|
79
86
|
end
|
80
87
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Pubid::Core
|
2
|
+
class TypedStage < Stage
|
3
|
+
attr_accessor :config, :abbr
|
4
|
+
|
5
|
+
# @param config [Configuration]
|
6
|
+
# @param abbr [Symbol] typed stage symbol, e.g. :dtr
|
7
|
+
# @param harmonized_code [String, Float, HarmonizedStageCode]
|
8
|
+
def initialize(config:, abbr: nil, harmonized_code: nil)
|
9
|
+
@config = config
|
10
|
+
@abbr = abbr
|
11
|
+
|
12
|
+
if harmonized_code
|
13
|
+
@harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
|
14
|
+
harmonized_code
|
15
|
+
else
|
16
|
+
HarmonizedStageCode.new(harmonized_code, config: config)
|
17
|
+
end
|
18
|
+
# @abbr ||= lookup_abbr(@harmonized_code.stages)
|
19
|
+
end
|
20
|
+
|
21
|
+
if abbr
|
22
|
+
raise Errors::TypedStageInvalidError, "#{abbr} is not valid typed stage" unless config.typed_stages.key?(abbr)
|
23
|
+
|
24
|
+
@harmonized_code ||= HarmonizedStageCode.new(abbr, config: config)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Compares one stage with another
|
29
|
+
# should return false if
|
30
|
+
def ==(other)
|
31
|
+
return false unless other
|
32
|
+
|
33
|
+
return abbr == other if other.is_a?(Symbol)
|
34
|
+
|
35
|
+
other&.harmonized_code == harmonized_code
|
36
|
+
end
|
37
|
+
|
38
|
+
def to_s(_opts = nil)
|
39
|
+
config.typed_stages[abbr][:abbr]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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.10.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: 2023-
|
11
|
+
date: 2023-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- lib/pubid/core/supplement.rb
|
80
80
|
- lib/pubid/core/transformer.rb
|
81
81
|
- lib/pubid/core/type.rb
|
82
|
+
- lib/pubid/core/typed_stage.rb
|
82
83
|
- lib/pubid/core/version.rb
|
83
84
|
homepage: https://github.com/metanorma/pubid-core
|
84
85
|
licenses:
|