Class: IsbnLink

Inherits:
Service show all
Includes:
MetadataHelper
Defined in:
app/service_adaptors/isbn_link.rb

Overview

A simple service to generate a blind link (NOT pre-checked for hits, just blindly created from a template) out to a service based on ISBN.

May likely be sub-classed for specific services (see AllBooks.com), which set default values.

  • :link_template. => String where “%s” will be replaced with ISBN

  • :display_name

  • :dispaly_text. Such as “Compare online prices

  • :isbn_normalize. Default nil, set to :ten or :thirteen if you need to normalize

    ISBN before substituting in :link_template.
    

Direct Known Subclasses

AllBooksDotCom

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

#group, #name, #priority, #request, #service_id, #status, #task, #url

Instance Method Summary collapse

Methods included from MetadataHelper

#get_doi, #get_epage, #get_gpo_item_nums, #get_identifier, #get_isbn, #get_issn, #get_lccn, #get_month, #get_oclcnum, #get_pmid, #get_search_creator, #get_search_terms, #get_search_title, #get_spage, #get_sudoc, #get_top_level_creator, #get_year, #normalize_lccn, #normalize_title, #raw_search_title, #title_is_serial?

Methods included from MarcHelper

#add_856_links, #edition_statement, #get_title, #get_years, #gmd_values, #service_type_for_856, #should_skip_856_link?, #strip_gmd

Methods inherited from Service

#credits, #display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_to_view_data, #response_url, #view_data_from_service_type

Constructor Details

#initialize(config) ⇒ IsbnLink

Returns a new instance of IsbnLink.



21
22
23
24
25
26
# File 'app/service_adaptors/isbn_link.rb', line 21

def initialize(config)    
  @display_text   = "Compare online prices"
  @isbn_normalize = nil
  
  super(config)
end

Instance Method Details

#handle(umlaut_request) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/service_adaptors/isbn_link.rb', line 28

def handle(umlaut_request)
  
  isbn = get_isbn(umlaut_request.referent)
  
  # No isbn, nothing we can do. 
  return umlaut_request.dispatched(self, true) if isbn.blank?

  # invalid isbn? forget it. 
  return umlaut_request.dispatched(self, true) unless ISBN.valid?(isbn)

  if @isbn_normalize == :ten
    isbn = ISBN.ten(isbn)    
  elsif @isbn_normalize == :thirteen
    isbn = ISBN.thirteen(isbn)
  end
  
  # Add the link
  link = @link_template.gsub("%s", isbn)
  
  umlaut_request.add_service_response(
    :service=>self, 
    :url=> link, 
    :display_text=> @display_text,
    :service_type_value => ServiceTypeValue[:highlighted_link]
  )

  return umlaut_request.dispatched(self, true)
end

#service_types_generatedObject



17
18
19
# File 'app/service_adaptors/isbn_link.rb', line 17

def service_types_generated
  return [ServiceTypeValue['highlighted_link']]
end