Class: Gpo
- Includes:
- MetadataHelper
- Defined in:
- app/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
#group, #name, #priority, #request, #service_id, #status, #task, #url
Instance Method Summary collapse
- #add_links_from_sudoc(request, sudoc) ⇒ Object
-
#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.
- #gpo_item_lookup_url(item) ⇒ Object
- #gpo_sudoc_find_url(sudoc) ⇒ Object
- #handle(request) ⇒ Object
-
#initialize(config) ⇒ Gpo
constructor
A new instance of Gpo.
- #service_types_generated ⇒ Object
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_url, #translate
Constructor Details
#initialize(config) ⇒ Gpo
Returns a new instance of Gpo.
11 12 13 14 15 16 |
# File 'app/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
#add_links_from_sudoc(request, sudoc) ⇒ Object
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 'app/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 'app/service_adaptors/gpo.rb', line 55 def analyze_gpo_items(items) item_hash = {} items.each do |i| = 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*$/ ) = $1.strip format_str = $2.strip format_str = "microform" if format_str == "MF" end item_hash[] ||= [] item_hash[].push( format_str ) end return item_hash end |
#gpo_item_lookup_url(item) ⇒ Object
79 80 81 |
# File 'app/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 'app/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 'app/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_generated ⇒ Object
18 19 20 21 22 23 |
# File 'app/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 |