C0 code coverage information

Generated on Tue Oct 16 11:40:47 -0400 2007 with rcov 0.8.0


Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name Total lines Lines of code Total coverage Code coverage
lib/alexandria/book_providers/mcu.rb 163 106
48.5% 
35.8% 
  1 # Copyright (C) 2004 Javier Fernandez-Sanguino
  2 # Copyright (C) 2007 Javier Fernandez-Sanguino and Marco Costantini
  3 #
  4 # Alexandria is free software; you can redistribute it and/or
  5 # modify it under the terms of the GNU General Public License as
  6 # published by the Free Software Foundation; either version 2 of the
  7 # License, or (at your option) any later version.
  8 #
  9 # Alexandria is distributed in the hope that it will be useful,
 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12 # General Public License for more details.
 13 #
 14 # You should have received a copy of the GNU General Public
 15 # License along with Alexandria; see the file COPYING.  If not,
 16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 17 # Boston, MA 02111-1307, USA.
 18 
 19 require 'cgi'
 20 require 'net/http'
 21 
 22 # http://www.mcu.es/libro/CE/AgenciaISBN/BBDDLibros/Sobre.html
 23 # http://www.mcu.es/comun/bases/isbn/ISBN.html
 24 
 25 module Alexandria
 26 class BookProviders
 27     class MCUProvider < GenericProvider
 28         include GetText
 29         GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
 30         
 31         LANGUAGES = {
 32             'es' => '1'
 33         }
 34 
 35 #        BASE_URI = "http://www.mcu.es/cgi-bin/BRSCGI3701?"
 36         BASE_URI = "http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?"
 37         def initialize
 38             super("MCU", _("Spanish Culture Ministry"))
 39 	    # No preferences
 40         end
 41         
 42         def search(criterion, type)
 43             prefs.read
 44 	    criterion = criterion.convert("ISO-8859-1", "UTF-8")
 45 	    print "Doing search with MCU #{criterion}, type: #{type}\n" if $DEBUG # for DEBUGing
 46             req = BASE_URI + "CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1-1000&SEPARADOR=&"
 47             req += case type
 48                 when SEARCH_BY_ISBN
 49                     "WGEN-C=&WISB-C=#{CGI::escape(criterion)}&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
 50 
 51                 when SEARCH_BY_TITLE
 52 		    "WGEN-C=&WISB-C=&WAUT-C=&WTIT-C=#{CGI::escape(criterion)}&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
 53 
 54                 when SEARCH_BY_AUTHORS
 55 		      "WGEN-C=&WISB-C=&WAUT-C=#{CGI::escape(criterion)}&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
 56 
 57                 when SEARCH_BY_KEYWORD
 58 			"WGEN-C=#{CGI::escape(criterion)}&WISB-C=&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
 59 
 60                 else
 61                     raise InvalidSearchTypeError
 62             end
 63             products = {}
 64 	    print "Request page is #{req}\n" if $DEBUG # for DEBUGing
 65             transport.get(URI.parse(req)).each do |line|
 66 	    	#line = line.convert("ISO-8859-1", "UTF-8")
 67 	    	print "Reading line: #{line}" if $DEBUG # for DEBUGing
 68                 if (line =~ /CMD=VERDOC.*&DOCN=([^&]*)&NDOC=([^&]*)/) and (!products[$1]) and (book = parseBook($1,$2)) then
 69                     products[$1] = book
 70                     puts $1 if $DEBUG # for DEBUGing
 71                 end
 72             end
 73 
 74             raise NoResultsError if products.values.empty?
 75             type == SEARCH_BY_ISBN ? products.values.first : products.values
 76         end
 77         
 78         def url(book)
 79             "http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERLST&BASE=ISBN&DOCS=1-15&CONF=AEISPA.cnf&OPDEF=AND&DOCS=1&SEPARADOR=&WGEN-C=&WISB-C=" + book.isbn + "&WAUT-C=&WTIT-C=&WMAT-C=&WEDI-C=&WFEP-C=&%40T353-GE=&%40T353-LE=&WSER-C=&WLUG-C=&WDIS-C=%28DISPONIBLE+or+AGOTADO%29&WLEN-C=&WCLA-C=&WSOP-C="
 80         end
 81 
 82         #######
 83         private
 84         #######
 85 
 86         def parseBook(docn,ndoc)
 87             detailspage='http://www.mcu.es/cgi-brs/BasesHTML/isbn/BRSCGI?CMD=VERDOC&CONF=AEISPA.cnf&BASE=ISBN&DOCN=' + docn + '&NDOC=' + ndoc
 88 	    print "Looking at detailspage: #{detailspage}\n" if $DEBUG # for DEBUGing
 89             product = {}
 90             product['authors'] = []
 91             nextline = nil
 92 	    robotstate = 0
 93             transport.get(URI.parse(detailspage)).each do |line|
 94 	    # This is a very crude robot interpreter
 95 	    # Note that the server provides more information 
 96 	    # we don't store:
 97 	    # - Language  - Description
 98 	    # - Binding   - Price 
 99 	    # - Colection - Theme
100 	    # - CDU      - Last update
101 
102 	    # There seems to be an issue with accented chars..
103 	    line = line.convert("UTF-8", "ISO-8859-1")
104 	    print "Reading line (robotstate #{robotstate}): #{line}" if $DEBUG # for DEBUGing
105                 if line =~ /^<\/td>$/ or line =~ /^<\/tr>$/
106 		    robotstate = 0 
107 		elsif robotstate == 1 and line =~ /^([^<]+)</ 
108 	 	    author = $1.gsub('&nbsp;',' ').sub(/ +$/,'')
109 		    if author.length > 3 then
110 		    # Only add authors of appropiate length
111        	       		    product['authors'] << author
112 			    print "Authors are #{product['authors']}\n" if $DEBUG # for DEBUGing
113 		    robotstate = 0
114 		    end
115                 elsif robotstate == 2 and line =~ /^(.*)$/ # The title es the next line to title declaration and has not tags on web src code
116 	            product['name'] = $1.strip
117 		    print "Name is #{product['name']}\n" if $DEBUG # for DEBUGing
118                     robotstate = 0
119 		elsif robotstate == 3 and line =~ /^([0-9]+-[0-9]+-[0-9]+-[0-9]+-[0-9]).*/ 
120                     product['isbn'] = $1
121 		    print "ISBN is #{product['isbn']}\n" if $DEBUG # for DEBUGing
122 		    robotstate = 0
123                 elsif robotstate == 4 and line =~ /^([^<]+)</
124                     product['manufacturer'] = $1.strip
125 		    print "Manufacturer is #{product['manufacturer']}\n" if $DEBUG # for DEBUGing
126 		    robotstate = 0 
127 #                elsif robotstate == 5 and line =~ /^([^<]+)</
128                 elsif robotstate == 5 and line =~ /<span>([^<]+)</
129                     product['media'] = $1.strip
130 		    print "Media is #{product['media']}\n" if $DEBUG # for DEBUGing
131 		    robotstate = 0 
132                 elsif line =~ /^.*>Autor:\s*</
133 		    robotstate = 1
134                 elsif line =~ /^.*>T(.|&iacute;)tulo:\s*</
135 		    robotstate = 2
136                 elsif line =~ /^.*>ISBN \(13\):\s*</
137 		    robotstate = 3
138                 elsif line =~ /^.*>Publicaci(.|&oacute;)n:\s*</
139 		    robotstate = 4
140                 elsif line =~ /^.*>Encuadernaci(.|&oacute;)n:\s*</
141 		    robotstate = 5 
142                 end
143             end
144 
145 	    # TODO: This provider does not include picture for books
146 #            %w{name isbn media manufacturer}.each do |field|
147 #	        print "Checking #{field} for nil\n" if $DEBUG # for DEBUGing
148 #                product[field]="" if product[field].nil?
149 #            end 
150             
151 	    print "Creating new book\n" if $DEBUG # for DEBUGing
152 	    book = Book.new(product['name'],
153 	                    product['authors'],
154 			    product['isbn'].delete('-'),
155 			    product['manufacturer'],
156                 nil, # TODO: furnish publish year
157 			    product['media'])
158             return [ book ]
159         end
160 
161     end
162 end
163 end

Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.

Valid XHTML 1.0! Valid CSS!