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/proxis.rb 132 89
32.6% 
19.1% 
  1 # Copyright (C) 2004-2006 Pascal Terjan 
  2 #
  3 # Alexandria is free software; you can redistribute it and/or
  4 # modify it under the terms of the GNU General Public License as
  5 # published by the Free Software Foundation; either version 2 of the
  6 # License, or (at your option) any later version.
  7 #
  8 # Alexandria is distributed in the hope that it will be useful,
  9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11 # General Public License for more details.
 12 #
 13 # You should have received a copy of the GNU General Public
 14 # License along with Alexandria; see the file COPYING.  If not,
 15 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 16 # Boston, MA 02111-1307, USA.
 17 
 18 require 'cgi'
 19 require 'net/http'
 20 
 21 module Alexandria
 22 class BookProviders
 23     class ProxisProvider < GenericProvider
 24         include GetText
 25         GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
 26         
 27         LANGUAGES = {
 28             'nl' => '1',
 29             'en' => '2',
 30             'fr' => '3'
 31         }
 32 
 33         def initialize
 34             super("Proxis", "Proxis (Belgium)")
 35             prefs.add("lang", _("Language"), "fr",
 36                       LANGUAGES.keys)
 37         end
 38         
 39         def search(criterion, type)
 40             prefs.read
 41 
 42             criterion = criterion.convert("windows-1252", "UTF-8")
 43             req = case type
 44                 when SEARCH_BY_ISBN
 45                     "p_isbn=#{Library.canonicalise_isbn(criterion)}&p_title=&p_author="
 46           
 47                 when SEARCH_BY_TITLE
 48                     "p_isbn=&p_title=#{CGI::escape(criterion)}&p_author="
 49           
 50                 when SEARCH_BY_AUTHORS
 51                     "p_isbn=&p_title=&p_author=#{CGI::escape(criterion)}"
 52             
 53                 when SEARCH_BY_KEYWORD
 54                     "p_isbn=&p_title=&p_author=&p_keyword=#{CGI::escape(criterion)}"
 55           
 56                 else
 57                     raise InvalidSearchTypeError
 58 
 59             end
 60           
 61             products = {}
 62             results_page = "http://oas2000.proxis.be/gate/jabba.search.submit_search?#{req}&p_item=#{LANGUAGES[prefs['lang']]}&p_order=1&p_operator=K&p_filter=1"
 63             transport.get(URI.parse(results_page)).each do |line|
 64                 if line =~ /br>.*DETAILS&mi=([^&]*)&si=/ #and (!products[$1]) and (book = parseBook($1)) then
 65                     book = parseBook($1)
 66                     products[$1] = book
 67                 end
 68             end
 69             
 70 	    # Workaround Proxis returning all editions of a book when searching on ISBN
 71 	    if type == SEARCH_BY_ISBN 
 72 		    products.delete_if {|n, p| p.first.isbn != Library.canonicalise_ean(criterion)}
 73 	    end
 74 	    
 75             raise NoResultsError if products.values.empty?
 76             type == SEARCH_BY_ISBN ? products.values.first : products.values
 77         end
 78 
 79         def url(book)
 80             "http://oas2000.proxis.be/gate/jabba.search.submit_search?p_isbn=" + Library.canonicalise_isbn(book.isbn) + "&p_item=1"
 81         end
 82 
 83         #######
 84         private
 85         #######
 86 
 87         def parseBook(product_id)
 88             conv = proc { |str| str.convert("UTF-8", "windows-1252") if str != nil }
 89             detailspage='http://oas2000.proxis.be/gate/jabba.coreii.g_p?bi=4&sp=DETAILS&mi='+product_id
 90             product = {}
 91             product['authors'] = []
 92             nextline = nil
 93             transport.get(URI.parse(detailspage)).each do |line|
 94                 if line =~ /span class="?AUTHOR"?>([^<]*)&nbsp; &nbsp;/i
 95                     author = $1.gsub('&nbsp;',' ').sub(/ +$/,'')
 96                     product['authors'] << author
 97                 elsif line =~ /SRC="(http:\/\/www.proxis.be\/IMG.\/.*)M\.jpg"/i 
 98                     product['image_url_small'] = $1+'S.jpg'
 99                     product['image_url_medium'] = $1+'M.jpg'
100                     product['image_url_large'] = $1+'L.jpg'
101 #                elsif line =~ /class="?TITLECOLOR"?>([^<]*)</i 
102                 elsif line =~ /<tr width="?100%"?><td valign="?middle"? width="?100%"? class="?verd_13_b"?>([^<]*)</i 
103                     product['name'] = $1.sub(/ +$/,'')
104                 elsif line =~ /Barcode \(EAN\)<\/TD><TD class="?INFO"?> : ([^<]*)</i 
105                     product['isbn'] = $1
106                 elsif line =~ /Publication date<\/TD><TD class="?INFO"?> : ..\/..\/([[:digit:]]{4})/i
107                     product['year'] = $1.to_i
108                 elsif line =~ /Type<\/TD>/i
109                     nextline = "media"
110                 elsif line =~ /(Publisher|Editeur|Uitgever)<\/TD><TD CLASS="?INFO"?>: ([^<]*)</i 
111                     product['manufacturer'] = $2
112                 elsif line =~ /TD CLASS="?INFO"?>: ([^<]*)</i and nextline
113                     product[nextline] = $1
114                 end
115             end
116 
117 #            %w{name isbn media manufacturer}.each do |field|
118 #                product[field] = "" if product[field].nil?
119 #            end 
120             
121             book = Book.new(conv.call(product['name']),
122                             (product['authors'].map { |x| conv.call(x) } rescue [  ]),
123                             conv.call(product['isbn']),
124                             conv.call(product['manufacturer']),
125                             product['year'],
126                             conv.call(product['media']))
127         
128             return [ book, product['image_url_medium'] ]
129         end
130     end
131 end
132 end

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

Valid XHTML 1.0! Valid CSS!