sul-dlss/argo

View on GitHub
app/services/collection_title_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

# Looks up collection title from Solr
class CollectionTitleService
  # @return [NilClass,String] the title of the collection if found in solr
  def self.find(collection_id)
    solr_doc = SearchService.query("id:\"#{collection_id}\"",
                                   rows: 1,
                                   fl: SolrDocument::FIELD_TITLE)['response']['docs'].first
    return unless solr_doc

    coll_title = solr_doc[SolrDocument::FIELD_TITLE]
    coll_title.is_a?(Array) ? coll_title.first : coll_title
  end
end