pubid-core 0.1.6 → 0.1.7

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: c46f13465619dbdc86817f58116f5e1777435535681a2960f54bda577337f196
4
- data.tar.gz: 11abb71f44d211f354c12d214606b0783f2bcf8d7a3036f114e08746b955a792
3
+ metadata.gz: 9895b8d56bf37310135d11148c71ea31514d203a4157b6d6bcb9a4d4df81be58
4
+ data.tar.gz: 92d7bc8de5d97c2bda090ba2e2056819d29a31fff22f67495a7a4947ffaecc98
5
5
  SHA512:
6
- metadata.gz: 298cff787725f61393f2dffa20289c6d773b18bef9bf674fe84dd21158dc641c646375d1de8beea5ea622dd50d1802fa636b2933dd4c29384dd79932791f476c
7
- data.tar.gz: be51cdf5eea98cf3161b0957890cae3b0cf6698af1dd5e8dc2046bfc591466df17a81a8a0ddb69f741f57356d9b9fbdc89faa349a86f08f1f6899a3d65aa1c1f
6
+ metadata.gz: 57ad7508563a1bd967e6d60ff78faa2ea7a26e954a001545f0220ccfbbfe6efe935d7d0f8e9a0dec06ef27fb93e5620c6a1e3ca50a43a71b019e63d5bfab4a6b
7
+ data.tar.gz: 0eda4ada9150f10b557a57610f802463773e8573c6f059180cec900ca769e205aa08e51e17d7152b11be88d57fd261b9b1b19d22f5744b51711b5ad1363569d8
@@ -27,12 +27,16 @@ module Pubid::Core
27
27
  opts.each { |key, value| send("#{key}=", value.is_a?(Array) && value || value.to_s) }
28
28
  end
29
29
 
30
+ def urn
31
+ Renderer::Urn.new(get_params).render
32
+ end
33
+
30
34
  def get_params
31
35
  instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
32
36
  end
33
37
 
34
38
  def to_s
35
- self.class.get_renderer.new(get_params).render
39
+ self.class.get_renderer_class.new(get_params).render
36
40
  end
37
41
 
38
42
  class << self
@@ -44,8 +48,12 @@ module Pubid::Core
44
48
  Corrigendum
45
49
  end
46
50
 
47
- def get_renderer
48
- Renderer
51
+ def get_renderer_class
52
+ Renderer::Base
53
+ end
54
+
55
+ def get_transformer_class
56
+ Transformer
49
57
  end
50
58
 
51
59
  def parse(code_or_params)
@@ -57,7 +65,7 @@ module Pubid::Core
57
65
  **(
58
66
  params.inject({}) do |r, i|
59
67
  result = r
60
- i.map {|k, v| Transformer.new.apply(k => v).to_a.first }.each do |k, v|
68
+ i.map {|k, v| get_transformer_class.new.apply(k => v).to_a.first }.each do |k, v|
61
69
  result = result.merge(k => r.key?(k) ? [v, r[k]] : v)
62
70
  end
63
71
  result
@@ -66,7 +74,7 @@ module Pubid::Core
66
74
  )
67
75
  else
68
76
  new(**params.map do |k, v|
69
- Transformer.new.apply(k => v).to_a.first
77
+ get_transformer_class.new.apply(k => v).to_a.first
70
78
  end.to_h)
71
79
  end
72
80
  # merge values repeating keys into array (for copublishers)
@@ -1,5 +1,5 @@
1
- module Pubid::Core
2
- class Renderer
1
+ module Pubid::Core::Renderer
2
+ class Base
3
3
  attr_accessor :params
4
4
 
5
5
  LANGUAGES = {
@@ -0,0 +1,72 @@
1
+ module Pubid::Core::Renderer
2
+ class Urn < Base
3
+ STAGES = { PWI: 0,
4
+ NP: 10,
5
+ AWI: 20,
6
+ WD: 20.20,
7
+ CD: 30,
8
+ DIS: 40,
9
+ FDIS: 50,
10
+ PRF: 50,
11
+ IS: 60 }.freeze
12
+
13
+ def render_identifier(params)
14
+ "urn:iso:std:%{publisher}%{copublisher}%{type}:%{number}%{part}%{stage}"\
15
+ "%{urn_stage}%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}%{language}" % params
16
+ end
17
+
18
+ def render_publisher(publisher, _opts, _params)
19
+ publisher.downcase
20
+ end
21
+
22
+ def render_copublisher(copublisher, _opts, _params)
23
+ return "-#{copublisher.downcase}" unless copublisher.is_a?(Array)
24
+
25
+ copublisher.map(&:to_s).sort.map do |copublisher|
26
+ "-#{copublisher.downcase}"
27
+ end.join
28
+ end
29
+
30
+ def render_edition(edition, _opts, _params)
31
+ ":ed-#{edition}"
32
+ end
33
+
34
+ def render_type(type, _, _)
35
+ ":#{type.downcase}"
36
+ end
37
+
38
+ def render_amendments(amendments, _opts, _params)
39
+ amendments&.map(&:render_urn)&.join || ""
40
+ end
41
+
42
+ def render_corrigendums(corrigendums, _opts, _params)
43
+ corrigendums&.map(&:render_urn)&.join || ""
44
+ end
45
+
46
+ def render_language(language, _opts, _params)
47
+ ":#{language}"
48
+ end
49
+
50
+ def render_stage(stage, _opts, _params)
51
+ return ":stage-#{sprintf('%05.2f', stage)}" if stage.is_a?(Float)
52
+
53
+ ":stage-#{sprintf('%05.2f', STAGES[stage.to_sym])}"
54
+ end
55
+
56
+ def render_urn_stage(stage, opts, params)
57
+ render_stage(stage, opts, params)
58
+ end
59
+
60
+ def render_corrigendum_stage(stage, opts, params)
61
+ render_stage(stage, opts, params)
62
+ end
63
+
64
+ def render_iteration(iteration, _opts, params)
65
+ ".v#{iteration}" if params[:stage]
66
+ end
67
+
68
+ def render_part(part, _opts, _params)
69
+ ":-#{part}"
70
+ end
71
+ end
72
+ end
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "0.1.6".freeze
3
+ VERSION = "0.1.7".freeze
4
4
  end
5
5
  end
data/lib/pubid/core.rb CHANGED
@@ -6,5 +6,6 @@ require_relative "core/supplement"
6
6
  require_relative "core/amendment"
7
7
  require_relative "core/corrigendum"
8
8
  require_relative "core/transformer"
9
- require_relative "core/renderer"
9
+ require_relative "core/renderer/base"
10
+ require_relative "core/renderer/urn"
10
11
  require_relative "core/identifier"
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.6
4
+ version: 0.1.7
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-09 00:00:00.000000000 Z
11
+ date: 2022-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,7 +70,8 @@ files:
70
70
  - lib/pubid/core/errors.rb
71
71
  - lib/pubid/core/identifier.rb
72
72
  - lib/pubid/core/parser.rb
73
- - lib/pubid/core/renderer.rb
73
+ - lib/pubid/core/renderer/base.rb
74
+ - lib/pubid/core/renderer/urn.rb
74
75
  - lib/pubid/core/supplement.rb
75
76
  - lib/pubid/core/transformer.rb
76
77
  - lib/pubid/core/version.rb