pubid-core 1.0.1 → 1.1.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 +10 -22
- data/lib/pubid/core/transformer.rb +42 -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: f2ec998c6f62ddf6387a254425f4989052de90cd44f60577c384f1371314e874
|
4
|
+
data.tar.gz: f9aa149ce454d7d8c674fe12c6c7dc9246ff06c6197c63686abaacd6babe15a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 502cca40f231aa67f96041c61cb82868a67a1db3b521d8a2e1f7431d3013dfe48d77e698139407c1640f23931d76766c92eeee36033f6f0de1424bd57f669ccc
|
7
|
+
data.tar.gz: 63ba052753612c1c239a5fc6bd71a3952f35dd6dd82715899fa02855479bb55039c71e6b2b7d5d13ab2d02abea638089ab96bc4eacf4c64a6bdfa9c5a27797ca
|
@@ -21,25 +21,9 @@ module Pubid::Core
|
|
21
21
|
def initialize(publisher:, number:, copublisher: nil, part: nil, type: nil,
|
22
22
|
year: nil, edition: nil, language: nil, amendments: nil,
|
23
23
|
corrigendums: nil)
|
24
|
-
if amendments
|
25
|
-
@amendments = if amendments.is_a?(Array)
|
26
|
-
amendments.map do |amendment|
|
27
|
-
self.class.get_amendment_class.new(**amendment)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
[self.class.get_amendment_class.new(**amendments)]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
if corrigendums
|
34
|
-
@corrigendums = if corrigendums.is_a?(Array)
|
35
|
-
corrigendums.map do |corrigendum|
|
36
|
-
self.class.get_corrigendum_class.new(**corrigendum)
|
37
|
-
end
|
38
|
-
else
|
39
|
-
[self.class.get_corrigendum_class.new(**corrigendums)]
|
40
|
-
end
|
41
|
-
end
|
42
24
|
|
25
|
+
@amendments = amendments
|
26
|
+
@corrigendums = corrigendums
|
43
27
|
@publisher = publisher.to_s
|
44
28
|
@number = number
|
45
29
|
@copublisher = copublisher if copublisher
|
@@ -72,6 +56,13 @@ module Pubid::Core
|
|
72
56
|
def parse(code_or_params)
|
73
57
|
params = code_or_params.is_a?(String) ?
|
74
58
|
get_parser_class.new.parse(update_old_code(code_or_params)) : code_or_params
|
59
|
+
transform(params)
|
60
|
+
rescue Parslet::ParseFailed => failure
|
61
|
+
raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# Transform parameters hash or array or hashes to identifier
|
65
|
+
def transform(params)
|
75
66
|
# Parslet returns an array when match any copublisher
|
76
67
|
# otherwise it's hash
|
77
68
|
if params.is_a?(Array)
|
@@ -80,7 +71,7 @@ module Pubid::Core
|
|
80
71
|
params.inject({}) do |r, i|
|
81
72
|
result = r
|
82
73
|
i.map {|k, v| get_transformer_class.new.apply(k => v).to_a.first }.each do |k, v|
|
83
|
-
result = result.merge(k => r.key?(k) ? [v, r[k]] : v)
|
74
|
+
result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
|
84
75
|
end
|
85
76
|
result
|
86
77
|
end
|
@@ -92,9 +83,6 @@ module Pubid::Core
|
|
92
83
|
end.to_h)
|
93
84
|
end
|
94
85
|
# merge values repeating keys into array (for copublishers)
|
95
|
-
|
96
|
-
rescue Parslet::ParseFailed => failure
|
97
|
-
raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
98
86
|
end
|
99
87
|
|
100
88
|
def get_amendment_class
|
@@ -1,4 +1,46 @@
|
|
1
1
|
module Pubid::Core
|
2
2
|
class Transformer < Parslet::Transform
|
3
|
+
class << self
|
4
|
+
def get_amendment_class
|
5
|
+
Amendment
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_corrigendum_class
|
9
|
+
Corrigendum
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
super
|
15
|
+
|
16
|
+
rule(amendments: subtree(:amendments)) do |context|
|
17
|
+
if context[:amendments].is_a?(Array)
|
18
|
+
context[:amendments] = context[:amendments].map do |amendment|
|
19
|
+
self.class.get_amendment_class.new(version: amendment[:version], number: amendment[:number])
|
20
|
+
end
|
21
|
+
else
|
22
|
+
context[:amendments] =
|
23
|
+
[self.class.get_amendment_class.new(
|
24
|
+
version: context[:amendments][:version],
|
25
|
+
number: context[:amendments][:number])]
|
26
|
+
|
27
|
+
end
|
28
|
+
context
|
29
|
+
end
|
30
|
+
|
31
|
+
rule(corrigendums: subtree(:corrigendums)) do |context|
|
32
|
+
if context[:corrigendums].is_a?(Array)
|
33
|
+
context[:corrigendums] = context[:corrigendums].map do |corrigendum|
|
34
|
+
self.class.get_corrigendum_class.new(version: corrigendum[:version], number: corrigendum[:number])
|
35
|
+
end
|
36
|
+
else
|
37
|
+
context[:corrigendums] =
|
38
|
+
[self.class.get_corrigendum_class.new(
|
39
|
+
version: context[:corrigendums][:version],
|
40
|
+
number: context[:corrigendums][:number])]
|
41
|
+
end
|
42
|
+
context
|
43
|
+
end
|
44
|
+
end
|
3
45
|
end
|
4
46
|
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: 1.0
|
4
|
+
version: 1.1.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-08-
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|