pubid-iso 0.6.0 → 0.6.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: 11124938cd55ceae313c720ac11b3c19c475e1398bb7e0eed93ac07ebbbe9eb4
4
- data.tar.gz: 72de1b3ce2af85a21b888e2180410d5efbe57f6ea297ff7b412a9758e024d1e5
3
+ metadata.gz: e0cd99c30184d624f0019e7d10fd9d3d752e86ff701b4852de0d97f79e9ac095
4
+ data.tar.gz: 1c2c1988f300757de153e28ff528f01a488c058e2b3b49a41be94a73ef242397
5
5
  SHA512:
6
- metadata.gz: dd4d5c372306186736e8c44c446e445758c8b7d871d73454096c739ed1e5e7fcc7890b8ea0189c44f5418150d54f6802d325687ab77dcf71984277ec244f303a
7
- data.tar.gz: f93770f6fb62a8401e99a59d1e47c99eb6f97c5be34385acb9f01187bb8eab504ccff0dc8ae50162037ef3f5080a0e0f2a8add11a2f789ef67cf153128c339eb
6
+ metadata.gz: 7f63fbc6f3f030698619fa235ee2ba17bc3ba8d237ae05b2b0397a6e211654defe106d6f13fabf4c28e40470bc8ba68664b07ff90ec12f8e1fb7d7f33a1302b2
7
+ data.tar.gz: dfa9bcb9441abc1ce2d5e56cce1ea915d72f3c9599ba64b6ec5e554e464397fe22940abc659eee1298136abba27acc26d5457f8e025a2f648a1fa32dfbe88159
@@ -11,8 +11,6 @@ module Pubid::Iso
11
11
  :iteration, :joint_document,
12
12
  :tctype, :sctype, :wgtype, :tcnumber, :scnumber, :wgnumber,
13
13
  :dirtype,
14
- # supplement for DIR type identifiers
15
- :supplement,
16
14
  :base,
17
15
  :typed_stage,
18
16
  :supplements,
@@ -24,7 +22,7 @@ module Pubid::Iso
24
22
  # @param stage [Stage, Symbol, String] stage or typed stage, e.g. "PWI", "NP", "50.00", Stage.new(abbr: :WD), "DTR"
25
23
  # @param iteration [Integer] document iteration, eg. "1", "2", "3"
26
24
  # @param joint_document [Identifier] joint document
27
- # @param supplement [Supplement] supplement
25
+ # @param supplements [Array<Supplement>] supplements
28
26
  # @param tctype [String] Technical Committee type, eg. "TC", "JTC"
29
27
  # @param sctype [String] TC subsommittee, eg. "SC"
30
28
  # @param wgtype [String] TC working group type, eg. "AG", "AHG"
@@ -44,12 +42,12 @@ module Pubid::Iso
44
42
  # @see Identifier
45
43
  # @see Pubid::Core::Identifier
46
44
  # @see Parser
47
- def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
45
+ def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil,
48
46
  joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
49
47
  scnumber: nil, wgnumber:nil,
50
48
  dir: nil, dirtype: nil, year: nil, amendments: nil,
51
49
  corrigendums: nil, type: nil, base: nil, supplements: nil,
52
- part: nil, addendum: nil, **opts)
50
+ part: nil, addendum: nil, edition: nil, **opts)
53
51
  super(**opts.merge(number: number, publisher: publisher, year: year,
54
52
  amendments: amendments, corrigendums: corrigendums))
55
53
 
@@ -64,25 +62,12 @@ module Pubid::Iso
64
62
  end
65
63
 
66
64
  if stage
67
- if stage.is_a?(Pubid::Core::Stage)
68
- @stage = stage
69
- @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
70
- elsif self.class.has_typed_stage?(stage)
71
- @typed_stage, @stage = find_typed_stage(stage)
72
- else
73
- @stage = Identifier.parse_stage(stage)
74
- # resolve typed stage when harmonized code provided as stage
75
- # or stage abbreviation was not resolved
76
- if /\A[\d.]+\z/.match?(stage) || @stage.empty_abbr?(with_prf: true)
77
- @typed_stage = resolve_typed_stage(@stage.harmonized_code)
78
- end
79
- end
65
+ @typed_stage, @stage = resolve_stage(stage)
80
66
  elsif iteration && !is_a?(Supplement)
81
67
  raise Errors::IterationWithoutStageError, "Document without stage cannot have iteration"
82
68
  end
83
69
 
84
70
  @iteration = iteration.to_i if iteration
85
- @supplement = supplement if supplement
86
71
  @joint_document = joint_document if joint_document
87
72
  @tctype = tctype if tctype
88
73
  @sctype = sctype.to_s if sctype
@@ -95,47 +80,7 @@ module Pubid::Iso
95
80
  @base = base if base
96
81
  @part = part if part
97
82
  @addendum = addendum if addendum
98
- end
99
-
100
- # @param typed_stage [String, Symbol] eg. "DTR" or :dtr
101
- # @return [[Symbol, Stage]] typed stage and stage with assigned harmonized codes
102
- def find_typed_stage(typed_stage)
103
- if typed_stage.is_a?(Symbol)
104
- return [typed_stage,
105
- Identifier.build_stage(
106
- harmonized_code: Identifier.build_harmonized_stage_code(self.class::TYPED_STAGES[typed_stage][:harmonized_stages])),
107
- ]
108
- end
109
-
110
- typed_stage = self.class::TYPED_STAGES.find do |_, v|
111
- if v[:abbr].is_a?(Hash)
112
- v[:abbr].value?(typed_stage)
113
- else
114
- if v.key?(:legacy_abbr)
115
- v[:legacy_abbr].include?(typed_stage) || v[:abbr] == typed_stage
116
- else
117
- v[:abbr] == typed_stage
118
- end
119
- #
120
- # v[:abbr] == typed_stage
121
- end
122
- end
123
-
124
- [typed_stage.first,
125
- Identifier.build_stage(
126
- harmonized_code: Identifier.build_harmonized_stage_code(typed_stage[1][:harmonized_stages]))]
127
- end
128
-
129
- # Resolve typed stage using stage harmonized stage code
130
- # @param harmonized_code [HarmonizedStageCode]
131
- # @return [Symbol, nil] typed stage or nil
132
- def resolve_typed_stage(harmonized_code)
133
- self.class::TYPED_STAGES.each do |k, v|
134
- if (v[:harmonized_stages] & harmonized_code.stages) == harmonized_code.stages
135
- return k
136
- end
137
- end
138
- nil
83
+ @edition = edition
139
84
  end
140
85
 
141
86
  class << self
@@ -179,7 +124,7 @@ module Pubid::Iso
179
124
  end.inject({}, :merge)
180
125
 
181
126
  # return supplement if supplements applied
182
- if identifier_params[:supplements]
127
+ if identifier_params[:supplements] && identifier_params[:supplements].is_a?(Array)
183
128
  return transform_supplements(
184
129
  identifier_params[:supplements],
185
130
  identifier_params.dup.tap { |h| h.delete(:supplements) }
@@ -196,24 +141,6 @@ module Pubid::Iso
196
141
  Identifier.create(**identifier_params)
197
142
  end
198
143
 
199
- # @param typed_stage [String, Symbol] typed stage, eg. "DTR" or :dtr
200
- # @return [Boolean] true when identifier has associated typed stage
201
- def has_typed_stage?(typed_stage)
202
- return self::TYPED_STAGES.key?(typed_stage) if typed_stage.is_a?(Symbol)
203
-
204
- self::TYPED_STAGES.any? do |_, v|
205
- if v[:abbr].is_a?(Hash)
206
- v[:abbr].value?(typed_stage)
207
- else
208
- if v.key?(:legacy_abbr)
209
- v[:legacy_abbr].include?(typed_stage) || v[:abbr] == typed_stage
210
- else
211
- v[:abbr] == typed_stage
212
- end
213
- end
214
- end
215
- end
216
-
217
144
  def get_amendment_class
218
145
  Pubid::Iso::Amendment
219
146
  end
@@ -238,6 +165,10 @@ module Pubid::Iso
238
165
  UPDATE_CODES
239
166
  end
240
167
 
168
+ def get_identifier
169
+ Identifier
170
+ end
171
+
241
172
  def type_match?(parameters)
242
173
  parameters[:type] ? has_type?(parameters[:type]) : has_typed_stage?(parameters[:stage])
243
174
  end
@@ -251,16 +182,6 @@ module Pubid::Iso
251
182
  ).render + (language ? ":#{language}" : "")
252
183
  end
253
184
 
254
- def get_params
255
- instance_variables.map do |var|
256
- if var.to_s == "@typed_stage" && @typed_stage
257
- [:typed_stage, self.class::TYPED_STAGES[@typed_stage][:abbr]]
258
- else
259
- [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)]
260
- end
261
- end.to_h
262
- end
263
-
264
185
  # @param format [:ref_num_short,:ref_num_long,:ref_dated,:ref_dated_long,:ref_undated,:ref_undated_long] create reference with specified format
265
186
  # Format options are:
266
187
  # :ref_num_short -- instance reference number: 1 letter language code + short form (DAM) + dated
@@ -333,23 +254,6 @@ module Pubid::Iso
333
254
  end
334
255
 
335
256
  # Return typed stage abbreviation, eg. "FDTR", "DIS", "TR"
336
- def typed_stage_abbrev
337
- if self.class::TYPED_STAGES.key?(typed_stage)
338
- self.class::TYPED_STAGES[typed_stage][:abbr]
339
- else
340
- stage ? "#{stage.abbr} #{type[:key].to_s.upcase}" : type[:key].to_s.upcase
341
- end
342
- end
343
-
344
- # Return typed stage name, eg. "Final Draft Technical Report" for "FDTR"
345
- def typed_stage_name
346
- if self.class::TYPED_STAGES.key?(typed_stage)
347
- self.class::TYPED_STAGES[typed_stage][:name]
348
- else
349
- stage ? "#{stage.name} #{type[:title]}" : type[:title]
350
- end
351
- end
352
-
353
257
  # returns root identifier
354
258
  def root
355
259
  return base.base if base&.base
@@ -8,6 +8,13 @@ module Pubid::Iso
8
8
 
9
9
  TYPED_STAGES = {}.freeze
10
10
 
11
+ attr_accessor :edition_publisher
12
+
13
+ def initialize(edition_publisher: nil, **opts)
14
+ super(**opts)
15
+ @edition_publisher = edition_publisher
16
+ end
17
+
11
18
  def self.type
12
19
  { key: :dir, title: "Directives" }
13
20
  end
@@ -21,11 +21,7 @@ module Pubid::Iso
21
21
  },
22
22
  }.freeze
23
23
 
24
- def initialize(publisher: "ISO", number: nil, stage: nil, iteration: nil, supplement: nil,
25
- joint_document: nil, tctype: nil, sctype: nil, wgtype: nil, tcnumber: nil,
26
- scnumber: nil, wgnumber:nil,
27
- dir: nil, dirtype: nil, year: nil, amendments: nil,
28
- corrigendums: nil, type: nil, base: nil, supplements: nil, **opts)
24
+ def initialize(stage: nil, iteration: nil, **opts)
29
25
 
30
26
  if iteration && stage.nil?
31
27
  raise Errors::IsStageIterationError, "IS stage document cannot have iteration"
@@ -169,9 +169,13 @@ module Pubid::Iso
169
169
  ((str("DIR") | str("Directives Part") | str("Directives, Part") | str("Directives,")).as(:type) >> space).maybe >>
170
170
  (str("JTC").as(:dirtype) >> space).maybe >>
171
171
  (digits.as(:number) >> (str(":") >> year).maybe).maybe >>
172
- (str(" -- Consolidated").maybe >> (space? >> (organization.as(:publisher) >> space).maybe >>
173
- (array_to_str(DIR_SUPPLEMENTS)) >> (str(":") >> year).maybe >>
174
- dir_supplement_edition.maybe).repeat(1).as(:supplements)).maybe
172
+ (str(" -- Consolidated").maybe >> (str("").as(:mark) >> space? >>
173
+ (organization.as(:publisher) >> space?).maybe >>
174
+ array_to_str(DIR_SUPPLEMENTS) >> (str(":") >> year).maybe >>
175
+ dir_supplement_edition.maybe).repeat(1).as(:supplements)).maybe >>
176
+ # parse identifiers with publisher at the end, e.g. "ISO/IEC DIR 2 ISO"
177
+ (space >> organization.as(:publisher) >> (str(":") >> year).maybe).as(:edition).maybe
178
+
175
179
  end
176
180
 
177
181
  rule(:std_document_body) do
@@ -4,12 +4,12 @@ module Pubid::Iso::Renderer
4
4
  class Dir < Base
5
5
 
6
6
  def render_identifier(params, opts)
7
- res = ("%{publisher} DIR%{dirtype}%{number}%{year}%{supplement}" % params)
7
+ res = ("%{publisher} DIR%{dirtype}%{number}%{year}%{edition}" % params)
8
8
 
9
9
  if params.key?(:joint_document)
10
10
  joint_params = prerender_params(params[:joint_document].get_params, {})
11
11
  joint_params.default = ""
12
- res += (" + %{publisher}%{dirtype}%{number}%{year}%{supplement}" % joint_params)
12
+ res += (" + %{publisher}%{dirtype}%{number}%{year}" % joint_params)
13
13
  end
14
14
 
15
15
  res
@@ -23,13 +23,8 @@ module Pubid::Iso::Renderer
23
23
  " #{dirtype}"
24
24
  end
25
25
 
26
- def render_supplement(supplement, _opts, _params)
27
- if supplement.publisher && supplement.publisher != ""
28
- " #{supplement.publisher} SUP"
29
- else
30
- " SUP"
31
- end + (supplement.year && ":#{supplement.year}" || "") +
32
- (supplement.edition && " Edition #{supplement.edition}" || "")
26
+ def render_edition(edition, _opts, _params)
27
+ " #{edition[:publisher]}" + (edition[:year] ? ":#{edition[:year]}" : "")
33
28
  end
34
29
  end
35
30
  end
@@ -15,28 +15,30 @@ module Pubid::Iso
15
15
  end
16
16
 
17
17
  rule(supplements: subtree(:supplements)) do |context|
18
- context[:supplements] =
19
- context[:supplements].map do |supplement|
20
- if supplement[:typed_stage]
21
- supplement.merge(
22
- case supplement[:typed_stage]
23
- when "PDAM"
24
- { typed_stage: "CD", type: "Amd" }
25
- when "pDCOR"
26
- { typed_stage: "CD", type: "Cor" }
18
+ if context[:supplements].is_a?(Array)
19
+ context[:supplements] =
20
+ context[:supplements].map do |supplement|
21
+ if supplement[:typed_stage]
22
+ supplement.merge(
23
+ case supplement[:typed_stage]
24
+ when "PDAM"
25
+ { typed_stage: "CD", type: "Amd" }
26
+ when "pDCOR"
27
+ { typed_stage: "CD", type: "Cor" }
28
+ else
29
+ {}
30
+ end
31
+ )
32
+ else
33
+ case supplement[:type]
34
+ when "Addendum"
35
+ supplement.merge({ type: "Add" })
27
36
  else
28
- {}
37
+ supplement
29
38
  end
30
- )
31
- else
32
- case supplement[:type]
33
- when "Addendum"
34
- supplement.merge({ type: "Add" })
35
- else
36
- supplement
37
39
  end
38
40
  end
39
- end
41
+ end
40
42
  context
41
43
  end
42
44
 
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.6.0".freeze
3
+ VERSION = "0.6.1".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pubid-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.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-07-21 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.8.6
61
+ version: 1.8.7
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.8.6
68
+ version: 1.8.7
69
69
  description: Library to generate, parse and manipulate ISO PubID.
70
70
  email:
71
71
  - open.source@ribose.com
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.0.3.1
148
+ rubygems_version: 3.3.26
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: Library to generate, parse and manipulate ISO PubID.