pubid-iso 0.4.1 → 0.5.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: 38d4eeb603e945da7dc88276eeec404e80e210dbb7256d0a1c6dbf0f5afe128e
4
- data.tar.gz: d3be687ed15dad803823d873a9fb0189a96c97c45870c69a7a4887f165c60075
3
+ metadata.gz: 84d4109f05e973ee81d7d7ab5a949b93de233594e81be474156add05c0eb611f
4
+ data.tar.gz: fe8f286a88801ebc7c02f97c8de81ad66f94c9cadf1db457418b3c6e55d1078b
5
5
  SHA512:
6
- metadata.gz: f99b0267a9322ceb93893b931a7ead3ac6e603cf95b8a75a75a192a8db6de3bab0c75fff137e7294b566a2d10960e8861dcddf9663d7b6a7473d0544f0e15683
7
- data.tar.gz: 2067033963eeac42aac98bf5178f0cf19fefe21f5eb334e53e1e3fe41c6665b64b6e580c1f126d4f8936c6008e47c4d12b49cc793e5f305a8732525ade50604b
6
+ metadata.gz: e46b0939a516226943c49e097da4a9c9d1dabc175661a2c776a6c2a54d150d22bb79275cb983bbd72470fc480fa85c3c352b4e49d25db8a3fe7d66c2d2350e42
7
+ data.tar.gz: 89c434768a1d6e05558717a19ef1c5ebb4a01b738523acee23a4c457155f9b97447fc7ce7fe8b7b305a1d9ffa6cb766fa7b2f707f3b5c58716436be7690c34ae
@@ -4,7 +4,7 @@ require_relative "../renderer/urn-tc"
4
4
 
5
5
  module Pubid::Iso
6
6
  module Identifier
7
- class Base < Pubid::Core::Identifier
7
+ class Base < Pubid::Core::Identifier::Base
8
8
  extend Forwardable
9
9
 
10
10
  attr_accessor :stage,
@@ -64,13 +64,13 @@ module Pubid::Iso
64
64
  end
65
65
 
66
66
  if stage
67
- if stage.is_a?(Stage)
67
+ if stage.is_a?(Pubid::Core::Stage)
68
68
  @stage = stage
69
69
  @typed_stage = resolve_typed_stage(@stage.harmonized_code) unless @stage.abbr
70
70
  elsif self.class.has_typed_stage?(stage)
71
71
  @typed_stage, @stage = find_typed_stage(stage)
72
72
  else
73
- @stage = Stage.parse(stage)
73
+ @stage = Identifier.parse_stage(stage)
74
74
  # resolve typed stage when harmonized code provided as stage
75
75
  # or stage abbreviation was not resolved
76
76
  if /\A[\d.]+\z/.match?(stage) || @stage.empty_abbr?(with_prf: true)
@@ -102,8 +102,8 @@ module Pubid::Iso
102
102
  def find_typed_stage(typed_stage)
103
103
  if typed_stage.is_a?(Symbol)
104
104
  return [typed_stage,
105
- Stage.new(
106
- harmonized_code: HarmonizedStageCode.new(self.class::TYPED_STAGES[typed_stage][:harmonized_stages])),
105
+ Identifier.build_stage(
106
+ harmonized_code: Identifier.build_harmonized_stage_code(self.class::TYPED_STAGES[typed_stage][:harmonized_stages])),
107
107
  ]
108
108
  end
109
109
 
@@ -122,7 +122,8 @@ module Pubid::Iso
122
122
  end
123
123
 
124
124
  [typed_stage.first,
125
- Stage.new(harmonized_code: HarmonizedStageCode.new(typed_stage[1][:harmonized_stages]))]
125
+ Identifier.build_stage(
126
+ harmonized_code: Identifier.build_harmonized_stage_code(typed_stage[1][:harmonized_stages]))]
126
127
  end
127
128
 
128
129
  # Resolve typed stage using stage harmonized stage code
@@ -188,18 +189,6 @@ module Pubid::Iso
188
189
  Identifier.create(**identifier_params)
189
190
  end
190
191
 
191
- def descendants
192
- ObjectSpace.each_object(Class).select { |klass| klass < self }
193
- end
194
-
195
- # @param type [Symbol, String] eg. :tr, :ts, "TS"
196
- # @return [Boolean] true if provided type matches with identifier's class type
197
- def has_type?(type)
198
- return type == self.type[:key] if type.is_a?(Symbol)
199
-
200
- self.type.key?(:values) ? self.type[:values].include?(type) : type.to_s.downcase.to_sym == self.type[:key]
201
- end
202
-
203
192
  # @param typed_stage [String, Symbol] typed stage, eg. "DTR" or :dtr
204
193
  # @return [Boolean] true when identifier has associated typed stage
205
194
  def has_typed_stage?(typed_stage)
@@ -241,6 +230,10 @@ module Pubid::Iso
241
230
  def get_update_codes
242
231
  UPDATE_CODES
243
232
  end
233
+
234
+ def type_match?(parameters)
235
+ parameters[:type] ? has_type?(parameters[:type]) : has_typed_stage?(parameters[:stage])
236
+ end
244
237
  end
245
238
 
246
239
  # Render URN identifier
@@ -337,7 +330,7 @@ module Pubid::Iso
337
330
  if self.class::TYPED_STAGES.key?(typed_stage)
338
331
  self.class::TYPED_STAGES[typed_stage][:abbr]
339
332
  else
340
- "#{stage.abbr} #{type[:key].to_s.upcase}"
333
+ stage ? "#{stage.abbr} #{type[:key].to_s.upcase}" : type[:key].to_s.upcase
341
334
  end
342
335
  end
343
336
 
@@ -346,7 +339,7 @@ module Pubid::Iso
346
339
  if self.class::TYPED_STAGES.key?(typed_stage)
347
340
  self.class::TYPED_STAGES[typed_stage][:name]
348
341
  else
349
- "#{stage.name} #{type[:title]}"
342
+ stage ? "#{stage.name} #{type[:title]}" : type[:title]
350
343
  end
351
344
  end
352
345
 
@@ -33,7 +33,7 @@ module Pubid::Iso
33
33
  if self.class::TYPED_STAGES.key?(typed_stage)
34
34
  super
35
35
  else
36
- stage.abbr
36
+ stage&.abbr
37
37
  end
38
38
  end
39
39
 
@@ -1,46 +1,12 @@
1
1
  module Pubid::Iso
2
2
  module Identifier
3
3
  class << self
4
- # Resolve identifier's class and create new identifier
5
- # @see Pubid::Identifier::Base.initialize for available options
6
- def create(**opts)
7
- resolve_identifier(
8
- opts[:type],
9
- opts[:stage],
10
- opts.reject { |k, _v| [:type, :stage].include?(k) })
11
- end
12
-
13
- # @param typed_stage_or_stage [String] typed stage or stage
14
- # @return identifier's class
15
- def resolve_identifier(type, typed_stage_or_stage, parameters = {})
16
- return Identifier::InternationalStandard.new(**parameters) if type.nil? && typed_stage_or_stage.nil?
17
-
18
- Base.descendants.each do |identifier_type|
19
- if type
20
- return identifier_type.new(stage: typed_stage_or_stage, **parameters) if identifier_type.has_type?(type)
21
-
22
- next
23
- elsif identifier_type.has_typed_stage?(typed_stage_or_stage)
24
- return identifier_type.new(stage: typed_stage_or_stage, **parameters)
25
- end
26
- end
27
-
28
- # When stage is not typed stage and type is not defined
29
- if type.nil? && (typed_stage_or_stage.is_a?(Stage) || Stage.has_stage?(typed_stage_or_stage))
30
- return Identifier::InternationalStandard.new(stage: typed_stage_or_stage, **parameters)
31
- end
32
-
33
- raise Errors::TypeStageParseError, "cannot parse typed stage or stage '#{typed_stage_or_stage}'" if type.nil?
34
-
35
- raise Errors::ParseTypeError, "cannot parse type #{type}"
36
- end
4
+ include Pubid::Core::Identifier
37
5
 
38
- # @see Pubid::Identifier::Base.parse
39
6
  def parse(*args)
40
7
  Base.parse(*args)
41
8
  end
42
9
 
43
- # Parse identifier from title
44
10
  def parse_from_title(title)
45
11
  title.split.reverse.inject(title) do |acc, part|
46
12
  return Base.parse(acc)
@@ -20,7 +20,7 @@ module Pubid::Iso
20
20
 
21
21
  DIR_SUPPLEMENTS = %w[Supplement SUP].freeze
22
22
 
23
- TYPED_STAGES = Pubid::Iso::Identifier::Base.descendants.map do |type|
23
+ TYPED_STAGES = Identifier.config.types.map do |type|
24
24
  type::TYPED_STAGES.map do |_, v|
25
25
  v.key?(:legacy_abbr) ? (v[:legacy_abbr] + [v[:abbr]]) : v[:abbr]
26
26
  end
@@ -74,7 +74,7 @@ module Pubid::Iso
74
74
  end
75
75
 
76
76
  rule(:roman_numerals) do
77
- array_to_str(%w[I V X L C D M]).repeat(1).as(:roman_numerals)
77
+ str("CD").absent? >> array_to_str(%w[I V X L C D M]).repeat(1).as(:roman_numerals)
78
78
  end
79
79
 
80
80
  rule(:year_digits) { (str("19") | str("20")) >> match('\d').repeat(2, 2) >> digits.absent? }
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Iso
3
- VERSION = "0.4.1".freeze
3
+ VERSION = "0.5.0".freeze
4
4
  end
5
5
  end
data/lib/pubid/iso.rb CHANGED
@@ -9,13 +9,8 @@ module Pubid
9
9
  end
10
10
  end
11
11
 
12
- STAGES_CONFIG = YAML.load_file(File.join(File.dirname(__FILE__), "../../stages.yaml"))
13
-
14
12
  require "pubid-core"
15
13
  require_relative "iso/errors"
16
- require_relative "iso/stage"
17
- require_relative "iso/type"
18
- require_relative "iso/harmonized_stage_code"
19
14
  require_relative "iso/transformer"
20
15
  require_relative "iso/identifier"
21
16
  require_relative "iso/identifier/base"
@@ -33,4 +28,67 @@ require_relative "iso/identifier/guide"
33
28
  require_relative "iso/identifier/recommendation"
34
29
  require_relative "iso/identifier/technology_trends_assessments"
35
30
  require_relative "iso/identifier/international_workshop_agreement"
31
+
32
+ config = Pubid::Core::Configuration.new
33
+ config.stages = YAML.load_file(File.join(File.dirname(__FILE__), "../../stages.yaml"))
34
+ config.default_type = Pubid::Iso::Identifier::InternationalStandard
35
+ config.type_class = Pubid::Core::Type
36
+ config.types = [Pubid::Iso::Identifier::InternationalStandard,
37
+ Pubid::Iso::Identifier::InternationalStandardizedProfile,
38
+ Pubid::Iso::Identifier::InternationalWorkshopAgreement,
39
+ Pubid::Iso::Identifier::Amendment,
40
+ Pubid::Iso::Identifier::Corrigendum,
41
+ Pubid::Iso::Identifier::PubliclyAvailableSpecification,
42
+ Pubid::Iso::Identifier::Recommendation,
43
+ Pubid::Iso::Identifier::Directives,
44
+ Pubid::Iso::Identifier::Supplement,
45
+ Pubid::Iso::Identifier::TechnicalCommittee,
46
+ Pubid::Iso::Identifier::TechnicalReport,
47
+ Pubid::Iso::Identifier::TechnicalSpecification,
48
+ Pubid::Iso::Identifier::TechnologyTrendsAssessments,
49
+ Pubid::Iso::Identifier::Guide]
50
+ config.type_names = { tr: {
51
+ long: "Technical Report",
52
+ short: "TR",
53
+ },
54
+ ts: {
55
+ long: "Technical Specification",
56
+ short: "TS",
57
+ },
58
+ is: {
59
+ long: "International Standard",
60
+ short: "IS",
61
+ },
62
+ pas: {
63
+ long: "Publicly Available Specification",
64
+ short: "PAS",
65
+ },
66
+ isp: {
67
+ long: "International Standardized Profiles",
68
+ short: "ISP",
69
+ },
70
+ guide: {
71
+ long: "Guide",
72
+ short: "Guide",
73
+ },
74
+ dir: {
75
+ long: "Directives",
76
+ short: "DIR",
77
+ },
78
+ dpas: {
79
+ long: "Publicly Available Specification Draft",
80
+ short: "DPAS",
81
+ },
82
+ cor: {
83
+ short: "Cor",
84
+ },
85
+ amd: {
86
+ short: "Amd",
87
+ },
88
+ r: {
89
+ long: "Recommendation",
90
+ short: "R",
91
+ } }.freeze
92
+ Pubid::Iso::Identifier.set_config(config)
93
+
36
94
  require_relative "iso/parser"
data/update_codes.yaml CHANGED
@@ -1 +1,2 @@
1
1
  ISO/R 657/IV: ISO/R 657-4:1969
2
+ ISO/IEC/IEEE 8802-22.2:2015/Amd.2:2017(E): ISO/IEC/IEEE 8802-22:2015/Amd.2:2017(E)
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.4.1
4
+ version: 0.5.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-02-10 00:00:00.000000000 Z
11
+ date: 2023-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 1.5.1
103
+ version: 1.6.0
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 1.5.1
110
+ version: 1.6.0
111
111
  description: Library to generate, parse and manipulate ISO PubID.
112
112
  email:
113
113
  - open.source@ribose.com
@@ -122,7 +122,6 @@ files:
122
122
  - lib/pubid-iso.rb
123
123
  - lib/pubid/iso.rb
124
124
  - lib/pubid/iso/errors.rb
125
- - lib/pubid/iso/harmonized_stage_code.rb
126
125
  - lib/pubid/iso/identifier.rb
127
126
  - lib/pubid/iso/identifier/amendment.rb
128
127
  - lib/pubid/iso/identifier/base.rb
@@ -161,9 +160,7 @@ files:
161
160
  - lib/pubid/iso/renderer/urn-supplement.rb
162
161
  - lib/pubid/iso/renderer/urn-tc.rb
163
162
  - lib/pubid/iso/renderer/urn.rb
164
- - lib/pubid/iso/stage.rb
165
163
  - lib/pubid/iso/transformer.rb
166
- - lib/pubid/iso/type.rb
167
164
  - lib/pubid/iso/version.rb
168
165
  - stages.yaml
169
166
  - update_codes.yaml
@@ -1,5 +0,0 @@
1
- module Pubid::Iso
2
- class HarmonizedStageCode < Pubid::Core::HarmonizedStageCode
3
-
4
- end
5
- end
@@ -1,5 +0,0 @@
1
- module Pubid::Iso
2
- class Stage < Pubid::Core::Stage
3
-
4
- end
5
- end
@@ -1,85 +0,0 @@
1
- module Pubid::Iso
2
- class Type
3
- attr_accessor :type
4
-
5
- TYPE_NAMES = {
6
- tr: {
7
- long: "Technical Report",
8
- short: "TR",
9
- },
10
- ts: {
11
- long: "Technical Specification",
12
- short: "TS",
13
- },
14
- is: {
15
- long: "International Standard",
16
- short: "IS",
17
- },
18
- pas: {
19
- long: "Publicly Available Specification",
20
- short: "PAS",
21
- },
22
- isp: {
23
- long: "International Standardized Profiles",
24
- short: "ISP",
25
- },
26
- guide: {
27
- long: "Guide",
28
- short: "Guide",
29
- },
30
- dir: {
31
- long: "Directives",
32
- short: "DIR",
33
- },
34
- dpas: {
35
- long: "Publicly Available Specification Draft",
36
- short: "DPAS",
37
- },
38
- cor: {
39
- short: "Cor",
40
- },
41
- amd: {
42
- short: "Amd",
43
- },
44
- r: {
45
- long: "Recommendation",
46
- short: "R",
47
- },
48
- }.freeze
49
-
50
- # Create new type
51
- # @param type [Symbol]
52
- def initialize(type = :is)
53
- type = type.to_s.downcase.to_sym unless type.is_a?(Symbol)
54
-
55
- raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type)
56
-
57
- @type = type
58
- end
59
-
60
- def self.parse(type_string)
61
- TYPE_NAMES.each do |type, values|
62
- return new(type) if values[:short] == type_string
63
- end
64
- raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type"
65
- end
66
-
67
- def to_s(format = :short)
68
- TYPE_NAMES[type][format]
69
- end
70
-
71
- def ==(other)
72
- return type == other if other.is_a?(Symbol)
73
-
74
- return false if other.nil?
75
-
76
- type == other.type
77
- end
78
-
79
- def self.has_type?(type)
80
- TYPE_NAMES.any? do |_, v|
81
- v[:short] == type
82
- end
83
- end
84
- end
85
- end