Class: DishImpact

Inherits:
Dish
  • Object
show all
Includes:
Comparable
Defined in:
lib/DishImpact.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Dish

#energyMean, #pch, #plip, #pprot, #tcv

Constructor Details

#initialize(name, foods, grams) ⇒ DishImpact

Returns a new instance of DishImpact.



15
16
17
18
# File 'lib/DishImpact.rb', line 15

def initialize(name, foods ,grams)
    super(name, foods ,grams)
    nutritional_footprints
end

Instance Attribute Details

#e_fpObject (readonly)

Returns the value of attribute e_fp.



13
14
15
# File 'lib/DishImpact.rb', line 13

def e_fp
  @e_fp
end

#foodListObject (readonly)

Returns the value of attribute foodList.



13
14
15
# File 'lib/DishImpact.rb', line 13

def foodList
  @foodList
end

#gramsObject (readonly)

Returns the value of attribute grams.



13
14
15
# File 'lib/DishImpact.rb', line 13

def grams
  @grams
end

#n_fpObject (readonly)

Returns the value of attribute n_fp.



13
14
15
# File 'lib/DishImpact.rb', line 13

def n_fp
  @n_fp
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/DishImpact.rb', line 13

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



80
81
82
83
84
# File 'lib/DishImpact.rb', line 80

def <=>(other)
    return nil unless other.instance_of? DishImpact
    
    terrainTotal + dailygei <=> other.terrainTotal + other.dailygei
end

#dailygeiObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/DishImpact.rb', line 19

def dailygei
    current = @foodList.head
    total = 0 
    count = 0  
    while current
        total += (current.value.gei * @grams[count])
        count += 1
        current = current.next
    end
    total
end

#geiMeanObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/DishImpact.rb', line 42

def geiMean
    current = @foodList.head
    total = 0 
    count = 0  
    while current
        total += (current.value.gei * @grams[count])
        count += 1
        current = current.next
    end
    total/foodList.length
end

#nutritional_footprintsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/DishImpact.rb', line 55

def nutritional_footprints
    @n_fp = 0
        if energyMean < 670 then 
            @n_fp = 1 
        elsif energyMean > 830 then 
            @n_fp = 3 
        else 
            @n_fp = 2 
        end
    
    @e_fp = 0 
        if dailygei < 800 then 
            @e_fp = 1 
        elsif dailygei > 1200 then 
            @e_fp = 3 
        else 
            @e_fp = 2 
        end
    
end

#terrainTotalObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/DishImpact.rb', line 30

def terrainTotal
    current = @foodList.head
    total = 0 
    count = 0  
    while current
        total += (current.value.terrain * @grams[count])
        count += 1
        current = current.next
    end
    total
end

#to_sObject



76
77
78
# File 'lib/DishImpact.rb', line 76

def to_s
    "(: #{@name} : gei [#{dailygei}] | terrain [#{terrainTotal}] :)"
end