relaton-iec 2.0.0.pre.alpha.2 → 2.0.0.pre.alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30dae3e87187acb54f65270769022c3c33222ae09c53d06465b4de77c780f222
4
- data.tar.gz: b6e962ea1ae3ab83769d05242a4063ab780307c57ee7167570fec219790cad0c
3
+ metadata.gz: ed597ec310f08e21a319b80ba42b45dc9e431a2b14100c18d45353314c44bb80
4
+ data.tar.gz: c9f4043f6d6e9e98359afea8ff2f6b9499ca408712f65f4c90d514a290fdedfe
5
5
  SHA512:
6
- metadata.gz: e9cfdf2b74d1d65ea5a2101ded6c12a5abddeebd25fb457cf559374f6630640493d4cbb287eaf5a32cf9f1acf4d9ffb617e5fbdbab3c68d85d41e702623e0193
7
- data.tar.gz: e659dd250b4c05d315c508f26a864ef56c8081c2181a43ee18eaa579cdb4be68ce8be09a59ad9e8b6af7a0df593e1ce6dd3823d1bc7bf7c2a9c342056f68c129
6
+ metadata.gz: c04abe068d4badc329f6e2a7598bf13562b3e21b6163a1d02593b7c52ba91385cd97c1c45aee087f8b909dca148bdaa4bdf58cffaf4e0b35036ddf569e9efb95
7
+ data.tar.gz: 120b8a7267badaf015db74182579fe079fb43e08d9fc2987c72d7cfb2772581f3467e969c24ad51245d5de8f098a9562d27b45048bf0fd4f0c97164e39481c99
@@ -179,10 +179,63 @@ module Relaton
179
179
  ret = hit.item
180
180
  if publication_date_in_range?(ret, opts)
181
181
  Util.info "Found: `#{ret.docidentifier.first.content}`", key: pubid.to_s
182
- ret
182
+ freeze_item(ret, opts)
183
183
  end
184
184
  end
185
185
 
186
+ # Freeze a document in time by filtering out relations, dates, and status
187
+ # that fall outside the specified date range.
188
+ def freeze_item(item, opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
189
+ return item unless opts[:publication_date_before] || opts[:publication_date_after]
190
+
191
+ item.relation = item.relation.select { |r| relation_in_range?(r, opts) }
192
+
193
+ had_obsoleted = item.date.any? { |d| d.type == "obsoleted" }
194
+ item.date = item.date.select { |d| date_entry_in_range?(d, opts) }
195
+ lost_obsoleted = had_obsoleted && item.date.none? { |d| d.type == "obsoleted" }
196
+
197
+ if lost_obsoleted && item.status&.stage&.content == "95"
198
+ item.status.stage.content = "60"
199
+ item.status.substage&.content = "60"
200
+ end
201
+
202
+ item
203
+ end
204
+
205
+ # Check if a relation's bibitem falls within the date range.
206
+ def relation_in_range?(rel, opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
207
+ rel.bibitem.date&.each do |d|
208
+ dt = (d.at || d.from)&.to_date
209
+ next unless dt
210
+
211
+ return false if opts[:publication_date_before] && dt >= opts[:publication_date_before]
212
+ return false if opts[:publication_date_after] && dt < opts[:publication_date_after]
213
+ end
214
+
215
+ rel.bibitem.docidentifier&.each do |did|
216
+ year = did.content[/:(\d{4})/, 1]&.to_i
217
+ next unless year&.positive?
218
+
219
+ return false if opts[:publication_date_before] && year >= opts[:publication_date_before].year
220
+ return false if opts[:publication_date_after] && year < opts[:publication_date_after].year
221
+ end
222
+
223
+ true
224
+ end
225
+
226
+ # Check if a date entry falls within the date range (always keeps published).
227
+ def date_entry_in_range?(date_entry, opts)
228
+ return true if date_entry.type == "published"
229
+
230
+ dt = (date_entry.at || date_entry.from)&.to_date
231
+ return true unless dt
232
+
233
+ return false if opts[:publication_date_before] && dt >= opts[:publication_date_before]
234
+ return false if opts[:publication_date_after] && dt < opts[:publication_date_after]
235
+
236
+ true
237
+ end
238
+
186
239
  # Analyze why no match was found and give helpful tips.
187
240
  # @param pubid [Pubid::Iec::Identifier]
188
241
  # @param result [Relaton::Iec::HitCollection]
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Iec
3
- VERSION = "2.0.0-alpha.2".freeze
3
+ VERSION = "2.0.0-alpha.3".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.2
4
+ version: 2.0.0.pre.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.