relaton-iso 2.0.0.pre.alpha.3 → 2.0.0.pre.alpha.4

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: a4e9325119df51d5aea288a6d612d7353107a25ac3030715dcf910ffaea13c26
4
- data.tar.gz: e8167236cafc25b54a3a4d8d4bcee86dca7326103aec873e3534bf896e9c7498
3
+ metadata.gz: db5f86dd933721ca9fb4b0da9000e420f96cbf3bf0899520859e2f7789791420
4
+ data.tar.gz: 5d5bf96408c996c7289aadc14d5993d5fa12c3a1d15f013110545b44de4a0e5c
5
5
  SHA512:
6
- metadata.gz: 9166abf7a46ec9604872543c9e572eebb03c34146635c156393cdd4e27c684a94e657daec4f55a889e928e38453fa1c690b6bc13549c7a67f80c6d7a9de447ae
7
- data.tar.gz: 1a57e63a6faca62cf6ed1b6a6d0e346ae783f30d9d2bf48ef833cdeb6282f04b07e2af468183cedd0bf5367b12d71daeb9e5aad0574207c746d6c1cd6bcb0ca0
6
+ metadata.gz: 4ca11e7589947364be4a08be23a2bc64b4e1a75e90dbb058a8509133b60f5fdd501de1af9b707beb03d3843436d0ffbe24c27d9d32af3c9d88a08aa3b4ad2fc3
7
+ data.tar.gz: 499048e6a3c826a7e0bc9ea419d8f926a374538a04d109df94b51e66cf51cf55ec04bf1acba862b9df1615056f85bfe1d17d104a48f0b255a54797675ac8d3c4
@@ -59,7 +59,10 @@ module Relaton
59
59
  Util.info "Found: `#{response_pubid}`", key: query_pubid.to_s
60
60
  get_all = (query_pubid.root.year && opts[:keep_year].nil?) || opts[:keep_year] || opts[:all_parts] ||
61
61
  opts[:publication_date_before] || opts[:publication_date_after]
62
- return ret if get_all
62
+ if get_all
63
+ filter_relations_by_date(ret, opts) if date_filter
64
+ return ret
65
+ end
63
66
 
64
67
  ret.to_most_recent_reference
65
68
  rescue ::Pubid::Core::Errors::ParseError
@@ -118,6 +121,45 @@ module Relaton
118
121
 
119
122
  private
120
123
 
124
+ # Filter out relations whose referenced document falls outside the date range.
125
+ # @param item [Relaton::Iso::ItemData]
126
+ # @param opts [Hash]
127
+ def filter_relations_by_date(item, opts)
128
+ return unless item.relation&.any?
129
+
130
+ item.relation.reject! { |rel| relation_outside_date_range?(rel, opts) }
131
+ end
132
+
133
+ # Check if a relation's bibitem date falls outside the given date range.
134
+ # @param rel [Relaton::Iso::Relation]
135
+ # @param opts [Hash]
136
+ # @return [Boolean]
137
+ def relation_outside_date_range?(rel, opts)
138
+ rel_date = relation_date(rel)
139
+ return false unless rel_date
140
+
141
+ return true if opts[:publication_date_before] && rel_date >= opts[:publication_date_before]
142
+ return true if opts[:publication_date_after] && rel_date < opts[:publication_date_after]
143
+
144
+ false
145
+ end
146
+
147
+ # Extract a Date from the relation's bibitem using circulated/published date or docidentifier year.
148
+ # @param rel [Relaton::Iso::Relation]
149
+ # @return [Date, nil]
150
+ def relation_date(rel)
151
+ bib = rel.bibitem
152
+ date_entry = bib.date&.find { |d| d.type == "circulated" } ||
153
+ bib.date&.find { |d| d.type == "published" }
154
+ return date_entry.at.to_date if date_entry&.at
155
+
156
+ docid = bib.docidentifier&.find(&:primary)&.content || bib.formattedref
157
+ return unless docid
158
+
159
+ year = docid.to_s[/:(\d{4})/, 1]
160
+ Date.new(year.to_i, 1, 1) if year
161
+ end
162
+
121
163
  # Find the best match among hits using date filters.
122
164
  # @param hits [Relaton::Iso::HitCollection]
123
165
  # @param pubid [Pubid::Iso::Identifier]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Relaton
4
4
  module Iso
5
- VERSION = "2.0.0-alpha.3"
5
+ VERSION = "2.0.0-alpha.4"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-iso
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre.alpha.3
4
+ version: 2.0.0.pre.alpha.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.