pubid-core 1.10.0 → 1.10.2

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: 135dbda350a5a305c463d0e56ed56303ad0a95dca7cbc6a74c38e66e37ae7780
4
- data.tar.gz: cf8b5afc99d6d4876d1aefd8fd21d95732f6cd26fefb18a9b4f1c4c2552a25ad
3
+ metadata.gz: ebe928af0a08e530bc616c88526fa076841d66f32fdb075640f67b7a72847b83
4
+ data.tar.gz: 438ade1f287d204a01aea76ea44e2bbc6cac186fd73bf5332bc1974dcec45df6
5
5
  SHA512:
6
- metadata.gz: 3401aa6d8c5ad4ab9e82361d2ec67b84976ddb47e661afb3f54ca3538388740acba8960c948520c49b0be8e4fb6781c37cea0d016ccd2d56044d1e2bf843c328
7
- data.tar.gz: f231d49c157d57b0d346ff9e246bd7cbe04b8ed770ac5b2c2b808f9c2ae8ff570f8d5b69649d94df35d5f239b5cdf15aa892775a85b0c0f9282a0090305ec33a
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
- # XXX: temporary hack to prepare typed_stage for rendering
69
- # probably need to convert typed_stage to class, now we store
70
- # typed_stage as key to typed stage (Symbol)
71
- if var.to_s == "@typed_stage" && @typed_stage
72
- [:typed_stage, self.class::TYPED_STAGES[@typed_stage][:abbr]]
73
- else
74
- [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)]
75
- end
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
@@ -101,5 +101,9 @@ module Pubid::Core
101
101
  def to_s(opts = {})
102
102
  empty_abbr?(**opts) ? "" : abbr
103
103
  end
104
+
105
+ def to_h
106
+ abbr
107
+ end
104
108
  end
105
109
  end
@@ -33,5 +33,10 @@ module Pubid::Core
33
33
  ":#{@number}:v1"
34
34
  end
35
35
  end
36
+
37
+ def to_h
38
+ { number: number,
39
+ year: year }
40
+ end
36
41
  end
37
42
  end
@@ -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: nil, harmonized_code: nil)
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
- if abbr
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
- @harmonized_code ||= HarmonizedStageCode.new(abbr, config: config)
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
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.10.0".freeze
3
+ VERSION = "1.10.2".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.10.0
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-01 00:00:00.000000000 Z
11
+ date: 2023-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake