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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97aa518f45d87f5bff0afa474a3db2057a3071e655915c83db8aaf38c911fe88
4
- data.tar.gz: f4ea4f74981a8624ed81a622a57634269d0efde5068f1d4385baf131670074ed
3
+ metadata.gz: c8fa90c212d201a964cf2744e9c8bcba06af62d10dfe195caa6af284189b82cd
4
+ data.tar.gz: 9d526bcae7afe9781b462aabd17fe3bbaafb1349e3b40c5f5fc6364468dce76d
5
5
  SHA512:
6
- metadata.gz: a1ee5291d1973c694f48ba299040c9ac5b22f592d3904fc729444e7df4b1dca204af1ee29cd06dd047fa0bb3efad35c232091e85ca0da000fce69d3d5c8ad36e
7
- data.tar.gz: 5525d84fb8ea848218849cbdaefba98e8bc9533be22edd41a5fef1f46c8b3ae1ffa3a060ad5b901327a4a00bcd87c486da239faea7cddee909748eb74d63aef7
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
- @stage = stage if stage
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(get_params).render
62
+ Renderer::Urn.new(to_h).render
62
63
  end
63
64
 
64
- def get_params
65
- instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
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
- get_params == other.get_params
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(get_params).render
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].get_params, **args)
47
+ render_supplement(supplement_params[:base].to_h, **args)
48
48
  else
49
- self.class.new(supplement_params[:base].get_params).render_base_identifier(
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
  )
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.8.6".freeze
3
+ VERSION = "1.9.0".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.8.6
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-07-18 00:00:00.000000000 Z
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.0.3.1
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.