Class: Alimento
- Inherits:
-
Object
- Object
- Alimento
- Defined in:
- lib/P06/alimento.rb
Overview
Esta clase permite representar la información básica de un alimento dado, sus proteinas, glúcidos y lípidos además, calcula el índice calórico del mismo.
- Author
-
Alberto González (alu0100949568@ull.edu.es)
- Copyright
-
Cretive Commons
- License
-
Distributes under the same terms as Ruby
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cal_index ⇒ Object
readonly
Returns the value of attribute cal_index.
-
#gluc ⇒ Object
readonly
Returns the value of attribute gluc.
-
#lip ⇒ Object
readonly
Returns the value of attribute lip.
-
#nom ⇒ Object
readonly
Returns the value of attribute nom.
-
#prot ⇒ Object
readonly
Returns the value of attribute prot.
Instance Method Summary collapse
-
#initialize(nom, prot, gluc, lip) ⇒ Alimento
constructor
Se asigna el nombre y la información nutricional del alimento.
-
#to_s ⇒ Object
Muestra la información de un alimento en concreto.
Constructor Details
#initialize(nom, prot, gluc, lip) ⇒ Alimento
Se asigna el nombre y la información nutricional del alimento
12 13 14 15 16 17 18 |
# File 'lib/P06/alimento.rb', line 12 def initialize(nom, prot, gluc, lip) @nom = nom @prot = prot @gluc = gluc @lip = lip @cal_index = (@prot.to_f*4 + @gluc.to_f*4 + @lip.to_f*9).round(2) end |
Instance Attribute Details
#cal_index ⇒ Object (readonly)
Returns the value of attribute cal_index
9 10 11 |
# File 'lib/P06/alimento.rb', line 9 def cal_index @cal_index end |
#gluc ⇒ Object (readonly)
Returns the value of attribute gluc
9 10 11 |
# File 'lib/P06/alimento.rb', line 9 def gluc @gluc end |
#lip ⇒ Object (readonly)
Returns the value of attribute lip
9 10 11 |
# File 'lib/P06/alimento.rb', line 9 def lip @lip end |
#nom ⇒ Object (readonly)
Returns the value of attribute nom
9 10 11 |
# File 'lib/P06/alimento.rb', line 9 def nom @nom end |
#prot ⇒ Object (readonly)
Returns the value of attribute prot
9 10 11 |
# File 'lib/P06/alimento.rb', line 9 def prot @prot end |
Instance Method Details
#to_s ⇒ Object
Muestra la información de un alimento en concreto
21 22 23 24 |
# File 'lib/P06/alimento.rb', line 21 def to_s #El huevo frito tiene 14.1 proteinas, 0.0 glúcidos, 19.5 lípidos " #{@nom}: #{@prot} proteinas, #{@gluc} glúcidos, #{@lip} lípidos, #{@cal_index} calorías" end |