pubid-core 1.8.5 → 1.8.7

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: 7d899ad0149355f47d28e9cbb6d840b3678fe5f69147ffa7e659b557ad182e9e
4
- data.tar.gz: 88493b5808fb4c51441b46b208ba8c32c5d13dedff1035b7ed19c80511869663
3
+ metadata.gz: 65c153405bb8ae343ef26b9943f013864d2db8fd2abfd27e14d2db1f83de4d0a
4
+ data.tar.gz: 1ebdf5cef55a9c09111f18245a9d6767ee8107d7039398e8aaa9ceb8f5e0e9d5
5
5
  SHA512:
6
- metadata.gz: 7bfcbf3c67033e5c6b858459b9f2e74cc2e4d172377a10dbbf92d4498a568f1d8967c0b2044211e4e8fd42c8875d77c83acaac35fdb1a3e27df9beb853fdaa6d
7
- data.tar.gz: 77253a629edfce98fbb5ae3505a80f7b6d4e2a51148ffb6cc9a9c9c0bbeff758aab615d27801069563f99d5a5f6c2c53cf3fa0f7ac3128c634796f27160f894d
6
+ metadata.gz: ff849c54be9d3e4b49a54c48fd58413b66fe0f2aae40f7735c62820fe064e08fdb77b9e197b21a3471dd14570b4875223dce065ae3e5333b614beb520c171bae
7
+ data.tar.gz: d649815ce64e1654b64681d1a183c6309759403738fff8d270ca01effe4a87d4a9e0e7e82f8468bbc7fe15c9717d2e0024e6268a16571eaba71620f0398ead6b
@@ -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,7 +53,8 @@ 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
@@ -62,7 +63,16 @@ module Pubid::Core
62
63
  end
63
64
 
64
65
  def get_params
65
- instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
66
+ instance_variables.map do |var|
67
+ # XXX: temporary hack to prepare typed_stage for rendering
68
+ # probably need to convert typed_stage to class, now we store
69
+ # typed_stage as key to typed stage (Symbol)
70
+ if var.to_s == "@typed_stage" && @typed_stage
71
+ [:typed_stage, self.class::TYPED_STAGES[@typed_stage][:abbr]]
72
+ else
73
+ [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)]
74
+ end
75
+ end.to_h
66
76
  end
67
77
 
68
78
  def ==(other)
@@ -74,6 +84,50 @@ module Pubid::Core
74
84
  self.class.get_renderer_class.new(get_params).render
75
85
  end
76
86
 
87
+ def typed_stage_abbrev
88
+ if self.class::TYPED_STAGES.key?(typed_stage)
89
+ return self.class::TYPED_STAGES[typed_stage][:abbr]
90
+ end
91
+
92
+ stage ? "#{stage.abbr} #{self.class.type[:key].to_s.upcase}" : self.class.type[:key].to_s.upcase
93
+ end
94
+
95
+ # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
96
+ def typed_stage_name
97
+ if self.class::TYPED_STAGES.key?(typed_stage)
98
+ return self.class::TYPED_STAGES[typed_stage][:name]
99
+ end
100
+
101
+ stage ? "#{stage.name} #{self.class.type[:title]}" : self.class.type[:title]
102
+ end
103
+
104
+ # @param stage [Stage, Symbol, String] stage or typed stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD), "DTR"
105
+ # @return [[nil, Stage], [Symbol, Stage]] typed stage and stage values
106
+ def resolve_stage(stage)
107
+ if stage.is_a?(Stage)
108
+ return [nil, stage] if stage.abbr
109
+
110
+ return [self.class.resolve_typed_stage(stage.harmonized_code), stage]
111
+ # @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
112
+ end
113
+
114
+ if self.class.has_typed_stage?(stage)
115
+ return self.class.find_typed_stage(stage)
116
+ end
117
+
118
+ parsed_stage = self.class.get_identifier.parse_stage(stage)
119
+ # resolve typed stage when harmonized code provided as stage
120
+ # or stage abbreviation was not resolved
121
+ if /\A[\d.]+\z/.match?(stage) || parsed_stage.empty_abbr?(with_prf: true)
122
+ return [self.class.resolve_typed_stage(parsed_stage.harmonized_code), parsed_stage]
123
+ end
124
+
125
+ [nil, parsed_stage]
126
+
127
+ # from IEC
128
+ # @typed_stage = self.class::TYPED_STAGES[@typed_stage][:abbr] if @typed_stage
129
+ end
130
+
77
131
  class << self
78
132
  # Parses given identifier
79
133
  # @param code_or_params [String, Hash] code or hash from parser
@@ -94,7 +148,7 @@ module Pubid::Core
94
148
  params.inject({}) do |r, i|
95
149
  result = r
96
150
  i.each do |k, v|
97
- result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
151
+ result = result.merge(k => r.key?(k) ? [r[k], v].flatten : v)
98
152
  end
99
153
  result
100
154
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.8.5".freeze
3
+ VERSION = "1.8.7".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.5
4
+ version: 1.8.7
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-04 00:00:00.000000000 Z
11
+ date: 2023-08-25 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.