Class: Food

Inherits:
FoodAbstract show all
Includes:
Comparable
Defined in:
lib/food/food_class.rb

Overview

Class for Food that inherit FoodAbstract

Instance Attribute Summary collapse

Attributes inherited from FoodAbstract

#energetic_content, #glucid_quantity, #lipid_quantity, #name, #protein_quantity

Instance Method Summary collapse

Methods inherited from FoodAbstract

#calculate_energetic_content

Constructor Details

#initialize(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name) ⇒ Food

Constructor of Food with the group name

Parameters:

  • name (String)

    the name for the food.

  • protein_energy_pair (pair)

    pair of protein number and energy.

  • glucid_energy_pair (pair)

    pair of glucid number and energy

  • lipid_energy_pair (pair)

    pair of lipid number and energy

  • group_name (String)

    the name for the food group.



77
78
79
80
# File 'lib/food/food_class.rb', line 77

def initialize(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair, group_name)
  @group_name = group_name
  super(name, protein_energy_pair, glucid_energy_pair, lipid_energy_pair)
end

Instance Attribute Details

#group_nameObject (readonly)



69
70
71
# File 'lib/food/food_class.rb', line 69

def group_name
  @group_name
end

Instance Method Details

#<=>(food) ⇒ String

Essential comparating for using Comparable Module

Returns:

  • (String)

    Return which food is higher depending on the enrgetic content



90
91
92
93
# File 'lib/food/food_class.rb', line 90

def <=> (food)
  raise unless food.is_a?Food
  return self.energetic_content <=> food.energetic_content
end

#to_sString

Return string with the output for the food calling the father

Returns:

  • (String)

    output of food



84
85
86
# File 'lib/food/food_class.rb', line 84

def to_s
  "Grupo: #{@group_name} | " + super
end