pubid-core 1.12.8 → 1.12.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +16 -1
- data/lib/pubid/core/edition.rb +26 -0
- data/lib/pubid/core/errors.rb +2 -1
- data/lib/pubid/core/identifier/base.rb +35 -2
- data/lib/pubid/core/renderer/base.rb +1 -0
- data/lib/pubid/core/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 830c9694368efc359626ee62bb062fd449692dc0fdd70b26763f647f8702e263
|
4
|
+
data.tar.gz: 26eee79eae6bdecd35adeb61fa000d7346c653b27de8fd2259dbdddbb8f1e655
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/pubid/core/errors.rb
CHANGED
@@ -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
|
@@ -89,10 +89,13 @@ module Pubid::Core
|
|
89
89
|
end
|
90
90
|
|
91
91
|
def ==(other)
|
92
|
-
|
92
|
+
case other
|
93
|
+
when String
|
93
94
|
to_s == other
|
94
|
-
|
95
|
+
when Identifier::Base
|
95
96
|
to_h == other.to_h
|
97
|
+
when Hash
|
98
|
+
to_h == other
|
96
99
|
else
|
97
100
|
raise Errors::WrongTypeError, "cannot compare with #{other.class} type"
|
98
101
|
end
|
@@ -164,6 +167,36 @@ module Pubid::Core
|
|
164
167
|
# @typed_stage = self.class::TYPED_STAGES[@typed_stage][:abbr] if @typed_stage
|
165
168
|
end
|
166
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
|
+
|
167
200
|
class << self
|
168
201
|
# Parses given identifier
|
169
202
|
# @param code_or_params [String, Hash] code or hash from parser
|
data/lib/pubid/core/version.rb
CHANGED
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.
|
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-
|
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
|