Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Adding in an option to strip druid for the older net/http branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
carrickr committed Nov 11, 2014
1 parent 38a7111 commit 4002f44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/dor-fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@ def total_apo_count
#Method to parse full Hash into an array containing only the druids
#
#@param response [Hash] Hash as returned by query_api
#@param no_prefix [boolean] if true (default), remove the druid: prefix on all druids, if false, leave alone
#@return [Array] the array listing all druids in the supplied Hash
def druid_array(response)
def druid_array(response,params={})
return_list = []
j = response
j.keys.each do |key|
if key != @@counts_key
j[key].each do |item|
return_list << item['druid'] if item['druid'] != nil
if item['druid'] != nil
druid=item['druid'].downcase
druid.gsub!('druid:','') if params[:no_prefix]
return_list << druid
end
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/dor_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
expected_output = ["druid:yg867hg1375", "druid:jf275fd6276", "druid:nz353cp1092", "druid:tc552kq0798", "druid:th998nk0722", "druid:ww689vs6534"]
expect(@df.druid_array(input)).to eq(expected_output)
end

it "druid_array should take in JSON and return a list of just the druids, stripping off druid prefix if requested" do
input = JSON['{"collections":[{"druid":"DRUID:yg867hg1375","latest_change":"2013-11-11T23:34:29Z","title":"Francis E. Stafford photographs, 1909-1933"}],"items":[{"druid":"druid:jf275fd6276","latest_change":"2013-11-11T23:34:29Z","title":"Album A: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:nz353cp1092","latest_change":"2013-11-11T23:34:29Z","title":"Album E: Photographs of the Seventh Day Adventist Church missionaries in China"},{"druid":"druid:tc552kq0798","latest_change":"2013-11-11T23:34:29Z","title":"Album D: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."},{"druid":"druid:th998nk0722","latest_change":"2013-11-11T23:34:29Z","title":"Album C: Photographs of the Chinese Revolution of 1911 and the Shanghai Commercial Press"},{"druid":"druid:ww689vs6534","latest_change":"2013-11-11T23:34:29Z","title":"Album B: Photographs of Chinas natural landscapes, urban scenes, cultural landmarks, social customs, and people."}],"counts":{"collections":1,"items":5,"total_count":6}}']
expected_output = ["yg867hg1375", "jf275fd6276", "nz353cp1092", "tc552kq0798", "th998nk0722", "ww689vs6534"]
expect(@df.druid_array(input,{:no_prefix=>true})).to eq(expected_output)
end
end

describe "Calling RESTful API and processing output" do
Expand Down

0 comments on commit 4002f44

Please sign in to comment.