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.
1 # Copyright (C) 2005-2006-2006 Mathieu Leduc-Hamel
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 # http://en.wikipedia.org/wiki/Renaud-Bray
19
20 require 'net/http'
21 require 'cgi'
22
23 module Alexandria
24 class BookProviders
25 class RENAUDProvider < GenericProvider
26 include GetText
27 #GetText.bindtextdomain(Alexandria::TEXTDOMAIN, nil, nil, "UTF-8")
28 BASE_URI = "http://www.renaud-bray.com/"
29 ACCENTUATED_CHARS = "áàâäçéèêëíìîïóòôöúùûü"
30
31 def initialize
32 super("RENAUD", "Renaud-Bray (Canada)")
33 end
34
35 def search(criterion, type)
36 criterion = criterion.convert("ISO-8859-1", "UTF-8")
37 req = BASE_URI + "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri="
38 # req = BASE_URI + "francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri="
39 req += case type
40 when SEARCH_BY_ISBN
41 "ISBN"
42 when SEARCH_BY_TITLE
43 "Titre"
44 when SEARCH_BY_AUTHORS
45 "Auteur"
46 when SEARCH_BY_KEYWORD
47 ""
48 else
49 raise InvalidSearchTypeError
50 end
51 req += "&Phrase="
52
53 req += CGI.escape(criterion)
54 p req if $DEBUG
55 data = transport.get(URI.parse(req))
56 begin
57 if type == SEARCH_BY_ISBN
58 return to_books(data).pop()
59 else
60 results = []
61 to_books(data).each{|book|
62 results << book
63 }
64 while /Suivant/.match(data)
65 md = /Enteterouge\">([\d]*)<\/b>/.match(data)
66 num = md[1].to_i+1
67 data = transport.get(URI.parse(req+"&PageActuelle="+num.to_s))
68 to_books(data).each{|book|
69 results << book
70 }
71 end
72 return results
73 end
74 rescue
75 raise NoResultsError
76 end
77 end
78
79 def url(book)
80 # "http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_section_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=" + book.isbn
81 "http://www.renaud-bray.com/francais/menu/gabarit.asp?Rubrique=&Recherche=&Entete=Livre&Page=Recherche_wsc.asp&OnlyAvailable=false&Tri=ISBN&Phrase=" + book.isbn
82 end
83
84 #######
85 private
86 #######
87
88 def to_books(data)
89 data = CGI::unescapeHTML(data)
90 data = data.convert("UTF-8", "ISO-8859-1")
91 raise NoResultsError if /<strong class="Promotion">Aucun article trouv. selon les crit.res demand.s<\/strong>/.match(data) != nil
92
93 titles = []
94 data.scan(/"(Jeune|Lire)Hyperlien" href.*><strong>([-,'\(\)&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/strong><\/a><br>/).each{|md|
95 titles << md[1].strip
96 }
97 raise if titles.empty?
98 authors = []
99 data.scan(/Nom_Auteur.*><i>([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/i>/).each{|md|
100 authors2 = []
101 for author in md[0].split(' ')
102 authors2 << author.strip
103 end
104 authors << authors2
105 }
106 raise if authors.empty?
107 isbns = []
108 data.scan(/ISBN : ?<\/td><td>(\d+)/).each{|md|
109 isbns << md[0].strip
110 }
111 raise if isbns.empty?
112 editions = []
113 publish_years = []
114 data.scan(/Parution : <br>(\d{4,}-\d{2,}-\d{2,})/).each{|md|
115 editions << md[0].strip
116 publish_years << md[0].strip.split(/-/)[0].to_i
117 }
118 raise if editions.empty? or publish_years.empty?
119 publishers = []
120 data.scan(/diteur : ([,'.&\#;\w\s#{ACCENTUATED_CHARS}]*)<\/span><br>/).each{|md|
121 publishers << md[0].strip
122 }
123 raise if publishers.empty?
124 book_covers = []
125 data.scan(/(\/ImagesEditeurs\/[\d]*\/([\dX]*-f.(jpg|gif))|\/francais\/suggestion\/images\/livre\/livre.gif)/).each{|md|
126 book_covers << BASE_URI + md[0].strip
127 }
128 raise if book_covers.empty?
129
130 books = []
131 titles.each_with_index{|title, i|
132 books << [Book.new(title, authors[i], isbns[i], publishers[i], publish_years[i], editions[i]),
133 book_covers[i]]
134 #print books
135 }
136 raise if books.empty?
137
138 return books
139 end
140
141 end
142 end
143 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.