pubid-core 1.12.3 → 1.12.5

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: 64675ccfe8fcc5a82c51595d306ac0c8d982979397d8c2ba103b3a37dd919902
4
- data.tar.gz: c04b2739095caf3d57c1679dc0fbc1132ddaea147ebe4e46ab9d059dfcfb1f27
3
+ metadata.gz: 820f263f5eb799412cef807145783bd70c29aeb8b75615380bf963d59e085a36
4
+ data.tar.gz: be7646e893635ad8a8ceb11f13ef0aca7817678e823e5994d353df8b28f9a669
5
5
  SHA512:
6
- metadata.gz: 944948eb1d762f72e9e1ef616e5322fdb5600175da5b93c05d9084bd082727a0f0e7b598d7c3324087f90417092a55da9cbc53c4bff9f1643acd210611586dad
7
- data.tar.gz: 2a5eee234aaad3fa30f52173c9a9736acc713ffd7a9964f6aea9ef9ff29124033832bff07f0dfdd9b4029d59d84792af04f410d009d45cc860004694e84d2a4e
6
+ metadata.gz: 369026a954871677ab43d9bdf05c0426a661a769ca264ecb4d83ac2c448b8036fe6baed64ec645361c34eb85bca91a3b26281f4956cbc7aedb190730539b67e0
7
+ data.tar.gz: f4b6d86709acc7c06d893cad292d8e7cb63ead59abe9cb7a289216d29e408e154751ebb75acfc2a2207564984ef3416ab276bf071e63e86e8b03d666e4961d96
@@ -1,14 +1,23 @@
1
1
  module Pubid::Core
2
2
  class Configuration
3
- attr_accessor :stages, :default_type, :type_class, :types, :type_names, :stage_class, :typed_stage_class
3
+ attr_accessor :stages, :default_type, :type_class, :types, :type_names,
4
+ :stage_class, :typed_stage_class, :prefixes, :identifier_module
4
5
 
5
6
  def initialize
7
+ @identifier_module = identifier_module
6
8
  @type_class = Pubid::Core::Type
7
9
  @stage_class = Pubid::Core::Stage
8
10
  @typed_stage_class = Pubid::Core::TypedStage
9
11
  @types = []
10
12
  end
11
13
 
14
+ def prefixes
15
+ # return default prefix using module name e.g.
16
+ # "ISO" for Pubid::Iso::Identifier
17
+ # "CORE" for Pubid::Core::TestIdentifier
18
+ @prefixes || [@identifier_module.to_s.split("::")[1].upcase]
19
+ end
20
+
12
21
  def typed_stages
13
22
  types.inject({}) do |res, type|
14
23
  res.merge(type::TYPED_STAGES)
@@ -61,7 +61,7 @@ module Pubid::Core
61
61
  end
62
62
 
63
63
  # @return [Hash] Identifier's parameters
64
- def to_h(deep: true)
64
+ def to_h(deep: true, add_type: true)
65
65
  result = instance_variables.map do |var|
66
66
  value = instance_variable_get(var)
67
67
 
@@ -76,8 +76,8 @@ module Pubid::Core
76
76
  ]
77
77
  end.to_h
78
78
 
79
- if respond_to?(:type)
80
- result[:type] = self.type[:short]
79
+ if add_type && respond_to?(:type) && type[:short]
80
+ result[:type] = type[:short]
81
81
  end
82
82
 
83
83
  result
@@ -92,8 +92,22 @@ module Pubid::Core
92
92
  self.class.get_renderer_class.new(to_h(deep: false)).render
93
93
  end
94
94
 
95
- def exclude(*attrs)
96
- self.class.new(**to_h.reject { |k| attrs.include?(k) })
95
+ def exclude(*args)
96
+ nested_exclusions, top_level_exclusions = args.partition { |arg| arg.is_a?(Hash) }
97
+
98
+ nested_exclusions = nested_exclusions.reduce({}, :merge)
99
+
100
+ excluded_hash = to_h(add_type: false)
101
+ .reject { |k, v| top_level_exclusions.include?(k) }
102
+ .each_with_object({}) do |(k, v), memo|
103
+ memo[k] = if v.is_a?(Hash) && nested_exclusions.key?(k)
104
+ v.reject { |key, _| nested_exclusions[k].include?(key) }
105
+ else
106
+ v
107
+ end
108
+ end
109
+
110
+ self.class.new(**excluded_hash)
97
111
  end
98
112
 
99
113
  def typed_stage_abbrev
@@ -36,6 +36,7 @@ module Pubid::Core
36
36
  # Parse identifier from title
37
37
  def set_config(config)
38
38
  @config = config
39
+ @config.identifier_module = self
39
40
  end
40
41
 
41
42
  def build_stage(**args)
@@ -61,5 +62,11 @@ module Pubid::Core
61
62
  def build_typed_stage(**args)
62
63
  @config.typed_stage_class.new(config: @config, **args)
63
64
  end
65
+
66
+ def parseable?(pubid)
67
+ @config.prefixes.any? do |prefix|
68
+ pubid.start_with?(prefix)
69
+ end
70
+ end
64
71
  end
65
72
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.12.3".freeze
3
+ VERSION = "1.12.5".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.12.3
4
+ version: 1.12.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-19 00:00:00.000000000 Z
11
+ date: 2024-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake