pubid-core 1.8.6 → 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: 97aa518f45d87f5bff0afa474a3db2057a3071e655915c83db8aaf38c911fe88
4
- data.tar.gz: f4ea4f74981a8624ed81a622a57634269d0efde5068f1d4385baf131670074ed
3
+ metadata.gz: 65c153405bb8ae343ef26b9943f013864d2db8fd2abfd27e14d2db1f83de4d0a
4
+ data.tar.gz: 1ebdf5cef55a9c09111f18245a9d6767ee8107d7039398e8aaa9ceb8f5e0e9d5
5
5
  SHA512:
6
- metadata.gz: a1ee5291d1973c694f48ba299040c9ac5b22f592d3904fc729444e7df4b1dca204af1ee29cd06dd047fa0bb3efad35c232091e85ca0da000fce69d3d5c8ad36e
7
- data.tar.gz: 5525d84fb8ea848218849cbdaefba98e8bc9533be22edd41a5fef1f46c8b3ae1ffa3a060ad5b901327a4a00bcd87c486da239faea7cddee909748eb74d63aef7
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
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.8.6".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.6
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-18 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.