Class: Gpo

Inherits:
Service show all
Includes:
MetadataHelper
Defined in:
lib/service_adaptors/gpo.rb

Overview

Still in progress. Uses illegal info:sudoc and info:gpo to get a a sudoc or a GPO Item Number for a given referent, and finds online availability, and/or links to GPO lookup for local depository with the item.

Constant Summary

Constants inherited from Service

Service::LinkOutFilterTask, Service::StandardTask

Instance Attribute Summary

Attributes inherited from Service

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

Instance Method Summary collapse

Methods included from MetadataHelper

#get_doi, #get_gpo_item_nums, #get_identifier, #get_isbn, #get_issn, #get_lccn, #get_oclcnum, #get_pmid, #get_search_creator, #get_search_terms, #get_search_title, #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) ⇒ Gpo

Returns a new instance of Gpo.



11
12
13
14
15
16
# File 'lib/service_adaptors/gpo.rb', line 11

def initialize(config)
  @display_name = "U.S. Government Printing Office"
  @gpo_item_find = true
  @sudoc_url_lookup = true
  super(config)
end

Instance Method Details



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/service_adaptors/gpo.rb', line 83

def add_links_from_sudoc(request, sudoc)
  # Screen scrape the GPO catalog.
  
  response = open( gpo_sudoc_find_url(sudoc)  ).read

  response_dom = Nokogiri::HTML(response)
  
  # Find each tr with class tr1, holding a td => The sixth td in there =>
  # one or more 'a' tags in there. These are links to fulltext. 
  links = response_dom.search('//tr[@class = "tr1"][td]/td[7]/a')

  urls_seen = []
  
  links.each do |link|
    # The href is an internally pointing ILS link. But the text inside
    # the a is what we want, it's actually a URL, fortunately. . 

    url = link.inner_text
    unless urls_seen.include?(url)
    
      notes = nil
      if (links.length > 1)        
        notes = "via " + URI.parse(url).host
      end

      request.add_service_response(:service => self, 
       :display_text => @display_name,
       :url => url,
       :notes => notes,
       :service_type_value => "fulltext"
       )
       urls_seen.push( url )
    end         
  end
  
end

#analyze_gpo_items(items) ⇒ Object

Takes an array of string of GPO Items with formats in parens, groups them by individual Item Number, identified by formats.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/service_adaptors/gpo.rb', line 55

def analyze_gpo_items(items)
  item_hash = {}

  items.each do |i|      

    bare_item = i
    format_str = 'paper'

    # seperate the format marker from the base item number, if present.
    # if it's not present, means paper. 
    if ( i =~ /^(.*)\(([^\)]+)\)\s*$/  )      
      bare_item = $1.strip
      format_str = $2.strip
      format_str = "microform" if format_str == "MF"
    end
    
    item_hash[bare_item] ||= []
    
    item_hash[bare_item].push( format_str )      
  end
  
  return item_hash  
end

#gpo_item_lookup_url(item) ⇒ Object



79
80
81
# File 'lib/service_adaptors/gpo.rb', line 79

def gpo_item_lookup_url(item)
  return "http://catalog.gpo.gov/fdlpdir/locate.jsp?ItemNumber=" + CGI.escape(item)
end

#gpo_sudoc_find_url(sudoc) ⇒ Object



120
121
122
# File 'lib/service_adaptors/gpo.rb', line 120

def gpo_sudoc_find_url(sudoc)
  return "http://catalog.gpo.gov/F/?func=find-a&find_code=GVD&request=#{CGI.escape('"'+sudoc+'"')}&local_base=GPO01PUB"
end

#handle(request) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/service_adaptors/gpo.rb', line 25

def handle(request)
  
  if ( @gpo_item_find )
    items = analyze_gpo_items(  get_gpo_item_nums(request.referent)  )
    
    items.each do |item, formats|
       # Generate URL to GPO Item Number lookup to finding
       # it in a repository near you. 

       request.add_service_response(:service => self, 
           :display_text => "Find in a Federal Depository Library",
           :url => gpo_item_lookup_url(item),
           :notes => "In " + formats.join(" or "),
           :service_type_value => "highlighted_link"
           )
    end
  end
  sudoc = get_sudoc(request.referent)
  
  if ( sudoc && @sudoc_url_lookup )
    add_links_from_sudoc(request, sudoc)
  end
  

  request.dispatched(self, true)
  
end

#service_types_generatedObject



18
19
20
21
22
23
# File 'lib/service_adaptors/gpo.rb', line 18

def service_types_generated
  a = []
  a.push(ServiceTypeValue["highlighted_link"]) if @gpo_item_find
  a.push(ServiceTypeValue["fulltext"]) if @sudoc_url_lookup
  return a
end