C0 code coverage information
Generated on Tue Dec 04 22:06:27 -0500 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 #####
2 #
3 # Copyright 2007 Chris Strom, Robin Strom
4 #
5 # This file is part of EEE Code.
6 #
7 # EEE Code is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # EEE Code is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with EEE Code. If not, see <http://www.gnu.org/licenses/>.
19 #
20 module RecipesHelper
21 def de_ferret_query(query)
22 Recipe.ferret2web.each do |ferret, web|
23 (query || '').gsub!(Regexp.new("#{ferret}\s*:"), web + ":")
24 end
25 # Recipe.search does this when no query terms are entered, but
26 # sorting it needed
27 if query == "number_of_ingredients:( >= 000)"
28 query = ""
29 end
30 query
31 end
32
33 def re_ferret_query(query)
34 q = ' '+query
35 Recipe.ferret2web.sort{|a,b| b[0].length <=> a[0].length}.each do |ferret, web|
36 (q || '').gsub!(Regexp.new("\\b#{web}\\s*:"), ferret + ":")
37 end
38 q.lstrip
39 end
40
41 def sort_fields
42 %w|title date prep_time number_of_ingredients|
43 end
44
45 def default_direction_for(field)
46 field == 'date' ? 'desc' : 'asc'
47 end
48
49 def ferret_field(web)
50 web2ferret = Hash[*Recipe.ferret2web.flatten].invert
51 ff = web2ferret[web] || web
52 ff == 'title' ? 'title_for_sort' : ff
53 end
54
55 def ferret_sort(field, direction)
56 return nil if field.nil?
57 return nil if !sort_fields.include?(field)
58 direction ||= default_direction_for(field)
59 Ferret::Search::SortField.new(ferret_field(field), :reverse => direction == 'desc')
60 end
61
62 def link_to_sort(name, field, query, sort=nil)
63 options = {:action => 'search', :query => query, :sort => field}
64 if sort && sort.name.to_s == ferret_field(field)
65 options[:dir] = sort.reverse? ? 'asc' : 'desc'
66 image = image_tag(sort.reverse? ? "down.gif" : "up.gif",
67 :title => "Shown in " + (sort.reverse? ? "desc" : "asc") + "ending order (click to reverse)",
68 :size => "13x13",
69 :style => 'border: 0px; margin-left: 5px; vertical-align: middle;')
70 end
71 link_to(name, options) + image.to_s
72 end
73 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.