Class: Dish

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

Direct Known Subclasses

DishImpact

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, foods, grams) ⇒ Dish

Returns a new instance of Dish.



14
15
16
17
18
19
20
21
# File 'lib/Dish.rb', line 14

def initialize(name, foods ,grams)
    super()
    @name = name
    @grams = grams
    @foodList = DobLinkedList.new()
    @foodList.insertMany(foods)

end

Instance Attribute Details

#foodListObject (readonly)

Returns the value of attribute foodList.



12
13
14
# File 'lib/Dish.rb', line 12

def foodList
  @foodList
end

#gramsObject (readonly)

Returns the value of attribute grams.



12
13
14
# File 'lib/Dish.rb', line 12

def grams
  @grams
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/Dish.rb', line 12

def name
  @name
end

Instance Method Details

#energyMeanObject



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/Dish.rb', line 97

def energyMean

current = @foodList.head
total = 0 
count = 0  
while current
    total += (current.value.n_value )
    count += 1
    current = current.next
end
total    end

#pchObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/Dish.rb', line 68

def pch
    current = @foodList.head
    totalgrams = 0 
    totalch = 0
    count = 0
    #@grams.each { |i| totalgrams += i }
    
    while current
        totalch += (current.value.ch_g * @grams[count])
        totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
        count += 1
        current = current.next
    end
    pch= (totalch*100)/totalgrams
    pch
end

#plipObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/Dish.rb', line 50

def plip
    current = @foodList.head
    totalgrams = 0 
    totallip = 0
    count = 0
    #@grams.each { |i| totalgrams += i }
    
    while current
        totallip += (current.value.lp_g * @grams[count])
        totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
        count += 1
        
        current = current.next
    end
    plip= (totallip*100)/totalgrams
    plip
end

#pprotObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/Dish.rb', line 32

def pprot
    current = @foodList.head
    totalgrams = 0 
    totalprot = 0
    count = 0
    #@grams.each { |i| totalgrams += i }
    
    while current
        totalprot += (current.value.pr_g * @grams[count])
        totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
        count += 1
        
        current = current.next
    end
    pprot = (totalprot*100)/totalgrams
    pprot
end

#tcvObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/Dish.rb', line 85

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

#to_sObject



23
24
25
26
27
28
# File 'lib/Dish.rb', line 23

def to_s
    s = "( #{name} :"
    food_arr = @foodList.collect { |i| i.value.name }
    food_arr.each_with_index { |name, i| s <<" |#{name}| x #{@grams[i]} g " }
    s << ": )"
end