class Alimento
Class Alimento
Stores a food and some values of its elements.
Attributes
glucids[R]
lipids[R]
name[R]
proteins[R]
Public Class Methods
new(name, proteins, glucids, lipids)
click to toggle source
Initialization of the object given its attributes @param name [String] Name of the Alimento
@param proteins [Fixnum] Proteins ammount of the Alimento
@param glucids [Fixnum] Glucids ammount of the Alimento
@param lipids [Fixnum] Lipids ammount of the Alimento
# File lib/nutrientes/alimento.rb, line 55 def initialize (name, proteins, glucids, lipids) @name = name @proteins = proteins @glucids = glucids @lipids = lipids end
Public Instance Methods
<=>(another)
click to toggle source
Method to implement the comparison between two Alimentos @param another [Object] Object to compare with @return [Fixnum] 1 if the first object is bigger, 0 if equal and -1 if minor
# File lib/nutrientes/alimento.rb, line 18 def <=>(another) if(another.caloric_value > caloric_value) return -1 else if(another.caloric_value < caloric_value) return 1 end if (another.proteins > proteins) return -1 else if(another.proteins < proteins) return 1 end if(another.glucids > glucids) return -1 else if(another.glucids < glucids) return 1 end if(another.lipids > lipids) return -1 else if(another.lipids < lipids) return 1 else return 0 end end end end end end
caloric_value()
click to toggle source
Calculates the caloric value of the Alimento
@return [Fixnum] The caloric value
# File lib/nutrientes/alimento.rb, line 70 def caloric_value() return (@proteins * 4 + @lipids * 9 + @glucids * 4) end
to_s()
click to toggle source
Method to transform an object of Alimento
to a string @return [String] the object as a string
# File lib/nutrientes/alimento.rb, line 64 def to_s() return String.new(@name + ", " + @proteins.to_s + "g proteins, " + @glucids.to_s + "g glucids, " + @lipids.to_s + "g lipids") end