pubid-core 0.1.5 → 0.1.6

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: 572e76f914359171e1ebd2e4894cd02fcfcc519311f687a5f616b701bf177a44
4
- data.tar.gz: 8e0328ff09f797795747a1df3de3484a37dc717c2e657e782c5d4310784044d0
3
+ metadata.gz: c46f13465619dbdc86817f58116f5e1777435535681a2960f54bda577337f196
4
+ data.tar.gz: 11abb71f44d211f354c12d214606b0783f2bcf8d7a3036f114e08746b955a792
5
5
  SHA512:
6
- metadata.gz: 8a62af066a0517b83ba5440f26437bdea0251f485de3d3062c38921fbe9271490aec6c90aa2bacdda7ed5772f44113ca248dbd68035b1223c83a0a075476f4ae
7
- data.tar.gz: ab780a3f9b8e17abbb3554615ecb7f2c642573c6399fed11c6d93e76aa6459cc9980f433b9d4f904da306a3d6afbefede51b4c3021fa9ce70905be424c17f368
6
+ metadata.gz: 298cff787725f61393f2dffa20289c6d773b18bef9bf674fe84dd21158dc641c646375d1de8beea5ea622dd50d1802fa636b2933dd4c29384dd79932791f476c
7
+ data.tar.gz: be51cdf5eea98cf3161b0957890cae3b0cf6698af1dd5e8dc2046bfc591466df17a81a8a0ddb69f741f57356d9b9fbdc89faa349a86f08f1f6899a3d65aa1c1f
@@ -2,14 +2,99 @@ module Pubid::Core
2
2
  class Renderer
3
3
  attr_accessor :params
4
4
 
5
+ LANGUAGES = {
6
+ "ru" => "R",
7
+ "fr" => "F",
8
+ "en" => "E",
9
+ "ar" => "A",
10
+ }.freeze
11
+
5
12
  def initialize(params)
6
13
  @params = params
7
- @params.default = ""
8
14
  end
15
+
16
+ def prerender_params(params, opts)
17
+ params.map do |key, value|
18
+ if respond_to?("render_#{key}")
19
+ [key, send("render_#{key}", value, opts, params)]
20
+ else
21
+ [key, value]
22
+ end
23
+ end.to_h
24
+ end
25
+
9
26
  # render from hash keys
10
- def render
11
- "%{publisher}%{type}%{stage} %{number}%{part}%{iteration}"\
12
- "%{edition}%{supplements}%{language}" % @params
27
+ def render(with_date: true, with_language_code: :iso)
28
+ params = prerender_params(@params,
29
+ { with_date: with_date, with_language_code: with_language_code })
30
+ # render empty string when the key is not exist
31
+ params.default = ""
32
+
33
+ render_identifier(params)
34
+ end
35
+
36
+ def render_identifier(params)
37
+ "%{publisher}%{copublisher}%{type}%{stage} %{number}%{part}%{iteration}"\
38
+ "%{year}%{edition}%{amendments}%{corrigendums}%{language}" % params
39
+ end
40
+
41
+ def render_copublisher(copublisher, _opts, _params)
42
+ # (!@copublisher.is_a?(Array) && [@copublisher]) || @copublisher
43
+ if copublisher.is_a?(Array)
44
+ copublisher.map(&:to_s).sort.map do |copublisher|
45
+ "/#{copublisher.gsub('-', '/')}"
46
+ end.join
47
+ else
48
+ "/#{copublisher}"
49
+ end
50
+ end
51
+
52
+ def render_amendments(amendments, _opts, _params)
53
+ amendments.map(&:render_pubid).join("+")
54
+ end
55
+
56
+ def render_corrigendums(corrigendums, _opts, _params)
57
+ corrigendums.map(&:render_pubid).join("+")
58
+ end
59
+
60
+ def render_type(type, opts, params)
61
+ if params[:copublisher]
62
+ " #{type}"
63
+ else
64
+ "/#{type}"
65
+ end
66
+ end
67
+
68
+ def render_stage(stage, opts, params)
69
+ if params[:copublisher]
70
+ " #{stage}"
71
+ else
72
+ "/#{stage}"
73
+ end
74
+ end
75
+
76
+ def render_part(part, opts, _params)
77
+ "-#{part}"
78
+ end
79
+
80
+ def render_year(year, opts, _params)
81
+ opts[:with_date] && ":#{year}" || ""
82
+ end
83
+
84
+ def render_language(language, opts, _params)
85
+ if opts[:with_language_code] == :single
86
+ "(#{LANGUAGES[language]})"
87
+ else
88
+ "(#{language})"
89
+ end
90
+ end
91
+
92
+ def render_edition(edition, _opts, _params)
93
+ " ED#{edition}"
94
+ end
95
+
96
+ def render_iteration(iteration, _opts, _params)
97
+ ".#{iteration}"
13
98
  end
14
99
  end
15
100
  end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "0.1.5".freeze
3
+ VERSION = "0.1.6".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: 0.1.5
4
+ version: 0.1.6
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-06-07 00:00:00.000000000 Z
11
+ date: 2022-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake