class Dish

Attributes

foodList[R]
grams[R]
name[R]

Public Class Methods

new(name, foods ,grams) click to toggle source
Calls superclass method
# File lib/Dish.rb, line 14
def initialize(name, foods ,grams)
    super()
    @name = name
    @grams = grams
    @foodList = DobLinkedList.new()
    @foodList.insertMany(foods)

end

Public Instance Methods

energyMean() click to toggle source
# 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
pch() click to toggle source
# 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
plip() click to toggle source
# 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
pprot() click to toggle source
# 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
tcv() click to toggle source
# 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_s() click to toggle source
# 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