pubid-core 1.12.9 → 1.12.11

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: ba717230345d92e43034c9974356212aadeb287ef99055dbcaee652f127db2be
4
- data.tar.gz: 72a1c56945dbb8ed8ad1749ac34bae5b998d10919dabf61cb2e0463102ea0534
3
+ metadata.gz: a529c731f2ad678ec6ecaacd1ae6aaff4710397d54d580cc3ee0931f48e7ec67
4
+ data.tar.gz: 5ecc01fa057e92d204bed040b092300261fe1b9ffc56ee31e399832fb5ac0ef0
5
5
  SHA512:
6
- metadata.gz: 7c8175936737bf172e01bd39934f70286af0c009f37e1faf44dfb884f4ce3e29fa0aab33dce2ebb5d65899169be19a912dc0e173f3b215b7331fe0970bb0d550
7
- data.tar.gz: f9103ba46e39e0b9f797a4cc831c7811d215266fe3b0afcf7c178ddb176c82bba83a2edd15b034aa1ffab8ac0e6d8ec5fcad976e4b79997c6a60ef8dd54373ca
6
+ metadata.gz: 67aee0e44b0c26e90459c6711a138751898088cb88a89420bf4cb7e7f9c7fd04127efd7b2adea726b7d11d2f10b93fc740ba8c486ebc726cc47af9b2c7c785c0
7
+ data.tar.gz: 816fa43aa6998ad40292041079bf96b76957480f3e393b63e77bdb21f898b595a0c7be4f82f283bc3553cdd816818fe9591ab513aafc8b3f189fd2826c21ba9b
data/README.adoc CHANGED
@@ -20,7 +20,6 @@ pubid_first.exclude(:year) == pubid_second
20
20
 
21
21
  === Using #to_h to convert identifier to hash
22
22
 
23
-
24
23
  [source,ruby]
25
24
  ----
26
25
  require "pubid-core"
@@ -29,3 +28,19 @@ pubid = Identifier.parse("ISO 1:1999")
29
28
  pubid.to_h
30
29
  => { publisher: "ISO", number: 1, year: 1999 }
31
30
  ----
31
+
32
+ === Using #new_edition_of? to compare identifiers
33
+
34
+ [source,ruby]
35
+ ----
36
+ require "pubid-core"
37
+
38
+ pubid_first = Identifier.parse("ISO 1:1999")
39
+ pubid_second = Identifier.parse("ISO 1:2000")
40
+
41
+ pubid_first.new_edition_of?(pubid_second)
42
+ => false
43
+ pubid_second.new_edition_of?(pubid_first)
44
+ => true
45
+
46
+ ----
@@ -0,0 +1,26 @@
1
+ module Pubid::Core
2
+ class Edition
3
+ include Comparable
4
+ attr_accessor :year, :number, :config
5
+
6
+ def initialize(config:, year: nil, number: nil)
7
+ @config = config
8
+ @year = year
9
+ @number = number
10
+ end
11
+
12
+ def <=>(other)
13
+ if other.year && year
14
+ return number <=> other.number if year == other.year
15
+
16
+ year <=> other.year
17
+ else
18
+ number <=> other.number
19
+ end
20
+ end
21
+
22
+ # def ==(other)
23
+ # other.year == year && number == other.number
24
+ # end
25
+ end
26
+ end
@@ -8,6 +8,7 @@ module Pubid::Core
8
8
  class TypeStageParseError < StandardError; end
9
9
  class WrongTypeError < StandardError; end
10
10
  class TypedStageInvalidError < StandardError; end
11
-
11
+ class AnotherDocumentError < StandardError; end
12
+ class CannotCompareError < StandardError; end
12
13
  end
13
14
  end
@@ -64,7 +64,7 @@ module Pubid::Core
64
64
  end
65
65
 
66
66
  def fuzzy?
67
- @stages.length > 1
67
+ @stages.length > 1 || @stages.none?
68
68
  end
69
69
 
70
70
  def stage
@@ -167,6 +167,36 @@ module Pubid::Core
167
167
  # @typed_stage = self.class::TYPED_STAGES[@typed_stage][:abbr] if @typed_stage
168
168
  end
169
169
 
170
+ # Checks if another identifier is newer edition of the same document
171
+ # @param other [Pubid::Core::Identifier::Base] pubid identifier to compare with
172
+ # @return [Boolean] true if another identifier is newer edition
173
+ def new_edition_of?(other)
174
+ if exclude(:year, :edition) != other.exclude(:year, :edition)
175
+ raise Errors::AnotherDocumentError, "cannot compare edition with #{other}"
176
+ end
177
+
178
+ if year.nil? || other.year.nil?
179
+ raise Errors::CannotCompareError, "cannot compare identifier without edition year"
180
+ end
181
+
182
+ if year == other.year && (edition || other.edition)
183
+ return false if other.edition.nil?
184
+
185
+ return true if edition.nil?
186
+
187
+ return edition > other.edition
188
+ end
189
+
190
+ year > other.year
191
+ end
192
+
193
+ # returns root identifier
194
+ def root
195
+ return base.base if base&.class&.method_defined?(:base) && base&.base
196
+
197
+ base || self
198
+ end
199
+
170
200
  class << self
171
201
  # Parses given identifier
172
202
  # @param code_or_params [String, Hash] code or hash from parser
@@ -7,6 +7,7 @@ module Pubid::Core::Renderer
7
7
  "fr" => "F",
8
8
  "en" => "E",
9
9
  "ar" => "A",
10
+ "es" => "S",
10
11
  }.freeze
11
12
 
12
13
  def initialize(params)
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.12.9".freeze
3
+ VERSION = "1.12.11".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.9
4
+ version: 1.12.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-12 00:00:00.000000000 Z
11
+ date: 2025-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -68,6 +68,7 @@ files:
68
68
  - lib/pubid/core/amendment.rb
69
69
  - lib/pubid/core/configuration.rb
70
70
  - lib/pubid/core/corrigendum.rb
71
+ - lib/pubid/core/edition.rb
71
72
  - lib/pubid/core/entity.rb
72
73
  - lib/pubid/core/errors.rb
73
74
  - lib/pubid/core/harmonized_stage_code.rb
@@ -86,7 +87,7 @@ homepage: https://github.com/metanorma/pubid-core
86
87
  licenses:
87
88
  - BSD-2-Clause
88
89
  metadata: {}
89
- post_install_message:
90
+ post_install_message:
90
91
  rdoc_options: []
91
92
  require_paths:
92
93
  - lib
@@ -101,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
102
  - !ruby/object:Gem::Version
102
103
  version: '0'
103
104
  requirements: []
104
- rubygems_version: 3.3.27
105
- signing_key:
105
+ rubygems_version: 3.5.22
106
+ signing_key:
106
107
  specification_version: 4
107
108
  summary: Library to generate, parse and manipulate PubID.
108
109
  test_files: []