Class: Menu
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cal ⇒ Object
readonly
Returns the value of attribute cal.
-
#cvt ⇒ Object
readonly
Returns the value of attribute cvt.
-
#menu ⇒ Object
readonly
Returns the value of attribute menu.
-
#percentage ⇒ Object
readonly
Returns the value of attribute percentage.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#<=>(anOther) ⇒ Object
Menus comparable function.
-
#footer_to_s ⇒ Object
Returns the menu’s footer to string.
- #head(op) ⇒ Object
-
#initialize(a = [], b = [], c = [], d = [], e = [], &block) ⇒ Menu
constructor
Creates a new diet Menu.
-
#menu_to_s ⇒ Object
Returns the menu’s plates to string.
- #nutritionfact(op) ⇒ Object
- #plate(op) ⇒ Object
-
#title_to_s ⇒ Object
Returns the menu’s title to string.
-
#to_s ⇒ Object
Returns the menu to string.
Constructor Details
#initialize(a = [], b = [], c = [], d = [], e = [], &block) ⇒ Menu
Creates a new diet Menu.
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
#cal ⇒ Object (readonly)
Returns the value of attribute cal.
3 4 5 |
# File 'lib/menu.rb', line 3 def cal @cal end |
#cvt ⇒ Object (readonly)
Returns the value of attribute cvt.
3 4 5 |
# File 'lib/menu.rb', line 3 def cvt @cvt end |
#menu ⇒ Object (readonly)
Returns the value of attribute menu.
3 4 5 |
# File 'lib/menu.rb', line 3 def @menu end |
#percentage ⇒ Object (readonly)
Returns the value of attribute percentage.
3 4 5 |
# File 'lib/menu.rb', line 3 def percentage @percentage end |
#title ⇒ Object (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.
103 104 105 |
# File 'lib/menu.rb', line 103 def <=>(anOther) to_s.length <=> anOther.to_s.length end |
#footer_to_s ⇒ Object
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 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 |
#menu_to_s ⇒ Object
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 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_s ⇒ Object
Returns the menu’s title to string.
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_s ⇒ Object
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 |