pubid-core 1.11.0 → 1.12.1

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: 0b73ed4ff507dfe5cb2c7b506eaa392ef6fbf3af9b2ff0d500151a430d0a8d2c
4
- data.tar.gz: 46108a14c2cbb1446085668ab46a8b60837e596a8a893f2f2731a2b247c6d7c2
3
+ metadata.gz: 448ee8d0c3ee2f141390d279b470709a69d479dd8203aab75202ec53f4b5d219
4
+ data.tar.gz: '0284a013694e73ddba1e96d3c560dbd27f15a69840f50cc33f19035adab3a373'
5
5
  SHA512:
6
- metadata.gz: 93fcaaf9757fc059fe26cfd9506c5d42806e56e6f1abd1a86d2464abdfcb64cba933e777813d988e06abe997099504a5e8f632fe08784c926fea105916301643
7
- data.tar.gz: d84b1ac6d760d5de765e87e041ad82a5dd7c76c762f69cb5a56074376981d7a0a13929162a462fd421144c1042042a51eae1c9cbb51433b7a4c9f377713d8ea5
6
+ metadata.gz: d7c8e1f74a0fb9fedb9388971edf1f2920917b1ea2d9d1fedab7cd7168412a9c085434f3da4ddf796d1921909db6589af4e1b4430a795227df65cf0dd2dc136b
7
+ data.tar.gz: 8c53cb46cf3fed1bcfbf1138063fbc728ad9c80b03b903a46acd211ce79fce6a086530280fbe6a63ef0d08671d468d6e9eaba489e9e22bfc0709f10da54fd776
@@ -1,8 +1,7 @@
1
1
  module Pubid::Core
2
2
  module Identifier
3
3
  class Base
4
- attr_accessor :number, :publisher, :copublisher, :part,
5
- :type, :year, :edition, :language, :amendments,
4
+ attr_accessor :number, :publisher, :copublisher, :part, :year, :edition, :language, :amendments,
6
5
  :corrigendums, :stage
7
6
 
8
7
  TYPED_STAGES = {}.freeze
@@ -21,7 +20,7 @@ module Pubid::Core
21
20
  # @param corrigendums [Array<Corrigendum>,Array<Hash>] document's corrigendums
22
21
  # @see Amendment
23
22
  # @see Corrigendum
24
- def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,
23
+ def initialize(publisher:, number:, copublisher: nil, part: nil,
25
24
  year: nil, edition: nil, language: nil, amendments: nil,
26
25
  corrigendums: nil, stage: nil)
27
26
 
@@ -49,7 +48,6 @@ module Pubid::Core
49
48
  @number = number
50
49
  @copublisher = copublisher if copublisher
51
50
  @part = part.to_s if part
52
- @type = type.to_s if type
53
51
  @year = year.to_i if year
54
52
  @edition = edition.to_i if edition
55
53
  @language = language.to_s if language
@@ -64,7 +62,7 @@ module Pubid::Core
64
62
 
65
63
  # @return [Hash] Identifier's parameters
66
64
  def to_h(deep: true)
67
- instance_variables.map do |var|
65
+ result = instance_variables.map do |var|
68
66
  value = instance_variable_get(var)
69
67
 
70
68
  [var.to_s.gsub("@", "").to_sym,
@@ -77,6 +75,12 @@ module Pubid::Core
77
75
  end
78
76
  ]
79
77
  end.to_h
78
+
79
+ if respond_to?(:type)
80
+ result[:type] = self.type[:key]
81
+ end
82
+
83
+ result
80
84
  end
81
85
 
82
86
  def ==(other)
@@ -102,8 +106,8 @@ module Pubid::Core
102
106
 
103
107
  # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
104
108
  def typed_stage_name
105
- if self.class::TYPED_STAGES.key?(stage&.typed_stage)
106
- return self.class::TYPED_STAGES[stage.typed_stage][:name]
109
+ if stage.is_a?(TypedStage) && self.class::TYPED_STAGES.key?(stage.abbr)
110
+ return self.class::TYPED_STAGES[stage.abbr][:name]
107
111
  end
108
112
 
109
113
  stage ? "#{stage.name} #{self.class.type[:title]}" : self.class.type[:title]
@@ -113,15 +117,9 @@ module Pubid::Core
113
117
  # @return [[nil, Stage], [Symbol, Stage]] typed stage and stage values
114
118
  def resolve_stage(stage)
115
119
  if stage.is_a?(Stage)
116
- # return [nil, stage] if stage.abbr
117
- # return stage if stage.abbr
120
+ return self.class.resolve_typed_stage(stage.harmonized_code) || stage unless stage.abbr
118
121
 
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
122
  return stage
124
- # @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
125
123
  end
126
124
 
127
125
  if self.class.has_typed_stage?(stage)
@@ -132,7 +130,7 @@ module Pubid::Core
132
130
  # resolve typed stage when harmonized code provided as stage
133
131
  # or stage abbreviation was not resolved
134
132
  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)
133
+ return self.class.resolve_typed_stage(parsed_stage.harmonized_code) || parsed_stage
136
134
  end
137
135
 
138
136
  parsed_stage
@@ -280,7 +278,7 @@ module Pubid::Core
280
278
  def resolve_typed_stage(harmonized_code)
281
279
  self::TYPED_STAGES.each do |k, v|
282
280
  if (v[:harmonized_stages] & harmonized_code.stages) == harmonized_code.stages
283
- return k
281
+ return get_identifier.build_typed_stage(abbr: k, harmonized_code: harmonized_code)
284
282
  end
285
283
  end
286
284
  nil
@@ -12,10 +12,10 @@ module Pubid::Core
12
12
  # @param typed_stage_or_stage [String] typed stage or stage
13
13
  # @return identifier's class
14
14
  def resolve_identifier(parameters = {})
15
- return @config.default_type.new(**parameters) if parameters[:type].nil? && parameters[:stage].nil?
15
+ return @config.default_type.new(**parameters.dup.tap { |h| h.delete(:type) }) if parameters[:type].nil? && parameters[:stage].nil?
16
16
 
17
17
  @config.types.each do |identifier_type|
18
- return identifier_type.new(**parameters) if identifier_type.type_match?(parameters)
18
+ return identifier_type.new(**parameters.dup.tap { |h| h.delete(:type) }) if identifier_type.type_match?(parameters)
19
19
  end
20
20
 
21
21
  # When stage is not typed stage and type is not defined
@@ -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.11.0".freeze
3
+ VERSION = "1.12.1".freeze
4
4
  end
5
5
  end
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.11.0
4
+ version: 1.12.1
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-18 00:00:00.000000000 Z
11
+ date: 2023-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake