C0 code coverage information

Generated on Tue Oct 16 11:40:48 -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/thalia.rb 142 89
29.6% 
13.5% 
  1 # Copyright (C) 2005-2006 Rene Samselnig
  2 # Copyright (C) 2007 Rene Samselnig 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 # http://de.wikipedia.org/wiki/Thalia_%28Buchhandel%29
 20 # Thalia.de bought the Austrian book trade chain Amadeus
 21 
 22 require 'net/http'
 23 require 'cgi'
 24 
 25 module Alexandria
 26 class BookProviders
 27     class ThaliaProvider < GenericProvider
 28     
 29         BASE_URI = "http://www.thalia.de/"
 30         def initialize
 31             super("Thalia", "Thalia (Germany)")
 32             # no preferences for the moment
 33         end
 34         
 35         def search(criterion, type)
 36             criterion = criterion.convert("ISO-8859-1", "UTF-8")
 37             req = BASE_URI + "shop/bde_bu_hg_startseite/schnellsuche/buch/?"
 38             #if type == SEARCH_BY_ISBN
 39             #    req += ""
 40             #else
 41             #    req += "act=suchen&"
 42             #end
 43             req += case type
 44                 when SEARCH_BY_ISBN
 45                     "fqbi="
 46 
 47                 when SEARCH_BY_TITLE
 48                     "fqbt="
 49 
 50                 when SEARCH_BY_AUTHORS
 51                     "fqba="
 52 
 53                 when SEARCH_BY_KEYWORD
 54                     "fqbs="
 55 
 56                 else
 57                     raise InvalidSearchTypeError
 58 
 59             end
 60 
 61             req += CGI.escape(criterion)
 62             p req if $DEBUG
 63             data = transport.get(URI.parse(req))
 64             if type == SEARCH_BY_ISBN
 65                 to_book(data) #rescue raise NoResultsError
 66             else
 67                 begin
 68                     results = [] 
 69                     each_book_page(data) do |page, title|
 70                         results << to_book(transport.get(URI.parse(BASE_URI + page)))
 71                     end
 72                     return results 
 73                 rescue
 74                     raise NoResultsError
 75                 end
 76             end
 77         end
 78 
 79         def url(book)
 80             BASE_URI + "shop/bde_bu_hg_startseite/schnellsuche/buch/?fqbi=" + book.isbn
 81         end
 82 
 83         #######
 84         private
 85         #######
 86     
 87         def to_book(data)
 88 						puts data if $DEBUG
 89 						raise NoResultsError if /Leider f&uuml;hrte Ihre Suche zu keinen Ergebnissen\./.match(data) != nil
 90 #						data = data.convert("UTF-8", "ISO-8859-1")
 91 						data = CGI::unescapeHTML(data)
 92 						product = {}
 93 						# title
 94             if md = /<span id="_artikel_titel">([^<]+)<\/span>/.match(data)
 95                 product["title"] = md[1].strip.unpack("C*").pack("U*")
 96             elsif md = /<div class="standard">\n<h3>\s*(<a title=".+"><\/a>\s+)?([^<]+)<span/.match(data)
 97                 product["title"] = md[2].strip.unpack("C*").pack("U*")
 98             else
 99                 product["title"] = ""
100             end
101 						# authors
102 						product["authors"] = []
103 						data.scan(/\/fq\w+\/([^"]+)" title="Mehr von\.\.\."><u[^>]*>([^<]+)<\/u>/) do |md|
104 #                next unless CGI.unescape(md[0]) == md[1]
105                 product["authors"] << md[1].unpack("C*").pack("U*")
106             end
107             #raise if product["authors"].empty?
108 						# isbn
109             raise "No isbn" unless md = /<strong>(ISBN-13|EAN|ISBN-13\/EAN):<\/strong>\D*(\d+)<\/li>/.match(data)
110             product["isbn"] = md[2].strip.gsub(/-/, "")
111 						# edition
112             md = /<strong>Einband:<\/strong> ([^<]+)/.match(data)
113             product["edition"] = md[1].strip.unpack("C*").pack("U*") if md != nil
114 						# publisher
115             md = /<strong>Ersch(ienen|eint) +bei:<\/strong>(\&nbsp;| )(<[^>]+>)?([^<]+)/.match(data)
116             product["publisher"] = md[4].strip.unpack("C*").pack("U*").split(/ /).each { |e| e.capitalize! }.join(" ") if md != nil
117 						# publish_year
118             md = /<strong>Ersch(ienen|eint)( voraussichtlich)?:<\/strong> ([^<]+)/.match(data)
119             product["publish_year"] = md[3].strip.unpack("C*").pack("U*")[-4 .. -1].to_i if md != nil
120             product["publish_year"] = nil if product["publish_year"] == 0
121 						# cover
122             if md = /<td valign="top"( nowrap)?>\n<div align="center">\n(<a href="[^>]+>)?<img (id="_artikel_mediumthumbnail" )?src="http:\/\/images\.thalia([^"]+)jpg/.match(data)
123                 product["cover"] = "http://images.thalia" + md[4] + "jpg"
124             else
125                 product["cover"] = nil
126             end
127 
128             book = Book.new(product["title"],
129 						                product["authors"],
130 									  				product["isbn"],
131 														product["publisher"],
132                                                          product["publish_year"],
133 														product["edition"])
134 						return [ book, product["cover"] ]
135         end
136 
137 				def each_book_page(data)
138 				    raise if data.scan(/<a href="#{BASE_URI}(shop\/bde_bu_hg_startseite\/artikeldetails\/[^\.]+\.html)\;jsessionid=[^"]+" title="Details zu diesem Produkt sehen..."><img class="left" width="40" height="60" src="[^"]+" alt="([^"]+)" border="0">/) { |a| yield a }.empty?
139 				end
140     end
141 end
142 end

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

Valid XHTML 1.0! Valid CSS!