C0 code coverage information
Generated on Tue Dec 04 22:06:26 -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
21 # Methods added to this helper will be available to all templates in the application.
22 module ApplicationHelper
23
24 def decimal_as_fraction(f)
25 i = f.floor.to_i
26 frac = f - i
27 frac_html = fraction_lookup(frac)
28 if frac_html
29 ((i == 0) ? '' : i.to_s + '') + frac_html
30 elsif frac == 0.0
31 i.to_s
32 else
33 f.to_s # + '(' + i.to_s + ' ' +frac.to_s + ')'
34 end
35 end
36
37 def fraction_lookup(frac)
38 case frac
39 when 0.125
40 pretty_fraction(1, 8)
41 when 0.167
42 pretty_fraction(1, 6)
43 when 0.25
44 pretty_fraction(1, 4)
45 when 0.333, 0.33
46 pretty_fraction(1, 3)
47 when 0.375
48 pretty_fraction(3, 8)
49 when 0.5
50 pretty_fraction(1, 2)
51 when 0.625
52 pretty_fraction(5, 8)
53 when 0.667, 0.67, 0.66
54 pretty_fraction(2, 3)
55 when 0.75
56 pretty_fraction(3, 4)
57 when 0.8335
58 pretty_fraction(5, 6)
59 when 0.875
60 pretty_fraction(7, 8)
61 end
62 end
63
64 def pretty_fraction(numerator, denominator)
65 %Q|<span class="fraction"><sup>#{numerator}</sup>⁄<sub>#{denominator}</sub></span>|
66 end
67
68 def wikify_recipe_links(text)
69 return nil if text.nil?
70
71 t = text.dup
72 t.gsub!(/\[recipe:(\S+)\s+([^\]]+)\]/m, link_to("\\2", '/recipes/\1'))
73 t.gsub!(/\[recipe:([^\]]+)\]/m) do |recipe_wiki|
74 recipe = Recipe.find_by_uri($1)
75 if recipe.nil?
76 logger.error("Invalid recipe link: #{$1}")
77 ''
78 else
79 link_to(recipe.title, '/recipes/' + $1)
80 end
81 end
82 t.gsub!(/\[howto:([^\]]+)\]/m) do |howto_wiki|
83 recipe = Recipe.find_howto($1)
84 if recipe.nil?
85 logger.error("Invalid howto: #{$1}")
86 ''
87 else
88 "see: " + link_to(recipe.title, '/recipes/' + recipe.uri)
89 end
90 end
91 t
92 end
93
94 def wikify(text)
95 return nil if text.nil?
96
97 t = wikify_recipe_links(text)
98 t.gsub!(/\[meal:(\S+)\s+([^\]]+)\]/m, link_to("\\2", '/meals/\1'))
99 t.gsub!(/\[kid:(\w+)\]/m) { |kid| ::Kid.nicknames[$1] }
100 t.gsub!(/(\d+)([FC])/, "\\1° \\2")
101 t
102 end
103
104 def wiki(text)
105 return nil if text.blank?
106 textilize(wikify(text))
107 end
108
109 def wiki_without_paragraph(text)
110 return nil if text.blank?
111 wikify(textilize_without_paragraph('xxx '+text)[4..-1])
112 end
113 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.0.