Class: MenuDSL
- Inherits:
-
Object
- Object
- MenuDSL
- Defined in:
- lib/menu/menudsl.rb
Instance Attribute Summary collapse
-
#ingest ⇒ Object
Returns the value of attribute ingest.
-
#name ⇒ Object
Returns the value of attribute name.
-
#plato ⇒ Object
Returns the value of attribute plato.
-
#porcent ⇒ Object
Returns the value of attribute porcent.
-
#titul ⇒ Object
Returns the value of attribute titul.
Instance Method Summary collapse
- #ingesta(text, options = {}) ⇒ Object
-
#initialize(name, &block) ⇒ MenuDSL
constructor
A new instance of MenuDSL.
- #platos(text, options = {}) ⇒ Object
- #porcentajes(text, options = {}) ⇒ Object
- #titulo(text, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ MenuDSL
Returns a new instance of MenuDSL.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/menu/menudsl.rb', line 5 def initialize(name,&block) self.name = name self.titul = [] self.ingest = [] self.plato = [] self.porcent = [] if block_given? if block.arity == 1 yield self else instance_eval &block end end end |
Instance Attribute Details
#ingest ⇒ Object
Returns the value of attribute ingest.
3 4 5 |
# File 'lib/menu/menudsl.rb', line 3 def ingest @ingest end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/menu/menudsl.rb', line 3 def name @name end |
#plato ⇒ Object
Returns the value of attribute plato.
3 4 5 |
# File 'lib/menu/menudsl.rb', line 3 def plato @plato end |
#porcent ⇒ Object
Returns the value of attribute porcent.
3 4 5 |
# File 'lib/menu/menudsl.rb', line 3 def porcent @porcent end |
#titul ⇒ Object
Returns the value of attribute titul.
3 4 5 |
# File 'lib/menu/menudsl.rb', line 3 def titul @titul end |
Instance Method Details
#ingesta(text, options = {}) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/menu/menudsl.rb', line 63 def ingesta(text, = {}) ing = text ing << "#{[:min]} -" if [:min] ing << " #{[:max]} %" if [:max] ingest << ing end |
#platos(text, options = {}) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/menu/menudsl.rb', line 71 def platos(text, = {}) plat = text plat << "#{[:description]}, " if [:description] plat << "#{[:porcion]}, " if [:porcion] plat << "#{[:gramos]}" if [:gramos] plato << plat end |
#porcentajes(text, options = {}) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/menu/menudsl.rb', line 53 def porcentajes(text, = {}) porcentaje = text porcentaje << "#{[:vct]} kcal | " if [:vct] porcentaje << "#{[:proteinas]}% - " if [:proteinas] porcentaje << "#{[:grasas]}% - " if [:grasas] porcentaje << "#{[:hidratos]}%" if [:hidratos] porcent << porcentaje end |
#titulo(text, options = {}) ⇒ Object
47 48 49 50 51 |
# File 'lib/menu/menudsl.rb', line 47 def titulo(text, = {}) title = text titul << title end |
#to_s ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/menu/menudsl.rb', line 21 def to_s output = "#{name}\n" titul.each do |title| output << "#{title}" output << "\n#{'=' * title.size}\n" end ingest.each do |ing| output << "#{ing}" end plato.each_with_index do |plat, index| output << "\n#{index + 1})#{plat}" end output << "\nV.C.T | % " porcent.each do |porcentaje| output << "#{porcentaje}" end output << "\n" output end |