pubid-core 1.2.0 → 1.2.1
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 +25 -21
- 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: 7cc372a0160fd8c1a670be2957f3b3e0a98766dd89ed6f8782b1f52085bcbb8f
|
4
|
+
data.tar.gz: 9a0d58a218b982531fe206bd7505203428ec6f9d7dcbaa649f80267b09e44030
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04e0297f6ce7bea0cabc3e41c7718e1eee523f93e039fa42f4b08c7a34d4fcb7b3c979fbcdb2c0c7bd980b4523d2c6985198cf61f03bb1fad64765a51ad2ccd8
|
7
|
+
data.tar.gz: f0c98e3158ff918fe1f0df2e5ae3c2e7cff838e6cdf37cd078d1abdc1d147561b2453ffb6b5c749dbc7b019f1691f59d0b0b52356a61efcbb10533ce44319d64
|
@@ -74,33 +74,37 @@ module Pubid::Core
|
|
74
74
|
def parse(code_or_params)
|
75
75
|
params = code_or_params.is_a?(String) ?
|
76
76
|
get_parser_class.new.parse(update_old_code(code_or_params)) : code_or_params
|
77
|
-
transform(params)
|
77
|
+
transform(params.is_a?(Array) ? array_to_hash(params) : params)
|
78
78
|
rescue Parslet::ParseFailed => failure
|
79
79
|
raise Errors::ParseError, "#{failure.message}\ncause: #{failure.parse_failure_cause.ascii_tree}"
|
80
80
|
end
|
81
81
|
|
82
|
+
# Converts array of hashes into single hash
|
83
|
+
# array like [{ publisher: "ISO" }, { number: 1 }] to hash { publisher: "ISO", number: 1 }
|
84
|
+
# @param params [Array<Hash>] input array of hashes, eg. [{ a: 1 }, { b: 2 }]
|
85
|
+
def array_to_hash(params)
|
86
|
+
params.inject({}) do |r, i|
|
87
|
+
result = r
|
88
|
+
i.each do |k, v|
|
89
|
+
result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
|
90
|
+
end
|
91
|
+
result
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
82
95
|
# Transform parameters hash or array or hashes to identifier
|
83
96
|
def transform(params)
|
84
|
-
#
|
85
|
-
#
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end
|
96
|
-
)
|
97
|
-
)
|
98
|
-
else
|
99
|
-
new(**params.map do |k, v|
|
100
|
-
get_transformer_class.new.apply(k => v).to_a.first
|
101
|
-
end.to_h)
|
102
|
-
end
|
103
|
-
# merge values repeating keys into array (for copublishers)
|
97
|
+
# run transform through each element,
|
98
|
+
# like running transformer.apply(number: 1) and transformer.apply(year: 1999)
|
99
|
+
# instead of running transformer on whole hash, like running transformer.apply({ number: 1, year: 1999 })
|
100
|
+
# where rule for number or year only will be not applied
|
101
|
+
# transformation only applied to rules matching the whole hash
|
102
|
+
|
103
|
+
identifier_params = params.map do |k, v|
|
104
|
+
get_transformer_class.new.apply(k => v).to_a.first
|
105
|
+
end.to_h
|
106
|
+
|
107
|
+
new(**identifier_params)
|
104
108
|
end
|
105
109
|
|
106
110
|
def get_amendment_class
|
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.2.
|
4
|
+
version: 1.2.1
|
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-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|