pubid-core 1.8.6 → 1.9.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/identifier/base.rb +62 -7
- data/lib/pubid/core/renderer/base.rb +2 -2
- data/lib/pubid/core/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8fa90c212d201a964cf2744e9c8bcba06af62d10dfe195caa6af284189b82cd
|
4
|
+
data.tar.gz: 9d526bcae7afe9781b462aabd17fe3bbaafb1349e3b40c5f5fc6364468dce76d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd9862d64043e894cd11ab5a92f5e792377dc28d1986918799e809c06070504e16f1be6fcecac05da3f366e52e2266476ff4733664ba3427a03f87b5a4ba8c4d
|
7
|
+
data.tar.gz: b0962ace109243f800c6c17ceacde35cc50f345c952dd75b9af42045d03dbf961a72cb4d42b3585f4c1a98ecc7a035795614c45c7e83ca48bd18160c11f573d6
|
@@ -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, :typed_stage
|
7
7
|
|
8
8
|
TYPED_STAGES = {}.freeze
|
9
9
|
|
@@ -53,25 +53,80 @@ module Pubid::Core
|
|
53
53
|
@year = year.to_i if year
|
54
54
|
@edition = edition.to_i if edition
|
55
55
|
@language = language.to_s if language
|
56
|
-
|
56
|
+
|
57
|
+
@typed_stage, @stage = resolve_stage(stage) if stage
|
57
58
|
end
|
58
59
|
|
59
60
|
# @return [String] Rendered URN identifier
|
60
61
|
def urn
|
61
|
-
Renderer::Urn.new(
|
62
|
+
Renderer::Urn.new(to_h).render
|
62
63
|
end
|
63
64
|
|
64
|
-
|
65
|
-
|
65
|
+
# @return [Hash] Identifier's parameters
|
66
|
+
def to_h
|
67
|
+
instance_variables.map do |var|
|
68
|
+
# XXX: temporary hack to prepare typed_stage for rendering
|
69
|
+
# probably need to convert typed_stage to class, now we store
|
70
|
+
# typed_stage as key to typed stage (Symbol)
|
71
|
+
if var.to_s == "@typed_stage" && @typed_stage
|
72
|
+
[:typed_stage, self.class::TYPED_STAGES[@typed_stage][:abbr]]
|
73
|
+
else
|
74
|
+
[var.to_s.gsub("@", "").to_sym, instance_variable_get(var)]
|
75
|
+
end
|
76
|
+
end.to_h
|
66
77
|
end
|
67
78
|
|
68
79
|
def ==(other)
|
69
|
-
|
80
|
+
to_h == other.to_h
|
70
81
|
end
|
71
82
|
|
72
83
|
# Render identifier using default renderer
|
73
84
|
def to_s
|
74
|
-
self.class.get_renderer_class.new(
|
85
|
+
self.class.get_renderer_class.new(to_h).render
|
86
|
+
end
|
87
|
+
|
88
|
+
def typed_stage_abbrev
|
89
|
+
if self.class::TYPED_STAGES.key?(typed_stage)
|
90
|
+
return self.class::TYPED_STAGES[typed_stage][:abbr]
|
91
|
+
end
|
92
|
+
|
93
|
+
stage ? "#{stage.abbr} #{self.class.type[:key].to_s.upcase}" : self.class.type[:key].to_s.upcase
|
94
|
+
end
|
95
|
+
|
96
|
+
# Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
|
97
|
+
def typed_stage_name
|
98
|
+
if self.class::TYPED_STAGES.key?(typed_stage)
|
99
|
+
return self.class::TYPED_STAGES[typed_stage][:name]
|
100
|
+
end
|
101
|
+
|
102
|
+
stage ? "#{stage.name} #{self.class.type[:title]}" : self.class.type[:title]
|
103
|
+
end
|
104
|
+
|
105
|
+
# @param stage [Stage, Symbol, String] stage or typed stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD), "DTR"
|
106
|
+
# @return [[nil, Stage], [Symbol, Stage]] typed stage and stage values
|
107
|
+
def resolve_stage(stage)
|
108
|
+
if stage.is_a?(Stage)
|
109
|
+
return [nil, stage] if stage.abbr
|
110
|
+
|
111
|
+
return [self.class.resolve_typed_stage(stage.harmonized_code), stage]
|
112
|
+
# @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
|
113
|
+
end
|
114
|
+
|
115
|
+
if self.class.has_typed_stage?(stage)
|
116
|
+
return self.class.find_typed_stage(stage)
|
117
|
+
end
|
118
|
+
|
119
|
+
parsed_stage = self.class.get_identifier.parse_stage(stage)
|
120
|
+
# resolve typed stage when harmonized code provided as stage
|
121
|
+
# or stage abbreviation was not resolved
|
122
|
+
if /\A[\d.]+\z/.match?(stage) || parsed_stage.empty_abbr?(with_prf: true)
|
123
|
+
return [self.class.resolve_typed_stage(parsed_stage.harmonized_code), parsed_stage]
|
124
|
+
end
|
125
|
+
|
126
|
+
[nil, parsed_stage]
|
127
|
+
|
128
|
+
# from IEC
|
129
|
+
# @typed_stage = self.class::TYPED_STAGES[@typed_stage][:abbr] if @typed_stage
|
75
130
|
end
|
76
131
|
|
77
132
|
class << self
|
@@ -44,9 +44,9 @@ module Pubid::Core::Renderer
|
|
44
44
|
def render_supplement(supplement_params, **args)
|
45
45
|
base = if supplement_params[:base].type == :amd
|
46
46
|
# render inner amendment (cor -> amd -> base)
|
47
|
-
render_supplement(supplement_params[:base].
|
47
|
+
render_supplement(supplement_params[:base].to_h, **args)
|
48
48
|
else
|
49
|
-
self.class.new(supplement_params[:base].
|
49
|
+
self.class.new(supplement_params[:base].to_h).render_base_identifier(
|
50
50
|
# always render year for identifiers with supplement
|
51
51
|
**args.merge({ with_date: true }),
|
52
52
|
)
|
data/lib/pubid/core/version.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.9.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-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -99,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
99
|
- !ruby/object:Gem::Version
|
100
100
|
version: '0'
|
101
101
|
requirements: []
|
102
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.3.26
|
103
103
|
signing_key:
|
104
104
|
specification_version: 4
|
105
105
|
summary: Library to generate, parse and manipulate PubID.
|