pubid-core 1.10.4 → 1.12.0

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: c3e8a5c951d09085272bd38ce431166aa6c9022c1bc05849843cccd7cb088923
4
- data.tar.gz: e6787ce70f4c22a3122eb1f83d9d71a8320842cae23793bae8b70d9f717aea3c
3
+ metadata.gz: 8752ce15b475a7cf21261ea7d1cac28e181052b6a888487a93f89c679bc3a317
4
+ data.tar.gz: 85f903a2d68b26497c832a41255a571ba76b55f56c754f277ca1b6a27ccde9ca
5
5
  SHA512:
6
- metadata.gz: 99f9146360a1c236b50624888c86e5bad0240cc0b61feb7baced9bbcb8d1858f2f8cc0fd3f22198ce2644fe834ce2bbd08aa3bbe52cbe5c3f41d9b4197dd4249
7
- data.tar.gz: 19f5b3f0faf42c2555cbfd4dd23d7f1c4d6463f6a0b39e41774db395b1c6600ef2a66a151ef35f2be7b09ce7e145487427e69a8cdb8462f96ff0e58e1cc5b1f7
6
+ metadata.gz: 87c242c84385cbdceb1e711ea16ebf96b844d591e900e75923fe1812ffff1a7ab5383ca8442e22a562a2d89b0cd910364a145c0044ce71ab8380c956dab7eba2
7
+ data.tar.gz: aa97a199ccaec9ddda10615c339308d64240d28f2bebf32075f50b17d34776b1f0d25d87f278498d6f4d79cb07291a5a1250c11d81446184c163d5a7637998b7
@@ -0,0 +1,11 @@
1
+ module Pubid::Core
2
+ class Entity
3
+ def ==(other)
4
+ instance_variables.map do |var|
5
+ return false unless instance_variable_get(var) == other.instance_variable_get(var)
6
+ end
7
+
8
+ true
9
+ end
10
+ end
11
+ end
@@ -102,8 +102,8 @@ module Pubid::Core
102
102
 
103
103
  # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
104
104
  def typed_stage_name
105
- if self.class::TYPED_STAGES.key?(stage&.typed_stage)
106
- return self.class::TYPED_STAGES[stage.typed_stage][:name]
105
+ if stage.is_a?(TypedStage) && self.class::TYPED_STAGES.key?(stage.abbr)
106
+ return self.class::TYPED_STAGES[stage.abbr][:name]
107
107
  end
108
108
 
109
109
  stage ? "#{stage.name} #{self.class.type[:title]}" : self.class.type[:title]
@@ -113,15 +113,9 @@ module Pubid::Core
113
113
  # @return [[nil, Stage], [Symbol, Stage]] typed stage and stage values
114
114
  def resolve_stage(stage)
115
115
  if stage.is_a?(Stage)
116
- # return [nil, stage] if stage.abbr
117
- # return stage if stage.abbr
116
+ return self.class.resolve_typed_stage(stage.harmonized_code) || stage unless stage.abbr
118
117
 
119
- # return [self.class.resolve_typed_stage(stage.harmonized_code), stage]
120
- unless stage.abbr
121
- stage.typed_stage = self.class.resolve_typed_stage(stage.harmonized_code)
122
- end
123
118
  return stage
124
- # @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
125
119
  end
126
120
 
127
121
  if self.class.has_typed_stage?(stage)
@@ -132,7 +126,7 @@ module Pubid::Core
132
126
  # resolve typed stage when harmonized code provided as stage
133
127
  # or stage abbreviation was not resolved
134
128
  if /\A[\d.]+\z/.match?(stage) || parsed_stage.empty_abbr?(with_prf: true)
135
- parsed_stage.typed_stage = self.class.resolve_typed_stage(parsed_stage.harmonized_code)
129
+ return self.class.resolve_typed_stage(parsed_stage.harmonized_code) || parsed_stage
136
130
  end
137
131
 
138
132
  parsed_stage
@@ -280,7 +274,7 @@ module Pubid::Core
280
274
  def resolve_typed_stage(harmonized_code)
281
275
  self::TYPED_STAGES.each do |k, v|
282
276
  if (v[:harmonized_stages] & harmonized_code.stages) == harmonized_code.stages
283
- return k
277
+ return get_identifier.build_typed_stage(abbr: k, harmonized_code: harmonized_code)
284
278
  end
285
279
  end
286
280
  nil
@@ -1,14 +1,13 @@
1
1
  module Pubid::Core
2
2
  class Stage
3
- attr_accessor :config, :abbr, :harmonized_code, :typed_stage
3
+ attr_accessor :config, :abbr, :harmonized_code
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, typed_stage: nil)
8
+ def initialize(config:, abbr: nil, harmonized_code: nil)
9
9
  @config = config
10
10
  @abbr = abbr&.to_s
11
- @typed_stage = typed_stage
12
11
 
13
12
  if harmonized_code
14
13
  @harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
@@ -5,7 +5,7 @@ module Pubid::Core
5
5
  # @param config [Configuration]
6
6
  # @param abbr [Symbol] typed stage symbol, e.g. :dtr
7
7
  # @param harmonized_code [String, Float, HarmonizedStageCode]
8
- def initialize(config:, abbr:, harmonized_code: nil)
8
+ def initialize(config:, abbr: nil, harmonized_code: nil)
9
9
  @config = config
10
10
  @abbr = abbr
11
11
 
@@ -15,14 +15,26 @@ module Pubid::Core
15
15
  else
16
16
  HarmonizedStageCode.new(harmonized_code, config: config)
17
17
  end
18
- # @abbr ||= lookup_abbr(@harmonized_code.stages)
18
+ @abbr ||= lookup_abbr(@harmonized_code.stages)
19
19
  end
20
20
 
21
- raise Errors::TypedStageInvalidError, "#{abbr} is not valid typed stage" unless config.typed_stages.key?(abbr)
21
+ if abbr && !config.typed_stages.key?(abbr)
22
+ raise Errors::TypedStageInvalidError, "#{abbr} is not valid typed stage"
23
+ end
22
24
 
23
25
  @harmonized_code ||= HarmonizedStageCode.new(abbr, config: config)
24
26
  end
25
27
 
28
+ def lookup_abbr(lookup_code)
29
+ lookup_code = lookup_code.first if lookup_code.is_a?(Array) && lookup_code.count == 1
30
+
31
+ config.typed_stages.each do |abbr, stage|
32
+ return abbr if stage[:harmonized_stages].include?(lookup_code)
33
+ end
34
+
35
+ nil
36
+ end
37
+
26
38
  # Compares one stage with another
27
39
  # should return false if
28
40
  def ==(other)
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.10.4".freeze
3
+ VERSION = "1.12.0".freeze
4
4
  end
5
5
  end
data/lib/pubid/core.rb CHANGED
@@ -15,3 +15,4 @@ require_relative "core/identifier/base"
15
15
  require_relative "core/harmonized_stage_code"
16
16
  require_relative "core/stage"
17
17
  require_relative "core/typed_stage"
18
+ require_relative "core/entity"
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.10.4
4
+ version: 1.12.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-17 00:00:00.000000000 Z
11
+ date: 2023-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -68,6 +68,7 @@ files:
68
68
  - lib/pubid/core/amendment.rb
69
69
  - lib/pubid/core/configuration.rb
70
70
  - lib/pubid/core/corrigendum.rb
71
+ - lib/pubid/core/entity.rb
71
72
  - lib/pubid/core/errors.rb
72
73
  - lib/pubid/core/harmonized_stage_code.rb
73
74
  - lib/pubid/core/identifier.rb