2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/to_html_fraction.rb', line 2
def to_html_fraction
body = case self.floor
when -1 then '-'
when 0 then ''
else self.to_i.to_s
end
fraction = case ((self.abs % 1.0) * 16).round.to_f / 16 when 0.0625 then ' 1/16'
when 0.125 then '⅛' when 0.1875 then ' 3/16'
when 0.25 then '¼' when 0.3125 then ' 5/16'
when 0.375 then '⅜' when 0.4375 then ' 7/16'
when 0.5 then '½' when 0.5625 then ' 9/16'
when 0.625 then '⅝' when 0.6875 then ' 11/16'
when 0.75 then '¾' when 0.8125 then ' 13/16'
when 0.875 then '⅞' when 0.9375 then ' 15/16'
else ''
end
body + fraction
end
|