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

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 inherited from Service

#display_name, #handle_wrapper, #link_out_filter, #preempted_by, required_config_params, #response_to_view_data, #response_url, #session, #update_session, #view_data_from_service_type

Constructor Details

- (Gpo) initialize(config)



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



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
119
# File 'lib/service_adaptors/gpo.rb', line 84

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

  hpricot = Hpricot(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 = hpricot.search('//tr[@class = "tr1"][td]/td:eq(6)/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

- (Object) analyze_gpo_items(items)

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



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

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

- (Object) gpo_item_lookup_url(item)



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

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

- (Object) gpo_sudoc_find_url(sudoc)



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

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

- (Object) handle(request)



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
52
# 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

- (Object) service_types_generated



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