Skip to content

Commit e2ca547

Browse files
Add event index handler specs
1 parent ba6bd28 commit e2ca547

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

app/models/concerns/event_index_handler.rb

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,9 @@ def obj_cache_key
5555
"objects/#{obj_id}-#{timestamp}"
5656
end
5757

58-
# accepts dois that start with 10. (dot)
59-
# followed by 4 or five digits 10.1234 or 10.12345
60-
# followed by a slash 10.1234/
61-
# followed by at least one more character 10.1234/123
6258
# QUESTION -> SHOULD THIS ALLOW DUPLICATE VALUES???
6359
def doi
64-
Array.wrap(subj_hash["proxyIdentifiers"])
65-
.map { |s| s[%r{\A(10\.\d{4,5}/.+)\z}, 1] }
66-
.compact +
67-
Array.wrap(obj_hash["proxyIdentifiers"])
68-
.map { |s| s[%r{\A(10\.\d{4,5}/.+)\z}, 1] }
69-
.compact +
70-
Array.wrap(subj_hash["funder"])
71-
.map { |f| DoiUtilities.doi_from_url(f["@id"]) }
72-
.compact +
73-
Array.wrap(obj_hash["funder"])
74-
.map { |f| DoiUtilities.doi_from_url(f["@id"]) }
75-
.compact +
60+
subj_proxy_identifier_dois + obj_proxy_identifier_dois + subj_funder_dois + obj_funder_dois +
7661
[DoiUtilities.doi_from_url(subj_id), DoiUtilities.doi_from_url(obj_id)].compact
7762
end
7863

@@ -162,4 +147,36 @@ def cache_key
162147
def date_published(doi)
163148
Doi.publication_date(doi)
164149
end
150+
151+
private
152+
153+
def subj_proxy_identifier_dois
154+
# Extract all subj proxy identifiers that match 10.()dot followed by 4 or 5 digits
155+
# then followed by a slash and finally followed by at least 1 character.
156+
# i.e. 10.1234/a, 10.12345/zenodo.100
157+
Array.wrap(subj_hash["proxyIdentifiers"])
158+
.map { |s| s[%r{\A(10\.\d{4,5}/.+)\z}, 1] }
159+
.compact
160+
end
161+
162+
def obj_proxy_identifier_dois
163+
# Extract all obj proxy identifiers that match 10.()dot followed by 4 or 5 digits
164+
# then followed by a slash and finally followed by at least 1 character.
165+
# i.e. 10.1234/a, 10.12345/zenodo.100
166+
Array.wrap(obj_hash["proxyIdentifiers"])
167+
.map { |s| s[%r{\A(10\.\d{4,5}/.+)\z}, 1] }
168+
.compact
169+
end
170+
171+
def subj_funder_dois
172+
Array.wrap(subj_hash["funder"])
173+
.map { |f| DoiUtilities.doi_from_url(f["@id"]) }
174+
.compact
175+
end
176+
177+
def obj_funder_dois
178+
Array.wrap(obj_hash["funder"])
179+
.map { |f| DoiUtilities.doi_from_url(f["@id"]) }
180+
.compact
181+
end
165182
end

0 commit comments

Comments
 (0)