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/ls.rb 131 83
32.1% 
15.7% 
  1 # Copyright (C) 2004 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 # Adapted code from 'bn.rb' (I hope that it works!)
 20 
 21 require 'net/http'
 22 require 'cgi'
 23 
 24 module Alexandria
 25 class BookProviders
 26     class SicilianoProvider < GenericProvider
 27     
 28         BASE_URI = "http://www.siciliano.com.br"
 29         LOCALE = "livro" # possible locales are: "livro", "importado"
 30         def initialize
 31             super("LS", "Livraria Siciliano (Brasil)")
 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 + "/#{LOCALE}.asp?tipo=10&pesquisa=" 
 38             req += case type
 39                 when SEARCH_BY_ISBN
 40                     "5&id="
 41 
 42                 when SEARCH_BY_TITLE
 43                     "1&id="
 44 
 45                 when SEARCH_BY_AUTHORS
 46                     "3&id="
 47 
 48                 when SEARCH_BY_KEYWORD
 49                     "&id=" # does the site provide this?
 50 
 51                 else
 52                     raise InvalidSearchTypeError
 53 
 54             end
 55 
 56             criterion = Library.canonicalise_isbn(criterion) if type == SEARCH_BY_ISBN
 57             req += CGI.escape(criterion)
 58             p req if $DEBUG
 59             data = transport.get(URI.parse(req))
 60 
 61             if type == SEARCH_BY_ISBN
 62                 book = to_book(data)
 63             else
 64                 begin
 65                     results = [] 
 66                     each_book_page(data) do |code, title|
 67                         results << to_book(transport.get(URI.parse(BASE_URI + "/#{LOCALE}.asp?orn=LSE&Tipo=2&ID=" + code)))
 68                     end
 69                     return results 
 70                 rescue
 71                     raise NoResultsError
 72                 end
 73             end
 74         end
 75 
 76         def url(book)
 77 	    "http://www.siciliano.com.br/#{LOCALE}.asp?tipo=10&pesquisa=5&id=" +  Library.canonicalise_isbn(book.isbn)
 78         end
 79 
 80         #######
 81         private
 82         #######
 83     
 84         def to_book(data)
 85             data = data.convert("UTF-8", "ISO-8859-1")
 86             raise NoResultsError if /<strong>Nenhum t.tulo foi encontrado\.<BR>/.match(data) != nil
 87 
 88             raise "No Title" unless md = /><strong(\s+class="titulodetalhes")?>([^<]+)<\/strong>(<\/a>)?<br ?\/>/.match(data)
 89             title = md[2].strip
 90 
 91             authors = []
 92             if md =/<strong class="(azulescuro|autordetalhes)">(.*)<\/strong><br ?\/><br ?\/>/.match(data)
 93                 md[2].strip.split(', ').each { |a| authors << CGI.unescape(a.strip) }
 94             end
 95 
 96             raise "No ISBN from Image" unless md = /<img src="capas\/([\dX]+)p?\.jpg" alt="" ?\/>/.match(data)
 97             isbn = Library.canonicalise_ean(md[1].strip)
 98 
 99             if md = /<br[^>]*>Editora: ([^<]+)<br>/.match(data)
100                 publisher = md[1].strip
101             else
102                 publisher = nil
103             end
104 
105             if md = /<br[^>]*>Encaderna..o: ([^<]+)<br>/.match(data)
106                 edition = md[1].strip
107             else
108                 edition = nil
109             end
110 
111             if md = /<br[^>]*>Edi..o: ([^<]+)<br>/.match(data)
112                 publish_year = md[1].strip.to_i
113             else
114                 publish_year = nil
115             end
116 
117             medium_cover = BASE_URI+'/capas/'+ Library.canonicalise_isbn(isbn) + 'p.jpg' # use + '.jpg' for bigger images
118             #raise "No Big Image" unless medium_cover = transport.get(URI.parse(BASE_URI+'/capas/'+ isbn + '.jpg'))
119             #raise "No Big Image" unless md = /<img src="capas\/(.+\/(\d+)p\.gif)" alt=""\/>/.match(data)
120             #medium_cover = md[1]
121             #small_cover = md[1]
122             return [ Book.new(title, authors, isbn, publisher, publish_year, edition), 
123                      medium_cover ]
124         end
125     
126         def each_book_page(data)
127             raise if data.scan(/<a href='#{LOCALE}.asp\?orn=LSE&Tipo=2&ID=(\d+)'><strong>/) { |a| yield a }.empty?
128         end
129     end
130 end
131 end

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

Valid XHTML 1.0! Valid CSS!