File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ def obj_cache_key
5555 "objects/#{ obj_id } -#{ timestamp } "
5656 end
5757
58- # QUESTION -> SHOULD THIS ALLOW DUPLICATE VALUES???
58+ # TODO: SHOULD THIS ALLOW DUPLICATE VALUES???
5959 def doi
6060 # Extract all subj proxy identifiers that match 10.()dot followed by 4 or 5 digits
6161 # then followed by a slash and finally followed by at least 1 character.
@@ -103,8 +103,16 @@ def issn
103103 Array . wrap ( obj_hash . dig ( "periodical" , "issn" ) ) . compact
104104 end
105105
106+ # TODO: WHY IS THIS AN ARRAY OF ARRAYS?
107+ # CAN WE CHANGE THIS TO BE A SIMPLE SINGLE ARRAY?
108+ # TODO: THE to_s CALL IS DONE BECAUSE OF THE EXISTING BUG
109+ # THAT ALLOWS NULL VALUES. IF WE CHANGE THIS AND CLEAN
110+ # THE DATA WE COULD REMOVE THIS CALL IN THE FUTURE.
106111 def prefix
107- [ doi . map { |d | d . to_s . split ( "/" , 2 ) . first } ] . compact
112+ # Loop through all dois in the doi array
113+ # Split each doi at the first slash -> /
114+ # And return the first element in that array i.e. the prefix
115+ [ doi . map { |d | d . split ( "/" , 2 ) . first } ] . compact
108116 end
109117
110118 def subtype
Original file line number Diff line number Diff line change 184184 expect ( event . issn ) . to ( eq ( [ ] ) )
185185 end
186186 end
187+
188+ describe "prefix" do
189+ it "when doi has dois returns the prefix of each doi" do
190+ event . subj_id = "10.0000/0000"
191+ event . obj_id = "10.0001/0001"
192+
193+ event . subj = {
194+ "proxyIdentifiers" : [ "10.0002/0002" ] ,
195+ "funder" : [ { "@id" : "10.0003/0003" } ] ,
196+ } . to_json
197+
198+ event . obj = {
199+ "proxyIdentifiers" : [ "10.0004/0004" ] ,
200+ "funder" : [ { "@id" : "10.0005/0005" } ] ,
201+ } . to_json
202+
203+ expect ( event . prefix . flatten ) . to ( contain_exactly (
204+ "10.0000" ,
205+ "10.0001" ,
206+ "10.0002" ,
207+ "10.0003" ,
208+ "10.0004" ,
209+ "10.0005" ,
210+ ) )
211+ end
212+
213+ it "when doi is an empty array returns an empty array" do
214+ event . subj_id = nil
215+ event . obj_id = nil
216+
217+ expect ( event . prefix . flatten ) . to ( eq ( [ ] ) )
218+ end
219+ end
187220end
You can’t perform that action at this time.
0 commit comments