pubid-core 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cc372a0160fd8c1a670be2957f3b3e0a98766dd89ed6f8782b1f52085bcbb8f
4
- data.tar.gz: 9a0d58a218b982531fe206bd7505203428ec6f9d7dcbaa649f80267b09e44030
3
+ metadata.gz: 2a3c1e99b3327c14f2364992238d1d6a4040809dca85a6640254e2669784a449
4
+ data.tar.gz: ca910a6333a2e5e9dc1c907577bee5c3e0c34bc6a891e07b310f4be39e9ecc59
5
5
  SHA512:
6
- metadata.gz: 04e0297f6ce7bea0cabc3e41c7718e1eee523f93e039fa42f4b08c7a34d4fcb7b3c979fbcdb2c0c7bd980b4523d2c6985198cf61f03bb1fad64765a51ad2ccd8
7
- data.tar.gz: f0c98e3158ff918fe1f0df2e5ae3c2e7cff838e6cdf37cd078d1abdc1d147561b2453ffb6b5c749dbc7b019f1691f59d0b0b52356a61efcbb10533ce44319d64
6
+ metadata.gz: b148eeaf72cd34a292d1da244e33a4c4f7eb1549cca374e9c7da7aadc6a09de262c992de578725ebb5ecaad4c1fa625365dbfda519119ccec82c39da224d71f7
7
+ data.tar.gz: 9fb7676fbd6e7ffbf1bce920a626d70a260c24e83d59569447595c4e28157e879969b6700423d9199564e915d7929ca5c93a507e2703d79c192f0cc21d6f91cf
@@ -13,6 +13,22 @@ module Pubid::Core::Renderer
13
13
  @params = params
14
14
  end
15
15
 
16
+ # Prerender parameters and store in @prerendered_params
17
+ # @param opts [Hash] options for render method, eg. { with_language_code: :single, with_date: true }
18
+ # @return [Renderer::Base] self
19
+ def prerender(**opts)
20
+ @prerendered_params = prerender_params(@params, opts)
21
+ @prerendered_params.default = ""
22
+ self
23
+ end
24
+
25
+ def render_base_identifier(**args)
26
+ prerender(**args)
27
+
28
+ render_identifier(@prerendered_params)
29
+ end
30
+
31
+
16
32
  def prerender_params(params, opts)
17
33
  params.map do |key, value|
18
34
  next unless value
@@ -24,16 +40,44 @@ module Pubid::Core::Renderer
24
40
  end.compact.to_h
25
41
  end
26
42
 
43
+ # Renders amendment and corrigendum when applied through identifier type
44
+ def render_supplement(supplement_params, **args)
45
+ if supplement_params[:base].type == :amd
46
+ # render inner amendment (cor -> amd -> base)
47
+ render_supplement(supplement_params[:base].get_params, **args)
48
+ else
49
+ self.class.new(supplement_params[:base].get_params).render_base_identifier(
50
+ # always render year for identifiers with supplement
51
+ **args.merge({ with_date: true }),
52
+ )
53
+ end +
54
+ case supplement_params[:type].type
55
+ when :amd
56
+ render_amendments(
57
+ [Pubid::Iso::Amendment.new(**supplement_params.slice(:number, :year, :stage, :edition, :iteration))],
58
+ args,
59
+ nil,
60
+ )
61
+ when :cor
62
+ render_corrigendums(
63
+ [Pubid::Iso::Corrigendum.new(**supplement_params.slice(:number, :year, :stage, :edition, :iteration))],
64
+ args,
65
+ nil,
66
+ )
67
+ # copy parameters from Identifier only supported by Corrigendum
68
+ end +
69
+ (supplement_params[:base].language ? render_language(supplement_params[:base].language, args, nil) : "")
70
+ end
71
+
27
72
  # Render identifier
28
73
  # @param with_date [Boolean] include year in output
29
74
  # @param with_language_code [:iso,:single] render document language as 2-letter ISO 639-1 language code or single code
30
- def render(with_date: true, with_language_code: :iso)
31
- params = prerender_params(@params,
32
- { with_date: with_date, with_language_code: with_language_code })
33
- # render empty string when the key is not exist
34
- params.default = ""
35
-
36
- render_identifier(params)
75
+ def render(with_date: true, with_language_code: :iso, **args)
76
+ if %i(amd cor).include? @params[:type]&.type
77
+ render_supplement(@params, **args.merge({ with_date: with_date, with_language_code: with_language_code}))
78
+ else
79
+ render_base_identifier(**args.merge({ with_date: with_date, with_language_code: with_language_code})) + @prerendered_params[:language].to_s
80
+ end
37
81
  end
38
82
 
39
83
  def render_base(params, prefix = "")
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.2.1".freeze
3
+ VERSION = "1.2.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.2.1
4
+ version: 1.2.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: 2022-10-12 00:00:00.000000000 Z
11
+ date: 2022-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake