Class: Menu

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/menu.rb

Direct Known Subclasses

MenuAges, MenuFoodGroups

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a = [], b = [], c = [], d = [], e = [], &block) ⇒ Menu

Creates a new diet Menu.

Parameters:

  • a (defaults to: [])

    the menu title

  • b (defaults to: [])

    the menu percentage

  • c (defaults to: [])

    the menu calories

  • d (defaults to: [])

    the menu plates

  • e (defaults to: [])

    the menu cvt



12
13
14
15
16
17
18
19
20
# File 'lib/menu.rb', line 12

def initialize (a=[],b=[],c=[],d=[],e=[], &block)
    
    @title, @percentage, @cal = a, b, d  
    @menu= c
    @cvt= e
    if(block_given?)
        instance_eval(&block)
    end
end

Instance Attribute Details

#calObject (readonly)

Returns the value of attribute cal.



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

def cal
  @cal
end

#cvtObject (readonly)

Returns the value of attribute cvt.



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

def cvt
  @cvt
end

Returns the value of attribute menu.



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

def menu
  @menu
end

#percentageObject (readonly)

Returns the value of attribute percentage.



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

def percentage
  @percentage
end

#titleObject (readonly)

Returns the value of attribute title.



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

def title
  @title
end

Instance Method Details

#<=>(anOther) ⇒ Object

Menus comparable function.

Returns:

  • true or false depending of the operator.



103
104
105
# File 'lib/menu.rb', line 103

def <=>(anOther)
    to_s.length <=> anOther.to_s.length
end

Returns the menu’s footer to string.

Returns:

  • the menu’s footer to string.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/menu.rb', line 53

def footer_to_s
    out = "V.C.T.|       "
    out << @cal
    out << "|"
    i=0
    @cvt.each do
        out << "#{@cvt[i]}"
        out << "-"
    i+=1
    end
    out = out.chop
    out
end

#head(op) ⇒ Object



108
109
110
111
# File 'lib/menu.rb', line 108

def head(op)
  @title = "#{op[:title]}"
  @percentage = "#{op[:percentage]}"
end

Returns the menu’s plates to string.

Returns:

  • the menu’s plates to string.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/menu.rb', line 35

def menu_to_s
    
    
    i=0
    out = ""
    @menu.each do
        out << "- "
        out << "#{@menu[i]}"
        out << "\n"
        i+=1
        
    end
    out
end

#nutritionfact(op) ⇒ Object



116
117
118
119
# File 'lib/menu.rb', line 116

def nutritionfact(op)
  @cvt = op[:cvt]
  @cal = op[:cal]
end

#plate(op) ⇒ Object



112
113
114
# File 'lib/menu.rb', line 112

def plate(op)
  @menu =  op[:menu]
end

#title_to_sObject

Returns the menu’s title to string.

Returns:

  • the menu’s title to stringr.



24
25
26
27
28
29
30
# File 'lib/menu.rb', line 24

def title_to_s
    out = @title
    out <<  " ("
    out << @percentage
    out << ")"
    out
end

#to_sObject

Returns the menu to string.

Returns:

  • the menu to string.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/menu.rb', line 70

def to_s
    
    out = @title
    out <<  " ("
    out << @percentage
    out << ")\n"
    
    i=0
    @menu.each do
        out << "- "
        out << "#{@menu[i]}"
        out << "\n"
        i+=1
        
    end
    
    out << "V.C.T.|       "
    out << @cal
    out << "|"
    i=0
    @cvt.each do
        out << "#{@cvt[i]}"
        out << "-"
    i+=1
    end
    out = out.chop
    out
    
end