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/bn.rb 126 81
32.5% 
14.8% 
  1 # Copyright (C) 2004-2006 Laurent Sansonetti
  2 # Copyright (C) 2007 Laurent Sansonetti 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://en.wikipedia.org/wiki/Barnes_&_Noble
 20 
 21 require 'net/http'
 22 require 'cgi'
 23 
 24 module Alexandria
 25 class BookProviders
 26     class BNProvider < GenericProvider
 27     
 28         BASE_URI = "http://search.barnesandnoble.com/"
 29         def initialize
 30             super("BN", "Barnes and Noble (Usa)")
 31             # no preferences for the moment
 32         end
 33         
 34         def search(criterion, type)
 35             criterion = criterion.convert("ISO-8859-1", "UTF-8")
 36             req = BASE_URI + "booksearch/"
 37             req += case type
 38                 when SEARCH_BY_ISBN
 39                     "isbninquiry.asp?ISBN="
 40 
 41                 when SEARCH_BY_TITLE
 42                     "results.asp?TTL="
 43 
 44                 when SEARCH_BY_AUTHORS
 45                     "results.asp?ATH="
 46 
 47                 when SEARCH_BY_KEYWORD
 48                     "results.asp?WRD="
 49 
 50                 else
 51                     raise InvalidSearchTypeError
 52 
 53             end
 54 
 55             req += CGI.escape(criterion)
 56             puts req if $DEBUG
 57             data = transport.get(URI.parse(req))
 58             if type == SEARCH_BY_ISBN
 59                 to_book(data) rescue raise NoResultsError
 60             else
 61                 begin
 62                     results = [] 
 63                     each_book_page(data) do |page, title|
 64                         results << to_book(transport.get(URI.parse(BASE_URI + page)))
 65                     end
 66                     return results 
 67                 rescue
 68                     raise NoResultsError
 69                 end
 70             end
 71         end
 72 
 73         def url(book)
 74             "http://search.barnesandnoble.com/booksearch/isbninquiry.asp?ISBN=" + book.isbn
 75         end
 76 
 77         #######
 78         private
 79         #######
 80     
 81         def to_book(data)
 82             raise NoResultsError if /<body><h1>Object Moved<\/h1>This object may be found <a HREF="http:\/\/www.barnesandnoble.com\/booksearch\/noresults.asp/.match(data) != nil
 83             data = data.convert("UTF-8", "ISO-8859-1")
 84 
 85             raise "No title" unless md = /Barnes&nbsp;&amp;&nbsp;Noble.com - Books: ([^<]+)/.match(data)
 86             title = md[1].strip
 87 
 88             authors = []
 89             data.scan(/<a href="\/booksearch\/results.asp\?ATH\=([^"]+)\&amp;z=y">\s*([^<]+)/) do |md|
 90                 md[1].gsub!('&nbsp;',' ')
 91                 next unless CGI.unescape(md[0]) == md[1]
 92                 authors << md[1]
 93             end
 94 
 95             raise "No ISBN" unless md = /ISBN-13:\s+<a style="text-decoration:none">([^<]+)/.match(data)
 96             isbn = md[1].strip
 97 
 98             #raise unless 
 99             md = /<li class="publisher">Publisher:\s+([^<]+)/.match(data)
100             publisher = md[1].strip or md
101 
102             #raise unless 
103             md = /<li class="format">Format:\s+([^<]+)/.match(data)
104             edition = md[1].strip or md
105 
106             publish_year = nil
107             if md = /<li class="pubDate">Pub. Date:[^<]+(\d\d\d\d)</.match(data)
108                 publish_year = md[1].to_i
109                 publish_year = nil if publish_year == 0
110             end
111 
112           if md = /<IMG SRC="(.+\/(\d+|ImageNA_product).gif)" ALT=("Book Cover"|"Image Not Available") WIDTH="\d+" HEIGHT="\d+" BORDER="0">/.match(data)
113             medium_cover = md[1]
114             small_cover = medium_cover.sub(/#{md[2]}/, (md[2].to_i - 1).to_s)
115             return [ Book.new(title, authors, isbn, publisher, publish_year, 
116                      edition), medium_cover ]
117           else return [ Book.new(title, authors, isbn, publisher, publish_year, edition) ]
118           end
119         end
120     
121         def each_book_page(data)
122             raise if data.scan(/<A href="(\/booksearch\/isbnInquiry.asp\?userid=[\w\d]+&isbn=[^"]+)">([^<]+)<\/A>/) { |a| yield a }.empty?
123         end
124     end
125 end
126 end

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

Valid XHTML 1.0! Valid CSS!