Sha256: 75e0ccbf91a25cf742b0835ff3ccbda4973c57924d349b63fcae34b5a0831fd7
Contents?: true
Size: 933 Bytes
Versions: 4
Compression:
Stored size: 933 Bytes
Contents
module QuickSearch::DoiTrap extend ActiveSupport::Concern include QuickSearch::EncodeUtf8 private def doi_trap unless params_q_scrubbed.nil? if is_a_doi?(doi_query) Event.create(category: 'doi-trap', action: doi_query, label: '') redirect_to doi_loaded_link # Alternately insert a loaded link into the results interface # @doi_loaded_link = loaded_link # @doi_callout = "Searching for a DOI? Try this: " end end end def is_a_doi?(query) if doi_regex.match(query) true else false end end def doi_regex /^(?:(?:doi:?\s*|(?:http:\/\/)?(?:dx\.)?(?:doi\.org)?\/))?(10(?:\.\d+){1,2}\/\S+)$/i end def doi_loaded_link QuickSearch::Engine::APP_CONFIG['doi_loaded_link'] + CGI.escape(doi_regex.match(doi_query)[1]) end def doi_query query = params_q_scrubbed query.strip! query.squish! query end end
Version data entries
4 entries across 4 versions & 1 rubygems