relaton-iso 1.12.2 → 1.13.0

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: 1f7c1d269d268e8bb7f9bc7b19b6e5466c9fb88f8a9db41f3944207535ca2edd
4
- data.tar.gz: 4a6545be437af6c6326fed4e231c387a0a5cc7c04168fa1098c9fffc78701b29
3
+ metadata.gz: ae80444c7eea0c2fc3650351cbec8bb812ddfb10ec57d8060e8fb15d05b47cee
4
+ data.tar.gz: c9d2ac614b3feb6841bcad5c631dac08d4d723befdb2a0361df58899162dfd09
5
5
  SHA512:
6
- metadata.gz: 3be88b28acc84c9877db94ef46e38488ea63b15ca2c19cd694c69d17f0e1b5c0b003a95929673d2e8a70cb69e91faef575506dab409d0c4b5e61f4dd046eb858
7
- data.tar.gz: 209c65c8d600a34566999600cc0fbb0b06564603821c00045a09e0e00ecd2f6abf79c59774142e4dc1474dcb08b2604aeb5f1874a25b9f29e0d0dd9b420fbd4b
6
+ metadata.gz: 88efa8cc67bf0b555756a09bf13593e1a5685c066589cfac81a12797edd1bfd8aac58188ad07f8128381c426f46755fc3ddeee037b19e584bf5a09915dad6d48
7
+ data.tar.gz: a84a89836305ad177253ae2b18d7c78d328a48ea66b6861f0fece81b31468fd20b6d3048ead7642862ad57f2145a638c8eae8930e54266ae1eeee7fc43319ec1
@@ -15,11 +15,11 @@ module RelatonIso
15
15
  end
16
16
 
17
17
  # @param lang [String, NilClass]
18
- # @return [RelatonIsoBib::IsoBibliographicItem]
18
+ # @return [RelatonIsoBib::IsoBibliographicItem, nil]
19
19
  def to_all_parts(lang = nil) # rubocop:disable Metrics/CyclomaticComplexity
20
20
  # parts = @array.reject { |h| h.hit["docPart"]&.empty? }
21
21
  hit = @array.min_by { |h| h.pubid.part }
22
- return @array.first.fetch lang unless hit
22
+ return @array.first&.fetch lang unless hit
23
23
 
24
24
  bibitem = hit.fetch(lang)
25
25
  all_parts_item = bibitem.to_all_parts
@@ -38,19 +38,19 @@ module RelatonIso
38
38
  query_pubid = Pubid::Iso::Identifier.parse(code)
39
39
  query_pubid.year = year if year
40
40
 
41
- hits = isobib_search_filter(query_pubid, opts)
41
+ resp = isobib_search_filter(query_pubid, opts)
42
42
 
43
43
  # return only first one if not all_parts
44
- ret = if !opts[:all_parts] || hits.size == 1
45
- hits.any? && hits.first.fetch(opts[:lang])
44
+ ret = if !opts[:all_parts] || resp[:hits].size == 1
45
+ resp[:hits].any? && resp[:hits].first.fetch(opts[:lang])
46
46
  else
47
- hits.to_all_parts(opts[:lang])
47
+ resp[:hits].to_all_parts(opts[:lang])
48
48
  end
49
49
 
50
50
  if ret
51
51
  warn "[relaton-iso] (\"#{query_pubid}\") found #{ret.docidentifier.first.id}"
52
52
  else
53
- return fetch_ref_err(query_pubid, query_pubid.year)
53
+ return fetch_ref_err(query_pubid)
54
54
  end
55
55
 
56
56
  if (query_pubid.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts]
@@ -86,6 +86,7 @@ module RelatonIso
86
86
  # @return [RelatonIso::HitCollection]
87
87
  def filter_hits_by_year(hit_collection, year) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
88
88
  missed_years = []
89
+ return { hits: hit_collection, missed_years: missed_years } if year.nil?
89
90
 
90
91
  # filter by year
91
92
  hits = hit_collection.select do |hit|
@@ -103,27 +104,22 @@ module RelatonIso
103
104
  end
104
105
  end
105
106
 
106
- if hits.empty? && !missed_years.empty?
107
- warn "[relaton-iso] (There was no match for #{year}, though there "\
108
- "were matches found for #{missed_years.join(', ')}.)"
109
- end
110
- hits
107
+ { hits: hits, missed_years: missed_years }
111
108
  end
112
109
 
113
110
  private
114
111
 
115
- def fetch_ref_err(query_pubid, year) # rubocop:disable Metrics/MethodLength
116
- id = year ? "#{query_pubid}:#{year}" : query_pubid
117
- warn "[relaton-iso] WARNING: no match found online for #{id}. "\
112
+ def fetch_ref_err(query_pubid) # rubocop:disable Metrics/MethodLength
113
+ warn "[relaton-iso] WARNING: no match found online for #{query_pubid}. " \
118
114
  "The code must be exactly like it is on the standards website."
119
115
  if /\d-\d/.match? query_pubid.to_s
120
- warn "[relaton-iso] The provided document part may not exist, "\
116
+ warn "[relaton-iso] The provided document part may not exist, " \
121
117
  "or the document may no longer be published in parts."
122
118
  else
123
- warn "[relaton-iso] If you wanted to cite all document parts for "\
124
- "the reference, use \"#{query_pubid} (all parts)\".\nIf the document "\
125
- "is not a standard, use its document type abbreviation "\
126
- "(TS, TR, PAS, Guide)."
119
+ warn "[relaton-iso] If you wanted to cite all document parts for " \
120
+ "the reference, use \"#{query_pubid} (all parts)\"."
121
+ warn "[relaton-iso] If the document is not a standard, use its " \
122
+ "document type abbreviation (TS, TR, PAS, Guide)."
127
123
  end
128
124
  nil
129
125
  end
@@ -133,26 +129,34 @@ module RelatonIso
133
129
  # @param query_pubid [Pubid::Iso::Identifier] reference without correction
134
130
  # @param opts [Hash]
135
131
  # @return [Array<RelatonIso::Hit>]
136
- def isobib_search_filter(query_pubid, opts) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
132
+ def isobib_search_filter(query_pubid, opts) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
133
+ missed_years = []
137
134
  query_pubid.part = nil if opts[:all_parts]
138
135
  warn "[relaton-iso] (\"#{query_pubid}\") fetching..."
139
136
  # fetch hits collection
140
137
  hit_collection = search(query_pubid.to_s(with_date: false))
141
138
  # filter only matching hits
142
- res = filter_hits hit_collection, query_pubid,
143
- all_parts: opts[:all_parts]
144
- return res unless res.empty?
139
+ res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
140
+ return res unless res[:hits].empty?
145
141
 
142
+ missed_years += res[:missed_years]
146
143
  # lookup for documents with stages when no match without stage
147
144
  res = filter_hits hit_collection, query_pubid,
148
145
  all_parts: opts[:all_parts], any_types_stages: true
149
- return res unless res.empty?
146
+ return res unless res[:hits].empty?
150
147
 
148
+ missed_years += res[:missed_years]
151
149
  # TODO: do this at pubid-iso
152
150
  if query_pubid.publisher == "ISO" && query_pubid.copublisher.nil? # try ISO/IEC if ISO not found
153
151
  warn "[relaton-iso] Attempting ISO/IEC retrieval"
154
152
  query_pubid.copublisher = "IEC"
155
153
  res = filter_hits hit_collection, query_pubid, all_parts: opts[:all_parts]
154
+ missed_years += res[:missed_years]
155
+ end
156
+
157
+ if res[:hits].empty? && missed_years.any?
158
+ warn "[relaton-iso] (There was no match for #{query_pubid.year}, though there "\
159
+ "were matches found for #{missed_years.uniq.join(', ')}.)"
156
160
  end
157
161
  res
158
162
  end
@@ -172,7 +176,7 @@ module RelatonIso
172
176
  query_pubid.amendments == hit_pubid.amendments
173
177
  end
174
178
 
175
- query_pubid.year ? filter_hits_by_year(result, query_pubid.year) : result
179
+ filter_hits_by_year(result, query_pubid.year)
176
180
  end
177
181
  end
178
182
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RelatonIso
4
- VERSION = "1.12.2"
4
+ VERSION = "1.13.0"
5
5
  end
data/relaton_iso.gemspec CHANGED
@@ -40,5 +40,5 @@ Gem::Specification.new do |spec|
40
40
 
41
41
  spec.add_dependency "algolia"
42
42
  spec.add_dependency "pubid-iso", "~> 0.1.8"
43
- spec.add_dependency "relaton-iso-bib", "~> 1.12.0"
43
+ spec.add_dependency "relaton-iso-bib", "~> 1.13.0"
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.2
4
+ version: 1.13.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-07-24 00:00:00.000000000 Z
11
+ date: 2022-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -198,14 +198,14 @@ dependencies:
198
198
  requirements:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
- version: 1.12.0
201
+ version: 1.13.0
202
202
  type: :runtime
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
- version: 1.12.0
208
+ version: 1.13.0
209
209
  description: 'RelatonIso: retrieve ISO Standards for bibliographic use using the IsoBibliographicItem
210
210
  model'
211
211
  email: