lpp1920 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.20
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="Tdd.html" title="Tdd (module)">Tdd</a></span>
86
+
87
+
88
+
89
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Alimento.html" title="Alimento (class)">Alimento</a></span>, <span class='object_link'><a href="ListaDE.html" title="ListaDE (class)">ListaDE</a></span>, <span class='object_link'><a href="Menu.html" title="Menu (class)">Menu</a></span>, <span class='object_link'><a href="MenuEficiente.html" title="MenuEficiente (class)">MenuEficiente</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</a></span>
90
+
91
+
92
+ </p>
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+ </div>
103
+
104
+ <div id="footer">
105
+ Generated on Wed Dec 18 07:36:36 2019 by
106
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
+ 0.9.20 (ruby-2.1.2).
108
+ </div>
109
+
110
+ </div>
111
+ </body>
112
+ </html>
@@ -0,0 +1,112 @@
1
+ # Estructura para representar los nodos de una lista
2
+ # Incluye el valor del nodo y los nodos siguiente y previo a este
3
+ Node = Struct.new(:value, :next, :prev)
4
+
5
+ # @author Juan Martínez
6
+ class ListaDE
7
+ include Enumerable
8
+ attr_reader :head, :tail, :size
9
+
10
+ # Initialize de la lista, establece a nil la cabeza y la cola
11
+ def initialize()
12
+ @head = nil
13
+ @tail = nil
14
+ @size = 0
15
+ end
16
+
17
+ # Inserta el valor pasado a la lista por el head
18
+ #
19
+ # @param value
20
+ # @return
21
+ def insertarHead(value)
22
+ nodo = Node.new(value)
23
+ if @head == nil and @tail == nil
24
+ @head = nodo
25
+ @tail = nodo
26
+ else
27
+ @head.next = nodo
28
+ nodo.prev = @head
29
+ @head = nodo
30
+ end
31
+ @size+=1
32
+ end
33
+
34
+ # Inserta el valor pasado a la lista por el tail
35
+ #
36
+ # @param value
37
+ # @return
38
+ def insertarTail(value)
39
+ nodo = Node.new(value)
40
+ if @head == nil and @tail == nil
41
+ @head = nodo
42
+ @tail = nodo
43
+ else
44
+ @tail.prev = nodo
45
+ nodo.next = @tail
46
+ @tail = nodo
47
+ end
48
+ @size+=1
49
+ end
50
+
51
+ # Extrae el primer valor de la lista.
52
+ #
53
+ # @return
54
+ def extraerHead ()
55
+ extraer = @head
56
+ headActual = @head.prev
57
+ @head = headActual
58
+ if headActual == nil
59
+ @tail = nil
60
+ else
61
+ @head.next = nil
62
+ end
63
+ @size-=1
64
+ return extraer
65
+ end
66
+
67
+ def extraerTail()
68
+ extraer = @tail
69
+ tailActual = @tail.next
70
+ @tail = tailActual
71
+ if tailActual == nil
72
+ @head = nil
73
+ else
74
+ @tail.prev = nil
75
+ end
76
+ @size-=1
77
+ return extraer
78
+ end
79
+
80
+ def emisionesDiarias
81
+ emisiones = 0
82
+ for i in 0..self.size-1
83
+ emisiones += self.extraerHead.value.gei
84
+ end
85
+ return emisiones
86
+ end
87
+
88
+ def emisionesAnuales
89
+ emisiones = 0
90
+ for i in 0..self.size-1
91
+ emisiones += self.extraerHead.value.gei
92
+ end
93
+ emisiones = emisiones * 365
94
+ return emisiones
95
+ end
96
+
97
+ def usoTerreno
98
+ uso_terreno = 0
99
+ for i in 0..self.size-1
100
+ uso_terreno += self.extraerHead.value.terreno
101
+ end
102
+ return uso_terreno
103
+ end
104
+
105
+ def each
106
+ nodo=@tail
107
+ while nodo != nil
108
+ yield nodo.value
109
+ nodo = nodo.next
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,111 @@
1
+ require "tdd/version"
2
+
3
+ # @author Juan Martínez Hurtado de Mendoza
4
+ class Menu
5
+ include Comparable
6
+ attr_reader :platos
7
+
8
+ def initialize (platos)
9
+ @platos = platos
10
+ end
11
+
12
+ # Calcula los gramos totales de proteínas, carbohidratos y lipidos.
13
+ #
14
+ # @return [Integer] El número total de gramos
15
+ def total_gramos
16
+ gramos = 0
17
+ @platos.each do |plato|
18
+ gramos += plato.proteinas + plato.carbohidratos + plato.lipidos
19
+ end
20
+ return gramos
21
+ end
22
+
23
+ # Calcula porcentaje de proteinas
24
+ #
25
+ # @return [Integer] Porcentaje de proteínas
26
+ def proteinas_porcentaje
27
+ gramos_total = self.total_gramos
28
+ proteinas_total = 0
29
+ platos.each do |plato|
30
+ proteinas_total += plato.proteinas
31
+ end
32
+ return ((proteinas_total*100)/gramos_total).to_i
33
+ end
34
+
35
+ # Calcula porcentaje de lipidos
36
+ #
37
+ # @return [Integer] Porcentaje de lipidos
38
+ def lipidos_porcentaje
39
+ gramos_total = self.total_gramos
40
+ lipidos_total = 0
41
+ platos.each do |plato|
42
+ lipidos_total += plato.lipidos
43
+ end
44
+ return ((lipidos_total*100)/gramos_total).to_i
45
+ end
46
+
47
+ # Calcula porcentaje de lipidos
48
+ #
49
+ # @return [Integer] Porcentaje de lipidos
50
+ def carbohidratos_porcentaje
51
+ gramos_total = self.total_gramos
52
+ carbohidratos_total = 0
53
+ platos.each do |plato|
54
+ carbohidratos_total += plato.carbohidratos
55
+ end
56
+ return ((carbohidratos_total*100)/gramos_total).to_i
57
+ end
58
+
59
+ # Calcula el valor calórico total
60
+ #
61
+ # @return [Integer] Calorias totales
62
+ def valorCaloricoTotal
63
+ calorias_totales = 0
64
+ platos.each do |plato|
65
+ calorias_totales += plato.valor_energetico
66
+ end
67
+ return calorias_totales
68
+ end
69
+
70
+ # Método que utiliza el módulo Comparable para poder comparar
71
+ #
72
+ # @param another [Object] Objeto con el que comparar
73
+ # @return [Boolean] True or false
74
+ def <=> (another)
75
+ self.valorCaloricoTotal <=> another.valorCaloricoTotal
76
+ end
77
+ end
78
+
79
+ class MenuEficiente < Menu
80
+ include Comparable
81
+ attr_reader :tipo_menu
82
+
83
+ def initialize (platos)
84
+ super(platos)
85
+ end
86
+
87
+ def total_gases
88
+ gases = 0
89
+ @platos.each do |plato|
90
+ gases += plato.gei
91
+ end
92
+ return gases
93
+ end
94
+
95
+ def total_terreno
96
+ terreno = 0
97
+ @platos.each do |plato|
98
+ terreno += plato.terreno
99
+ end
100
+ return terreno
101
+ end
102
+
103
+ def to_s
104
+ "Gases Totales: #{self.total_gases} kgCO2eq,\n " +
105
+ "Uso Terreno: #{self.total_terreno} m2año"
106
+ end
107
+
108
+ def <=> (another)
109
+ self.total_gases <=> another.total_gases
110
+ end
111
+ end
@@ -0,0 +1,89 @@
1
+ class Plate
2
+ attr_accessor :nombre, :alimento
3
+
4
+ def initialize(name, &block)
5
+ @nombre = name
6
+ @alimento = []
7
+
8
+ if block_given?
9
+ if block.arity == 1
10
+ yield self
11
+ else
12
+ instance_eval(&block)
13
+ end
14
+ end
15
+ end
16
+
17
+ def to_s
18
+ output = @nombre
19
+ output << "\n#{'=' * @nombre.size}\n\n"
20
+ output << "Alimentos: #{@alimento.join(', ')}\n\n"
21
+
22
+ output
23
+ end
24
+
25
+ def nombre(name, options = {})
26
+ nombre = name
27
+ @nombre << " (#{nombre})"
28
+ end
29
+
30
+ def alimento(options = {})
31
+ alimento = options[:descripcion]
32
+ alimento << " (#{options[:gramos]} gramos)"
33
+ @alimento << alimento
34
+ end
35
+ end
36
+
37
+ class Menu2
38
+ attr_accessor :nombre, :descripcion, :componente
39
+
40
+ def initialize(name, &block)
41
+ @nombre = name
42
+ @descripcion = ''
43
+ @componente = []
44
+
45
+ if block_given?
46
+ if block.arity == 1
47
+ yield self
48
+ else
49
+ instance_eval(&block)
50
+ end
51
+ end
52
+ end
53
+
54
+ def to_s
55
+ output = @nombre
56
+ output << "\n#{'=' * @nombre.size}\n\n"
57
+ output << "Componentes: #{@componente.join(', ')}"
58
+ end
59
+
60
+ def descripcion(description, options = {})
61
+ descripcion = description
62
+ @nombre << " (#{descripcion})"
63
+ end
64
+
65
+ def componente(options = {})
66
+ componente = options[:descripcion]
67
+ componente << " (#{options[:precio]} €)"
68
+ @componente << componente
69
+ end
70
+ end
71
+
72
+ menu = Menu2.new("Combinado 1") do
73
+ descripcion "hamburguesa con papas"
74
+ componente :descripcion => "hamburguesa especial", :precio => 4.2
75
+ componente :descripcion => "papas pequeñas", :precio => 3
76
+ end
77
+ puts menu
78
+
79
+ plato = Plate.new("Hamurguesa") do
80
+ nombre "Hamburguesa especial de la casa"
81
+ alimento :descripcion => "carne de vaca",
82
+ :gramos => 20
83
+ alimento :descripcion => "huevo",
84
+ :gramos => 10
85
+ end
86
+
87
+ puts plato
88
+
89
+
@@ -0,0 +1,62 @@
1
+ require "tdd/version"
2
+
3
+ # @author Juan Martínez
4
+ class Alimento
5
+ include Comparable
6
+ attr_reader :nombre, :proteinas, :carbohidratos, :lipidos, :gei, :terreno
7
+
8
+ def initialize (nombre, proteinas, carbohidratos, lipidos, gei, terreno)
9
+ @nombre = nombre
10
+ @proteinas = proteinas
11
+ @carbohidratos = carbohidratos
12
+ @lipidos = lipidos
13
+ @gei = gei
14
+ @terreno = terreno
15
+ end
16
+
17
+ def get_nombre
18
+ "Nombre: #{@nombre}"
19
+ end
20
+
21
+ def get_gei
22
+ "GEI: #{@gei} kgCO2eq"
23
+ end
24
+
25
+ def get_terreno
26
+ "Terreno: #{@terreno} m2/año"
27
+ end
28
+
29
+ # Formatea el alimento
30
+ #
31
+ # @return [String]
32
+ def to_s
33
+ "Nombre: #{@nombre}\n " +
34
+ "Proteinas: #{@proteinas}\n " +
35
+ "Carbohidratos: #{@carbohidratos}\n " +
36
+ "Lipidos: #{@lipidos}\n " +
37
+ "GEI: #{@gei}\n " +
38
+ "Terreno: #{@terreno}"
39
+ end
40
+
41
+ def valor_energetico
42
+ (@lipidos * 9) + (@proteinas * 4) + (@carbohidratos * 4)
43
+ end
44
+
45
+ def impacto_ambiental
46
+ true
47
+ end
48
+
49
+ def huella_nutricional
50
+ if self.valor_energetico < 670 and self.gei < 800
51
+ return 1,self
52
+ elseif self.valor_energetico.between?(670,830) and self.gei.between?(800-1200)
53
+ return 2,self
54
+ else
55
+ return 3,self
56
+ end
57
+ end
58
+
59
+ def <=> (another)
60
+ self.valor_energetico <=> another.valor_energetico
61
+ end
62
+ end