Skip to content

Commit

Permalink
return metadata identifiers in preferred order
Browse files Browse the repository at this point in the history
  • Loading branch information
peetucket committed Nov 26, 2019
1 parent a8708e5 commit 9bb4bcd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/services/metadata_service.rb
Expand Up @@ -16,9 +16,10 @@ def can_resolve?(identifier)
handlers.key?(prefix.to_sym)
end

# TODO: Return a prioritized list
# return the identfiers found in the same order of the known prefixes we specified
def resolvable(identifiers)
identifiers.select { |identifier| can_resolve?(identifier) }
res_ids = identifiers.select { |identifier| can_resolve?(identifier) }
MetadataService.known_prefixes.map { |prefix| res_ids.find { |res_id| res_id.start_with?(prefix.to_s) } }.compact
end

def fetch(identifier)
Expand Down
14 changes: 14 additions & 0 deletions spec/services/metadata_service_spec.rb
Expand Up @@ -7,6 +7,20 @@
expect { described_class.fetch('foo:bar') }.to raise_exception(MetadataError)
end

describe 'resolvable' do
it 'returns only resolvable identifiers' do
expect(described_class.resolvable(['bogus:1234', 'catkey:5678'])).to eq(['catkey:5678'])
end

it 'returns only resolvable identifiers in preferred order when more one is resolvable' do
expect(described_class.resolvable(['barcode:1234', 'catkey:5678'])).to eq(['catkey:5678', 'barcode:1234'])
end

it 'returns an empty array when no resolvable identifiers are found' do
expect(described_class.resolvable(['bogus:1234', 'nada:5678'])).to eq([])
end
end

describe 'Symphony handler' do
let(:resource) { instance_double(MarcxmlResource, mods: mods) }
let(:mods) { File.read(File.join(fixture_dir, 'mods_record.xml')) }
Expand Down

0 comments on commit 9bb4bcd

Please sign in to comment.