pubid-core 1.12.9 → 1.12.10

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: 830c9694368efc359626ee62bb062fd449692dc0fdd70b26763f647f8702e263
4
+ data.tar.gz: 26eee79eae6bdecd35adeb61fa000d7346c653b27de8fd2259dbdddbb8f1e655
5
5
  SHA512:
6
- metadata.gz: 7c8175936737bf172e01bd39934f70286af0c009f37e1faf44dfb884f4ce3e29fa0aab33dce2ebb5d65899169be19a912dc0e173f3b215b7331fe0970bb0d550
7
- data.tar.gz: f9103ba46e39e0b9f797a4cc831c7811d215266fe3b0afcf7c178ddb176c82bba83a2edd15b034aa1ffab8ac0e6d8ec5fcad976e4b79997c6a60ef8dd54373ca
6
+ metadata.gz: 49f386ef299df70fc725137b186f8e375033e62874be0ec871384a131451f3f5cd28e28aa2474a8d15adeb9c887b1e9b8c47709e91211b8ec4e44b93de2a8616
7
+ data.tar.gz: 2841a2ef9b8ffe2e8b4e6577f3782ba110fb4e9a6bd6564eb428aea9675173d3743b9e65c0b388b3ad2e6f334f50eeaabc4fe25459e8ef7d2584ce0d1d028b6c
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
@@ -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.10".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.10
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-07-12 00:00:00.000000000 Z
11
+ date: 2024-10-30 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