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 +4 -4
- data/lib/relaton/iso/bibliography.rb +43 -1
- data/lib/relaton/iso/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db5f86dd933721ca9fb4b0da9000e420f96cbf3bf0899520859e2f7789791420
|
|
4
|
+
data.tar.gz: 5d5bf96408c996c7289aadc14d5993d5fa12c3a1d15f013110545b44de4a0e5c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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]
|
data/lib/relaton/iso/version.rb
CHANGED