pubid-core 0.2.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pubid/core/identifier.rb +56 -27
- data/lib/pubid/core/parser.rb +6 -0
- data/lib/pubid/core/renderer/base.rb +5 -25
- data/lib/pubid/core/renderer/urn.rb +6 -21
- data/lib/pubid/core/supplement.rb +3 -0
- 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: e4f9bff0cb4e318de8dab3eb5c8155cb5fe3c560cc24d0616cb38f71a9a83d1c
|
4
|
+
data.tar.gz: 306cc2e013df2f7d236ef62b45fdaccc0038d8e220827898e817a8b2d47dc19e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8845cff2602c572ccf3a8bc081aa8f326dcaa0384c06353dd1ca842ae94405acc821b12b3fdb9c7eb14c70da61c9abcee2297d01a94a56125e8298411cf9f72
|
7
|
+
data.tar.gz: 78a9452536f524523c470d09973490bb6d2f7c634c531e05dc4150a92ef21bffedb3b0a3bb65c1a32afae17c4c3eee63dd5c0fc055549d80bf7cf9bbd491edeb
|
@@ -4,7 +4,23 @@ module Pubid::Core
|
|
4
4
|
:type, :year, :edition, :language, :amendments,
|
5
5
|
:corrigendums
|
6
6
|
|
7
|
-
|
7
|
+
# Creates new identifier from options provided:
|
8
|
+
# @param publisher [String] document's publisher, eg. "ISO"
|
9
|
+
# @param copublisher [String,Array<String>] document's copublisher, eg. "IEC"
|
10
|
+
# @param number [Integer] document's number, eg. "1234"
|
11
|
+
# @param part [String] document's part and subparts, eg. "1", "1-1A", "2-3D"
|
12
|
+
# @param type [String] document's type, eg. "TR", "TS"
|
13
|
+
# @param year [Integer] document's year, eg. "2020"
|
14
|
+
# @param edition [Integer] document's edition, eg. "1"
|
15
|
+
# @param language [String] document's translation language
|
16
|
+
# (available languages: "ru", "fr", "en", "ar")
|
17
|
+
# @param amendments [Array<Amendment>] document's amendments
|
18
|
+
# @param corrigendums [Array<Corrigendum>] document's corrigendums
|
19
|
+
# @see Amendment
|
20
|
+
# @see Corrigendum
|
21
|
+
def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,
|
22
|
+
year: nil, edition: nil, language: nil, amendments: nil,
|
23
|
+
corrigendums: nil)
|
8
24
|
if amendments
|
9
25
|
@amendments = if amendments.is_a?(Array)
|
10
26
|
amendments.map do |amendment|
|
@@ -24,9 +40,17 @@ module Pubid::Core
|
|
24
40
|
end
|
25
41
|
end
|
26
42
|
|
27
|
-
|
43
|
+
@publisher = publisher.to_s
|
44
|
+
@number = number
|
45
|
+
@copublisher = copublisher if copublisher
|
46
|
+
@part = part.to_s if part
|
47
|
+
@type = type.to_s if type
|
48
|
+
@year = year.to_i if year
|
49
|
+
@edition = edition.to_i if edition
|
50
|
+
@language = language.to_s if language
|
28
51
|
end
|
29
52
|
|
53
|
+
# @return [String] Rendered URN identifier
|
30
54
|
def urn
|
31
55
|
Renderer::Urn.new(get_params).render
|
32
56
|
end
|
@@ -35,36 +59,16 @@ module Pubid::Core
|
|
35
59
|
instance_variables.map { |var| [var.to_s.gsub("@", "").to_sym, instance_variable_get(var)] }.to_h
|
36
60
|
end
|
37
61
|
|
62
|
+
# Render identifier using default renderer
|
38
63
|
def to_s
|
39
64
|
self.class.get_renderer_class.new(get_params).render
|
40
65
|
end
|
41
66
|
|
42
67
|
class << self
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
def get_corrigendum_class
|
48
|
-
Corrigendum
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_renderer_class
|
52
|
-
Renderer::Base
|
53
|
-
end
|
54
|
-
|
55
|
-
def get_transformer_class
|
56
|
-
Transformer
|
57
|
-
end
|
58
|
-
|
59
|
-
def update_old_code(code)
|
60
|
-
return code unless defined?(UPDATE_CODES)
|
61
|
-
|
62
|
-
UPDATE_CODES.each do |from, to|
|
63
|
-
code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to)
|
64
|
-
end
|
65
|
-
code
|
66
|
-
end
|
67
|
-
|
68
|
+
# Parses given identifier
|
69
|
+
# @param code_or_params [String, Hash] code or hash from parser
|
70
|
+
# eg. "ISO 1234", { }
|
71
|
+
# @return [Pubid::Core::Identifier] identifier
|
68
72
|
def parse(code_or_params)
|
69
73
|
params = code_or_params.is_a?(String) ?
|
70
74
|
get_parser_class.new.parse(update_old_code(code_or_params)) : code_or_params
|
@@ -92,6 +96,31 @@ module Pubid::Core
|
|
92
96
|
rescue Parslet::ParseFailed => failure
|
93
97
|
raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
94
98
|
end
|
99
|
+
|
100
|
+
def get_amendment_class
|
101
|
+
Amendment
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_corrigendum_class
|
105
|
+
Corrigendum
|
106
|
+
end
|
107
|
+
|
108
|
+
def get_renderer_class
|
109
|
+
Renderer::Base
|
110
|
+
end
|
111
|
+
|
112
|
+
def get_transformer_class
|
113
|
+
Transformer
|
114
|
+
end
|
115
|
+
|
116
|
+
def update_old_code(code)
|
117
|
+
return code unless defined?(UPDATE_CODES)
|
118
|
+
|
119
|
+
UPDATE_CODES.each do |from, to|
|
120
|
+
code = code.gsub(from.match?(/^\/.*\/$/) ? Regexp.new(from[1..-2]) : /^#{Regexp.escape(from)}$/, to)
|
121
|
+
end
|
122
|
+
code
|
123
|
+
end
|
95
124
|
end
|
96
125
|
end
|
97
126
|
end
|
data/lib/pubid/core/parser.rb
CHANGED
@@ -34,9 +34,12 @@ module Pubid::Core::Renderer
|
|
34
34
|
render_identifier(params)
|
35
35
|
end
|
36
36
|
|
37
|
+
def render_base(params, prefix = "")
|
38
|
+
"%{publisher}%{copublisher}#{prefix} %{number}" % params
|
39
|
+
end
|
40
|
+
|
37
41
|
def render_identifier(params)
|
38
|
-
|
39
|
-
"%{year}%{edition}%{amendments}%{corrigendums}%{language}" % params
|
42
|
+
render_base(params)
|
40
43
|
end
|
41
44
|
|
42
45
|
def render_copublisher(copublisher, _opts, _params)
|
@@ -58,21 +61,6 @@ module Pubid::Core::Renderer
|
|
58
61
|
corrigendums.sort.map(&:render_pubid).join("+")
|
59
62
|
end
|
60
63
|
|
61
|
-
def render_type(type, opts, params)
|
62
|
-
if params[:copublisher]
|
63
|
-
" #{type}"
|
64
|
-
else
|
65
|
-
"/#{type}"
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def render_stage(stage, opts, params)
|
70
|
-
if params[:copublisher]
|
71
|
-
" #{stage}"
|
72
|
-
else
|
73
|
-
"/#{stage}"
|
74
|
-
end
|
75
|
-
end
|
76
64
|
|
77
65
|
def render_part(part, opts, _params)
|
78
66
|
"-#{part}"
|
@@ -89,13 +77,5 @@ module Pubid::Core::Renderer
|
|
89
77
|
"(#{language})"
|
90
78
|
end
|
91
79
|
end
|
92
|
-
|
93
|
-
def render_edition(edition, _opts, _params)
|
94
|
-
" ED#{edition}"
|
95
|
-
end
|
96
|
-
|
97
|
-
def render_iteration(iteration, _opts, _params)
|
98
|
-
".#{iteration}"
|
99
|
-
end
|
100
80
|
end
|
101
81
|
end
|
@@ -1,18 +1,12 @@
|
|
1
1
|
module Pubid::Core::Renderer
|
2
2
|
class Urn < Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
CD: 30,
|
8
|
-
DIS: 40,
|
9
|
-
FDIS: 50,
|
10
|
-
PRF: 50,
|
11
|
-
IS: 60 }.freeze
|
3
|
+
|
4
|
+
def render_base(params)
|
5
|
+
"urn:iso:std:%{publisher}%{copublisher}%{type}:%{number}%{part}" % params
|
6
|
+
end
|
12
7
|
|
13
8
|
def render_identifier(params)
|
14
|
-
|
15
|
-
"%{urn_stage}%{corrigendum_stage}%{iteration}%{edition}%{amendments}%{corrigendums}%{language}" % params
|
9
|
+
render_base(params)
|
16
10
|
end
|
17
11
|
|
18
12
|
def render_publisher(publisher, _opts, _params)
|
@@ -20,7 +14,7 @@ module Pubid::Core::Renderer
|
|
20
14
|
end
|
21
15
|
|
22
16
|
def render_copublisher(copublisher, _opts, _params)
|
23
|
-
return "-#{copublisher.downcase}" unless copublisher.is_a?(Array)
|
17
|
+
return "-#{copublisher.to_s.downcase}" unless copublisher.is_a?(Array)
|
24
18
|
|
25
19
|
copublisher.map(&:to_s).sort.map do |copublisher|
|
26
20
|
"-#{copublisher.downcase}"
|
@@ -47,15 +41,6 @@ module Pubid::Core::Renderer
|
|
47
41
|
":#{language}"
|
48
42
|
end
|
49
43
|
|
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
44
|
|
60
45
|
def render_corrigendum_stage(stage, opts, params)
|
61
46
|
render_stage(stage, opts, params)
|
@@ -3,6 +3,9 @@ module Pubid::Core
|
|
3
3
|
include Comparable
|
4
4
|
attr_accessor :version, :number
|
5
5
|
|
6
|
+
# Creates new supplement with provided version and optional number
|
7
|
+
# @param version [Integer]
|
8
|
+
# @param number [Integer]
|
6
9
|
def initialize(version:, number: nil)
|
7
10
|
@version, @number = version&.to_i, number&.to_i
|
8
11
|
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: 0.
|
4
|
+
version: 1.0.0
|
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-
|
11
|
+
date: 2022-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|