Class: Plate

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

Overview

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, extra, quantity, nutr_info) ⇒ Plate

Returns a new instance of Plate.



5
6
7
8
9
10
# File 'lib/Prct07/Plate.rb', line 5

def initialize(name, extra, quantity, nutr_info)
  @Name = name
  @Extra = extra
  @Quantity = check_quantity quantity
  @NutritionalInfo = nutr_info
end

Instance Attribute Details

#ExtraObject (readonly)

Returns the value of attribute Extra.



3
4
5
# File 'lib/Prct07/Plate.rb', line 3

def Extra
  @Extra
end

#NameObject (readonly)

Returns the value of attribute Name.



3
4
5
# File 'lib/Prct07/Plate.rb', line 3

def Name
  @Name
end

#NutritionalInfoObject (readonly)

Returns the value of attribute NutritionalInfo.



3
4
5
# File 'lib/Prct07/Plate.rb', line 3

def NutritionalInfo
  @NutritionalInfo
end

#QuantityObject (readonly)

Returns the value of attribute Quantity.



3
4
5
# File 'lib/Prct07/Plate.rb', line 3

def Quantity
  @Quantity
end

Instance Method Details

#check_quantity(quantity) ⇒ Object

checks if the argument is valid



13
14
15
16
17
18
19
# File 'lib/Prct07/Plate.rb', line 13

def check_quantity(quantity)
  if (quantity > 0)
    quantity
  else
    1
  end
end

#to_sObject

necessary for puts method



22
23
24
# File 'lib/Prct07/Plate.rb', line 22

def to_s
  @Name + ", " + @Extra + ", " + @Quantity.to_s + " g"
end