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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e9bf3dd3d9bc2b650200a864109ae197ab92914d1badcbf211d414b9b72d535
4
- data.tar.gz: 65ceef880cc4e59dfa4cd059cd2b57090cfee8400cf26717f6bd480d3a29b7db
3
+ metadata.gz: 7cc372a0160fd8c1a670be2957f3b3e0a98766dd89ed6f8782b1f52085bcbb8f
4
+ data.tar.gz: 9a0d58a218b982531fe206bd7505203428ec6f9d7dcbaa649f80267b09e44030
5
5
  SHA512:
6
- metadata.gz: 57670502ba1de60b88d0befb0933f990c37b3dd23544a5bd4889d2da0aea6086ea1d87032e9c547c2c5a9430037c3325d77149ebe36edf3a66c349ec3d734274
7
- data.tar.gz: 1c9917b90d532faf17a601fea62ea18fe204098052b349b189067287877f29ba66dd2e244389b4b906d8772d33eced7aa2f204f61082a81aede616168e11b038
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
- # Parslet returns an array when match any copublisher
85
- # otherwise it's hash
86
- if params.is_a?(Array)
87
- new(
88
- **(
89
- params.inject({}) do |r, i|
90
- result = r
91
- i.map {|k, v| get_transformer_class.new.apply(k => v).to_a.first }.each do |k, v|
92
- result = result.merge(k => r.key?(k) ? [v, r[k]].flatten : v)
93
- end
94
- result
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
@@ -1,5 +1,5 @@
1
1
  module Pubid
2
2
  module Core
3
- VERSION = "1.2.0".freeze
3
+ VERSION = "1.2.1".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: 1.2.0
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-09-19 00:00:00.000000000 Z
11
+ date: 2022-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake