Class: Fraction

Inherits:
Object
  • Object
show all
Defined in:
lib/fraction.rb,
ext/fraction/fraction.c

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#denominatorObject (readonly)

Returns the value of attribute denominator.



4
5
6
# File 'lib/fraction.rb', line 4

def denominator
  @denominator
end

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/fraction.rb', line 4

def error
  @error
end

#numeratorObject (readonly)

Returns the value of attribute numerator.



4
5
6
# File 'lib/fraction.rb', line 4

def numerator
  @numerator
end

Instance Method Details

#to_htmlObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fraction.rb', line 6

def to_html
  entity = case self.numerator

  when 1 then
    case self.denominator
    when 2 then "½"
    when 3 then "⅓"
    when 4 then "¼"
    when 5 then "⅕"
    when 6 then "⅙"
    when 8 then "⅛"
    end

  when 2 then
    case self.denominator
    when 3 then "⅔"
    when 5 then "⅖"
    end

  when 3 then
    case self.denominator
    when 4 then "¾"
    when 5 then "⅗"
    when 8 then "⅜"
    end

  when 4 then "⅘"

  when 5 then
    case self.denominator
    when 6 then "⅚"
    when 8 then "⅝"
    end
    
  when 7 then "⅞"
  end

  entity ||= "#{self.numerator}/#{self.denominator}"
  entity
end