pubid-core 1.5.2 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d11f67c2e955fc7a68dffe340770552b3148b1767bd3095600c35ec9696e239c
4
- data.tar.gz: f1db402f0c58b0340ea34da7b129021be3985aed9e6573d462645240717062b3
3
+ metadata.gz: b85bcef46a9327cb4c9ae474a84dea3b3986990082459b2f2bb37aa1c7578861
4
+ data.tar.gz: b7caa4de8dd3ac5c9e9b0d9bed0f3690207f48b5ec6366d4515a2ab138ab5b92
5
5
  SHA512:
6
- metadata.gz: 330a2e07981ef86fa2c26ac46636d91c8737fb6a0a11e84e2b91fc15f9c7b2eee98f3d6f0792534f924cbb343d80df634febfabc4325c87f5eede56481d10d2c
7
- data.tar.gz: e6b481d0431d82220983541c2f7162d087bc38894d9b8c8d7c6758b02adc87009a4b195ee639626af6a436ad833f6c4441b38d8c41553ff882b1c0405540f029
6
+ metadata.gz: 70ab4b5c6c3393811c898e3d66dbb9c1f1f80b34a5f9337697748ef06a6ee5f3331828b731b776fedeb44379c7766dda901cca146e15ba62731b17258e7d7cb5
7
+ data.tar.gz: 518912efd803e1ee6cef6d189fd618f4f52300109d057b35f9061437a199488b74c09cf2cafbb9622fe9a49c4e8fd7a0cea96e4e2861f53b6014e06277444c80
@@ -0,0 +1,6 @@
1
+ module Pubid::Core
2
+ class Configuration
3
+ attr_accessor :stages, :default_type, :type_class, :types, :type_names
4
+
5
+ end
6
+ end
@@ -4,5 +4,9 @@ module Pubid::Core
4
4
  class HarmonizedStageCodeInvalidError < StandardError; end
5
5
  class StageInvalidError < StandardError; end
6
6
  class HarmonizedStageRenderingError < StandardError; end
7
+ class ParseTypeError < StandardError; end
8
+ class TypeStageParseError < StandardError; end
9
+ class WrongTypeError < StandardError; end
10
+
7
11
  end
8
12
  end
@@ -2,28 +2,22 @@ module Pubid::Core
2
2
  class HarmonizedStageCode
3
3
  include Comparable
4
4
  # attr_accessor :stage, :substage
5
- attr_accessor :stages
6
-
7
- DESCRIPTIONS = STAGES_CONFIG["codes_description"]
8
- DRAFT_STAGES = STAGES_CONFIG["draft_codes"]
9
- CANCELED_STAGES = STAGES_CONFIG["canceled_codes"]
10
- PUBLISHED_STAGES = STAGES_CONFIG["published_codes"]
11
- STAGES_NAMES = STAGES_CONFIG["stage_codes"]
12
- SUBSTAGES_NAMES = STAGES_CONFIG["substage_codes"]
5
+ attr_accessor :config, :stages
13
6
 
14
7
  # @param stage_or_code [String,Array<String>] stage number or whole harmonized code with substage
15
8
  # or list or stages for fuzzy stages eg. "10", 10, "20.20", ["10.20", "20.20"]
16
9
  # or stage name eg. "proposal", "approval"
17
10
  # @param substage [Integer, String] eg. "00", 0
18
11
  # or substage name eg. "registration", "start_of_main_action"
19
- def initialize(stage_or_code, substage = "00")
12
+ def initialize(stage_or_code, substage = "00", config:)
13
+ @config = config
20
14
  @stages = if stage_or_code.is_a?(Array)
21
15
  stage_or_code
22
- elsif stage_or_code.is_a?(String) && DESCRIPTIONS.key?(stage_or_code)
16
+ elsif stage_or_code.is_a?(String) && config.stages["codes_description"].key?(stage_or_code)
23
17
  [stage_or_code]
24
18
  # when stage is stage name
25
- elsif STAGES_NAMES.key?(stage_or_code.to_s)
26
- ["#{STAGES_NAMES[stage_or_code.to_s]}.#{SUBSTAGES_NAMES[substage.to_s]}"]
19
+ elsif config.stages["stage_codes"].key?(stage_or_code.to_s)
20
+ ["#{config.stages["stage_codes"][stage_or_code.to_s]}.#{config.stages["substage_codes"][substage.to_s]}"]
27
21
  else
28
22
  # stage is number
29
23
  ["#{stage_or_code}.#{substage}"]
@@ -34,15 +28,15 @@ module Pubid::Core
34
28
  def validate_stages
35
29
  @stages.each do |stage|
36
30
  # raise an error when stage is wrong
37
- raise Errors::HarmonizedStageCodeInvalidError unless DESCRIPTIONS.key?(stage)
31
+ raise Errors::HarmonizedStageCodeInvalidError unless config.stages["codes_description"].key?(stage)
38
32
  end
39
33
  end
40
34
 
41
35
  def to_s
42
36
  if fuzzy?
43
- return "draft" if @stages.all? { |s| DRAFT_STAGES.include?(s) || CANCELED_STAGES.include?(s) }
37
+ return "draft" if @stages.all? { |s| config.stages["draft_codes"].include?(s) || config.stages["canceled_codes"].include?(s) }
44
38
 
45
- return "published" if @stages.all? { |s| PUBLISHED_STAGES.include?(s) }
39
+ return "published" if @stages.all? { |s| config.stages["published_codes"].include?(s) }
46
40
 
47
41
  raise Errors::HarmonizedStageRenderingError, "cannot render fuzzy stages"
48
42
  else
@@ -73,7 +67,7 @@ module Pubid::Core
73
67
  end
74
68
 
75
69
  def description
76
- DESCRIPTIONS[to_s]
70
+ config.stages["codes_description"][to_s]
77
71
  end
78
72
  end
79
73
  end
@@ -0,0 +1,157 @@
1
+ module Pubid::Core
2
+ module Identifier
3
+ class Base
4
+ attr_accessor :number, :publisher, :copublisher, :part,
5
+ :type, :year, :edition, :language, :amendments,
6
+ :corrigendums, :stage
7
+
8
+ # Creates new identifier from options provided:
9
+ # @param publisher [String] document's publisher, eg. "ISO"
10
+ # @param copublisher [String,Array<String>] document's copublisher, eg. "IEC"
11
+ # @param number [Integer] document's number, eg. "1234"
12
+ # @param part [String] document's part and subparts, eg. "1", "1-1A", "2-3D"
13
+ # @param type [String] document's type, eg. "TR", "TS"
14
+ # @param year [Integer] document's year, eg. "2020"
15
+ # @param edition [Integer] document's edition, eg. "1"
16
+ # @param language [String] document's translation language
17
+ # (available languages: "ru", "fr", "en", "ar")
18
+ # @param amendments [Array<Amendment>,Array<Hash>] document's amendments
19
+ # @param corrigendums [Array<Corrigendum>,Array<Hash>] document's corrigendums
20
+ # @see Amendment
21
+ # @see Corrigendum
22
+ def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,
23
+ year: nil, edition: nil, language: nil, amendments: nil,
24
+ corrigendums: nil, stage: nil)
25
+
26
+ if amendments
27
+ @amendments = amendments.map do |amendment|
28
+ if amendment.is_a?(Hash)
29
+ self.class.get_transformer_class.new.apply(:amendments => [amendment])[:amendments].first
30
+ else
31
+ amendment
32
+ end
33
+ end
34
+ end
35
+
36
+ if corrigendums
37
+ @corrigendums = corrigendums.map do |corrigendum|
38
+ if corrigendum.is_a?(Hash)
39
+ self.class.get_transformer_class.new.apply(:corrigendums => [corrigendum])[:corrigendums].first
40
+ else
41
+ corrigendum
42
+ end
43
+ end
44
+ end
45
+
46
+ @publisher = publisher.to_s
47
+ @number = number
48
+ @copublisher = copublisher if copublisher
49
+ @part = part.to_s if part
50
+ @type = type.to_s if type
51
+ @year = year.to_i if year
52
+ @edition = edition.to_i if edition
53
+ @language = language.to_s if language
54
+ @stage = stage if stage
55
+ end
56
+
57
+ # @return [String] Rendered URN identifier
58
+ def urn
59
+ Renderer::Urn.new(get_params).render
60
+ end
61
+
62
+ def get_params
63
+ instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
64
+ end
65
+
66
+ # Render identifier using default renderer
67
+ def to_s
68
+ self.class.get_renderer_class.new(get_params).render
69
+ end
70
+
71
+ class << self
72
+ # Parses given identifier
73
+ # @param code_or_params [String, Hash] code or hash from parser
74
+ # eg. "ISO 1234", { }
75
+ # @return [Pubid::Core::Identifier] identifier
76
+ def parse(code_or_params)
77
+ params = code_or_params.is_a?(String) ?
78
+ get_parser_class.new.parse(update_old_code(code_or_params)) : code_or_params
79
+ transform(params.is_a?(Array) ? array_to_hash(params) : params)
80
+ rescue Parslet::ParseFailed => failure
81
+ raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
82
+ end
83
+
84
+ # Converts array of hashes into single hash
85
+ # array like [{ publisher: "ISO" }, { number: 1 }] to hash { publisher: "ISO", number: 1 }
86
+ # @param params [Array<Hash>] input array of hashes, eg. [{ a: 1 }, { b: 2 }]
87
+ def array_to_hash(params)
88
+ params.inject({}) do |r, i|
89
+ result = r
90
+ i.each do |k, v|
91
+ result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
92
+ end
93
+ result
94
+ end
95
+ end
96
+
97
+ # Transform parameters hash or array or hashes to identifier
98
+ def transform(params)
99
+ # run transform through each element,
100
+ # like running transformer.apply(number: 1) and transformer.apply(year: 1999)
101
+ # instead of running transformer on whole hash, like running transformer.apply({ number: 1, year: 1999 })
102
+ # where rule for number or year only will be not applied
103
+ # transformation only applied to rules matching the whole hash
104
+
105
+ identifier_params = params.map do |k, v|
106
+ get_transformer_class.new.apply(k => v).to_a.first
107
+ end.to_h
108
+
109
+ new(**identifier_params)
110
+ end
111
+
112
+ # @param type [Symbol, String] eg. :tr, :ts, "TS"
113
+ # @return [Boolean] true if provided type matches with identifier's class type
114
+ def has_type?(type)
115
+ return type == self.type[:key] if type.is_a?(Symbol)
116
+
117
+ self.type.key?(:values) ? self.type[:values].include?(type) : type.to_s.downcase.to_sym == self.type[:key]
118
+ end
119
+
120
+ def get_amendment_class
121
+ Amendment
122
+ end
123
+
124
+ def get_corrigendum_class
125
+ Corrigendum
126
+ end
127
+
128
+ def get_renderer_class
129
+ Renderer::Base
130
+ end
131
+
132
+ def get_transformer_class
133
+ Transformer
134
+ end
135
+
136
+ # @return [Hash, nil] replacement patterns
137
+ def get_update_codes
138
+ nil
139
+ end
140
+
141
+ def update_old_code(code)
142
+ return code unless get_update_codes
143
+
144
+ get_update_codes.each do |from, to|
145
+ code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to)
146
+ end
147
+ code
148
+ end
149
+
150
+ # Returns true when identifier's type match with provided parameters
151
+ def type_match?(parameters)
152
+ has_type?(parameters[:type])
153
+ end
154
+ end
155
+ end
156
+ end
157
+ end
@@ -1,153 +1,66 @@
1
1
  module Pubid::Core
2
- class Identifier
3
- attr_accessor :number, :publisher, :copublisher, :part,
4
- :type, :year, :edition, :language, :amendments,
5
- :corrigendums
2
+ module Identifier
3
+ attr_accessor :config
4
+ @config = nil
5
+
6
+ # Resolve identifier's class and create new identifier
7
+ # @see Pubid::Identifier::Base.initialize for available options
8
+ def create(**opts)
9
+ resolve_identifier(opts)
10
+ # resolve_identifier(
11
+ # opts[:type],
12
+ # opts[:stage],
13
+ # opts.reject { |k, _v| [:type, :stage].include?(k) },
14
+ # )
15
+ end
6
16
 
7
- # Creates new identifier from options provided:
8
- # @param publisher [String] document's publisher, eg. "ISO"
9
- # @param copublisher [String,Array<String>] document's copublisher, eg. "IEC"
10
- # @param number [Integer] document's number, eg. "1234"
11
- # @param part [String] document's part and subparts, eg. "1", "1-1A", "2-3D"
12
- # @param type [String] document's type, eg. "TR", "TS"
13
- # @param year [Integer] document's year, eg. "2020"
14
- # @param edition [Integer] document's edition, eg. "1"
15
- # @param language [String] document's translation language
16
- # (available languages: "ru", "fr", "en", "ar")
17
- # @param amendments [Array<Amendment>,Array<Hash>] document's amendments
18
- # @param corrigendums [Array<Corrigendum>,Array<Hash>] document's corrigendums
19
- # @see Amendment
20
- # @see Corrigendum
21
- def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,
22
- year: nil, edition: nil, language: nil, amendments: nil,
23
- corrigendums: nil)
17
+ # @param typed_stage_or_stage [String] typed stage or stage
18
+ # @return identifier's class
19
+ def resolve_identifier(parameters = {})
20
+ return @config.default_type.new(**parameters) if parameters[:type].nil? && parameters[:stage].nil?
24
21
 
25
- if amendments
26
- @amendments = amendments.map do |amendment|
27
- if amendment.is_a?(Hash)
28
- self.class.get_transformer_class.new.apply(:amendments => [amendment])[:amendments].first
29
- else
30
- amendment
31
- end
32
- end
22
+ @config.types.each do |identifier_type|
23
+ return identifier_type.new(**parameters) if identifier_type.type_match?(parameters)
33
24
  end
34
25
 
35
- if corrigendums
36
- @corrigendums = corrigendums.map do |corrigendum|
37
- if corrigendum.is_a?(Hash)
38
- self.class.get_transformer_class.new.apply(:corrigendums => [corrigendum])[:corrigendums].first
39
- else
40
- corrigendum
41
- end
42
- end
26
+ # When stage is not typed stage and type is not defined
27
+ if parameters[:type].nil? && (parameters[:stage].is_a?(Stage) || has_stage?(parameters[:stage]))
28
+ return @config.default_type.new(stage: parameters[:stage], **parameters)
43
29
  end
44
30
 
45
- @publisher = publisher.to_s
46
- @number = number
47
- @copublisher = copublisher if copublisher
48
- @part = part.to_s if part
49
- @type = type.to_s if type
50
- @year = year.to_i if year
51
- @edition = edition.to_i if edition
52
- @language = language.to_s if language
53
- end
31
+ raise Errors::TypeStageParseError, "cannot parse typed stage or stage '#{parameters[:stage]}'" if parameters[:type].nil?
54
32
 
55
- # @return [String] Rendered URN identifier
56
- def urn
57
- Renderer::Urn.new(get_params).render
33
+ raise Errors::ParseTypeError, "cannot parse type #{parameters[:type]}"
58
34
  end
59
35
 
60
- def get_params
61
- instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
36
+ # @see Pubid::Identifier::Base.parse
37
+ def parse(*args)
38
+ Base.parse(*args)
62
39
  end
63
40
 
64
- # Render identifier using default renderer
65
- def to_s
66
- self.class.get_renderer_class.new(get_params).render
41
+ # Parse identifier from title
42
+ def set_config(config)
43
+ @config = config
67
44
  end
68
45
 
69
- class << self
70
- # Parses given identifier
71
- # @param code_or_params [String, Hash] code or hash from parser
72
- # eg. "ISO 1234", { }
73
- # @return [Pubid::Core::Identifier] identifier
74
- def parse(code_or_params)
75
- params = code_or_params.is_a?(String) ?
76
- get_parser_class.new.parse(update_old_code(code_or_params)) : code_or_params
77
- transform(params.is_a?(Array) ? array_to_hash(params) : params)
78
- rescue Parslet::ParseFailed => failure
79
- raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
80
- end
81
-
82
- # Converts array of hashes into single hash
83
- # array like [{ publisher: "ISO" }, { number: 1 }] to hash { publisher: "ISO", number: 1 }
84
- # @param params [Array<Hash>] input array of hashes, eg. [{ a: 1 }, { b: 2 }]
85
- def array_to_hash(params)
86
- params.inject({}) do |r, i|
87
- result = r
88
- i.each do |k, v|
89
- result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
90
- end
91
- result
92
- end
93
- end
94
-
95
- # Transform parameters hash or array or hashes to identifier
96
- def transform(params)
97
- # run transform through each element,
98
- # like running transformer.apply(number: 1) and transformer.apply(year: 1999)
99
- # instead of running transformer on whole hash, like running transformer.apply({ number: 1, year: 1999 })
100
- # where rule for number or year only will be not applied
101
- # transformation only applied to rules matching the whole hash
102
-
103
- identifier_params = params.map do |k, v|
104
- get_transformer_class.new.apply(k => v).to_a.first
105
- end.to_h
106
-
107
- new(**identifier_params)
108
- end
109
-
110
- def descendants
111
- ObjectSpace.each_object(Class).select { |klass| klass < self }
112
- end
113
-
114
- # @param type [Symbol, String] eg. :tr, :ts, "TS"
115
- # @return [Boolean] true if provided type matches with identifier's class type
116
- def has_type?(type)
117
- return type == self.type[:key] if type.is_a?(Symbol)
118
-
119
- self.type.key?(:values) ? self.type[:values].include?(type) : type.to_s.downcase.to_sym == self.type[:key]
120
- end
121
-
122
- def get_amendment_class
123
- Amendment
124
- end
125
-
126
- def get_corrigendum_class
127
- Corrigendum
128
- end
129
-
130
- def get_renderer_class
131
- Renderer::Base
132
- end
46
+ def build_stage(**args)
47
+ Stage.new(config: @config, **args)
48
+ end
133
49
 
134
- def get_transformer_class
135
- Transformer
136
- end
50
+ def parse_stage(stage)
51
+ Stage.parse(stage, config: @config)
52
+ end
137
53
 
138
- # @return [Hash, nil] replacement patterns
139
- def get_update_codes
140
- nil
141
- end
54
+ def has_stage?(stage)
55
+ Stage.has_stage?(stage, config: @config)
56
+ end
142
57
 
143
- def update_old_code(code)
144
- return code unless get_update_codes
58
+ def build_type(type, **args)
59
+ @config.type_class.new(type, config: @config, **args)
60
+ end
145
61
 
146
- get_update_codes.each do |from, to|
147
- code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to)
148
- end
149
- code
150
- end
62
+ def build_harmonized_stage_code(stage_or_code, substage = "00")
63
+ HarmonizedStageCode.new(stage_or_code, substage, config: @config)
151
64
  end
152
65
  end
153
66
  end
@@ -1,27 +1,27 @@
1
1
  module Pubid::Core
2
2
  class Stage
3
- attr_accessor :abbr, :harmonized_code
4
-
5
- STAGES = STAGES_CONFIG["abbreviations"]
3
+ attr_accessor :config, :abbr, :harmonized_code
6
4
 
7
5
  # @param abbr [String, Symbol] abbreviation eg. :PWI, :WD
8
6
  # @param harmonized_code [String, Float, HarmonizedStageCode]
9
- def initialize(abbr: nil, harmonized_code: nil)
7
+ # @param config [Configuration]
8
+ def initialize(config:, abbr: nil, harmonized_code: nil)
9
+ @config = config
10
10
  @abbr = abbr&.to_s
11
11
 
12
12
  if harmonized_code
13
13
  @harmonized_code = if harmonized_code.is_a?(HarmonizedStageCode)
14
14
  harmonized_code
15
15
  else
16
- HarmonizedStageCode.new(harmonized_code)
16
+ HarmonizedStageCode.new(harmonized_code, config: config)
17
17
  end
18
18
  @abbr ||= lookup_abbr(@harmonized_code.stages)
19
19
  end
20
20
 
21
21
  if abbr
22
- raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless STAGES.key?(abbr.to_s)
22
+ raise Errors::StageInvalidError, "#{abbr} is not valid stage" unless config.stages["abbreviations"].key?(abbr.to_s)
23
23
 
24
- @harmonized_code ||= HarmonizedStageCode.new(lookup_code(abbr))
24
+ @harmonized_code ||= HarmonizedStageCode.new(lookup_code(abbr), config: config)
25
25
  end
26
26
  end
27
27
 
@@ -31,7 +31,7 @@ module Pubid::Core
31
31
  def lookup_abbr(lookup_code)
32
32
  lookup_code = lookup_code.first if lookup_code.is_a?(Array) && lookup_code.count == 1
33
33
 
34
- STAGES.each do |abbr, codes|
34
+ config.stages["abbreviations"].each do |abbr, codes|
35
35
  case codes
36
36
  when Array
37
37
  if lookup_code.is_a?(Array)
@@ -51,25 +51,25 @@ module Pubid::Core
51
51
  end
52
52
 
53
53
  def lookup_code(lookup_abbr)
54
- STAGES[lookup_abbr.to_s]
54
+ config.stages["abbreviations"][lookup_abbr.to_s]
55
55
  end
56
56
 
57
- def self.parse(stage)
57
+ def self.parse(stage, config:)
58
58
  if /\A[\d.]+\z/.match?(stage)
59
- Stage.new(harmonized_code: stage)
59
+ Stage.new(harmonized_code: stage, config: config)
60
60
  else
61
61
  raise Errors::StageInvalidError unless stage.is_a?(Symbol) || stage.is_a?(String) || stage.is_a?(Parslet::Slice)
62
62
 
63
- Stage.new(abbr: stage.to_s)
63
+ Stage.new(abbr: stage.to_s, config: config)
64
64
  end
65
65
  end
66
66
 
67
67
  # @return [Boolean] true if stage exists
68
- def self.has_stage?(stage)
68
+ def self.has_stage?(stage, config:)
69
69
  if stage.is_a?(Stage)
70
- STAGES.key?(stage.abbr.to_sym)
70
+ config.stages["abbreviations"].key?(stage.abbr.to_sym)
71
71
  else
72
- STAGES.key?(stage.to_s) || /\A[\d.]+\z/.match?(stage)
72
+ config.stages["abbreviations"].key?(stage.to_s) || /\A[\d.]+\z/.match?(stage)
73
73
  end
74
74
  end
75
75
 
@@ -80,7 +80,7 @@ module Pubid::Core
80
80
 
81
81
  # Return stage name, eg. "Draft International Standard" for "DIS"
82
82
  def name
83
- STAGES_CONFIG["names"][abbr.to_s]
83
+ config.stages["names"][abbr.to_s]
84
84
  end
85
85
 
86
86
  # @param with_prf [Boolean]
@@ -1,25 +1,30 @@
1
1
  module Pubid::Core
2
2
  class Type
3
- attr_accessor :type
3
+ attr_accessor :type, :config
4
+
4
5
  # Create new type
5
6
  # @param type [Symbol]
6
- def initialize(type = DEFAULT_TYPE)
7
+ def initialize(type = nil, config:)
8
+ @config = config
9
+ if type.nil?
10
+ type = @config.default_type.type[:key]
11
+ end
7
12
  type = type.to_s.downcase.to_sym unless type.is_a?(Symbol)
8
13
 
9
- raise Errors::WrongTypeError, "#{type} type is not available" unless TYPE_NAMES.key?(type)
14
+ raise Errors::WrongTypeError, "#{type} type is not available" unless @config.type_names.key?(type)
10
15
 
11
16
  @type = type
12
17
  end
13
18
 
14
- def self.parse(type_string)
15
- TYPE_NAMES.each do |type, values|
16
- return new(type) if values[:short] == type_string
19
+ def self.parse(type_string, config:)
20
+ config.type_names.each do |type, values|
21
+ return new(type, config: config) if values[:short] == type_string
17
22
  end
18
23
  raise Errors::ParseTypeError, "Cannot parse '#{type_string}' type"
19
24
  end
20
25
 
21
26
  def to_s(format = :short)
22
- TYPE_NAMES[type][format]
27
+ @config.type_names[type][format]
23
28
  end
24
29
 
25
30
  def ==(other)
@@ -30,8 +35,8 @@ module Pubid::Core
30
35
  type == other.type
31
36
  end
32
37
 
33
- def self.has_type?(type)
34
- TYPE_NAMES.any? do |_, v|
38
+ def self.has_type?(type, config:)
39
+ config.type_names.any? do |_, v|
35
40
  v[:short] == type
36
41
  end
37
42
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.5.2".freeze
3
+ VERSION = "1.6.0".freeze
4
4
  end
5
5
  end
data/lib/pubid/core.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "parslet"
2
2
 
3
+ require_relative "core/configuration"
3
4
  require_relative "core/errors"
4
5
  require_relative "core/parser"
5
6
  require_relative "core/type"
@@ -10,5 +11,6 @@ require_relative "core/transformer"
10
11
  require_relative "core/renderer/base"
11
12
  require_relative "core/renderer/urn"
12
13
  require_relative "core/identifier"
14
+ require_relative "core/identifier/base"
13
15
  require_relative "core/harmonized_stage_code"
14
16
  require_relative "core/stage"
data/lib/pubid-core.rb CHANGED
@@ -1,3 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ module Pubid::Core
4
+ def self.configuration
5
+ @configuration ||= Configuration.new
6
+ end
7
+
8
+ def self.configure
9
+ yield(configuration)
10
+ end
11
+ end
12
+
3
13
  require_relative "pubid/core"
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.5.2
4
+ version: 1.6.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-03-07 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
@@ -66,10 +66,12 @@ files:
66
66
  - lib/pubid-core.rb
67
67
  - lib/pubid/core.rb
68
68
  - lib/pubid/core/amendment.rb
69
+ - lib/pubid/core/configuration.rb
69
70
  - lib/pubid/core/corrigendum.rb
70
71
  - lib/pubid/core/errors.rb
71
72
  - lib/pubid/core/harmonized_stage_code.rb
72
73
  - lib/pubid/core/identifier.rb
74
+ - lib/pubid/core/identifier/base.rb
73
75
  - lib/pubid/core/parser.rb
74
76
  - lib/pubid/core/renderer/base.rb
75
77
  - lib/pubid/core/renderer/urn.rb