pubid-core 1.10.0 → 1.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +29 -0
- data/lib/pubid/core/identifier/base.rb +13 -8
- data/lib/pubid/core/stage.rb +4 -0
- data/lib/pubid/core/supplement.rb +5 -0
- data/lib/pubid/core/typed_stage.rb +5 -7
- data/lib/pubid/core/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebe928af0a08e530bc616c88526fa076841d66f32fdb075640f67b7a72847b83
|
4
|
+
data.tar.gz: 438ade1f287d204a01aea76ea44e2bbc6cac186fd73bf5332bc1974dcec45df6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4d60fc2b2dc1f146a31f3b03275522d598b18adc8e86c9b229fd9cea4375c851fea88b02e96ff74e2c55d6e215e849ec7f026f53fa34d18a77a47d7e2312a81
|
7
|
+
data.tar.gz: 8d7e1fffb7cf18ff56524be8187fb4895a2e1043ccc1941c9a6500f834bf566461758cca8aac34be8c64bc637610602d65129e4b658e76a973ac91ea4a7a5541
|
data/README.adoc
CHANGED
@@ -1,2 +1,31 @@
|
|
1
1
|
= Publication identifiers parsing library
|
2
2
|
|
3
|
+
== Usage
|
4
|
+
|
5
|
+
=== Exclude attributes when compare
|
6
|
+
|
7
|
+
[source,ruby]
|
8
|
+
----
|
9
|
+
require "pubid-core"
|
10
|
+
|
11
|
+
pubid_first = Identifier.parse("ISO 1:1999")
|
12
|
+
pubid_second = Identifier.parse("ISO 1")
|
13
|
+
|
14
|
+
pubid_first == pubid_second
|
15
|
+
=> false
|
16
|
+
|
17
|
+
pubid_first.exclude(:year) == pubid_second
|
18
|
+
=> true
|
19
|
+
----
|
20
|
+
|
21
|
+
=== Using #to_h to convert identifier to hash
|
22
|
+
|
23
|
+
|
24
|
+
[source,ruby]
|
25
|
+
----
|
26
|
+
require "pubid-core"
|
27
|
+
|
28
|
+
pubid = Identifier.parse("ISO 1:1999")
|
29
|
+
pubid.to_h
|
30
|
+
=> { publisher: "ISO", number: 1, year: 1999 }
|
31
|
+
----
|
@@ -65,14 +65,15 @@ module Pubid::Core
|
|
65
65
|
# @return [Hash] Identifier's parameters
|
66
66
|
def to_h
|
67
67
|
instance_variables.map do |var|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
68
|
+
value = instance_variable_get(var)
|
69
|
+
|
70
|
+
[var.to_s.gsub("@", "").to_sym,
|
71
|
+
if value.is_a?(Array)
|
72
|
+
value.map { |v| v.respond_to?(:to_h) ? v.to_h : v }
|
73
|
+
else
|
74
|
+
value.respond_to?(:to_h) ? value.to_h : value
|
75
|
+
end
|
76
|
+
]
|
76
77
|
end.to_h
|
77
78
|
end
|
78
79
|
|
@@ -85,6 +86,10 @@ module Pubid::Core
|
|
85
86
|
self.class.get_renderer_class.new(to_h).render
|
86
87
|
end
|
87
88
|
|
89
|
+
def exclude(*attrs)
|
90
|
+
self.class.new(**to_h.reject { |k| attrs.include?(k) })
|
91
|
+
end
|
92
|
+
|
88
93
|
def typed_stage_abbrev
|
89
94
|
if stage.is_a?(TypedStage)
|
90
95
|
return stage.to_s
|
data/lib/pubid/core/stage.rb
CHANGED
@@ -5,7 +5,7 @@ module Pubid::Core
|
|
5
5
|
# @param config [Configuration]
|
6
6
|
# @param abbr [Symbol] typed stage symbol, e.g. :dtr
|
7
7
|
# @param harmonized_code [String, Float, HarmonizedStageCode]
|
8
|
-
def initialize(config:, abbr
|
8
|
+
def initialize(config:, abbr:, harmonized_code: nil)
|
9
9
|
@config = config
|
10
10
|
@abbr = abbr
|
11
11
|
|
@@ -18,19 +18,17 @@ module Pubid::Core
|
|
18
18
|
# @abbr ||= lookup_abbr(@harmonized_code.stages)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
raise Errors::TypedStageInvalidError, "#{abbr} is not valid typed stage" unless config.typed_stages.key?(abbr)
|
21
|
+
raise Errors::TypedStageInvalidError, "#{abbr} is not valid typed stage" unless config.typed_stages.key?(abbr)
|
23
22
|
|
24
|
-
|
25
|
-
end
|
23
|
+
@harmonized_code ||= HarmonizedStageCode.new(abbr, config: config)
|
26
24
|
end
|
27
25
|
|
28
26
|
# Compares one stage with another
|
29
27
|
# should return false if
|
30
28
|
def ==(other)
|
31
|
-
return false unless other
|
29
|
+
return false unless other.is_a?(self.class)
|
32
30
|
|
33
|
-
return abbr == other if other.is_a?(Symbol)
|
31
|
+
# return abbr == other if other.is_a?(Symbol)
|
34
32
|
|
35
33
|
other&.harmonized_code == harmonized_code
|
36
34
|
end
|
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.10.
|
4
|
+
version: 1.10.2
|
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-11-
|
11
|
+
date: 2023-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|