alu0100974652-pract06 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +11 -0
- data/.pract06.gemspec.swp +0 -0
- data/.rake_tasks~ +7 -0
- data/.rspec +3 -0
- data/.travis.yml +12 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +95 -0
- data/Guardfile +82 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +1011 -0
- data/docs/List.html +798 -0
- data/docs/Node.html +409 -0
- data/docs/Plato.html +1034 -0
- data/docs/Plato_herencia.html +979 -0
- data/docs/Pract06.html +133 -0
- data/docs/Pract06/Error.html +124 -0
- data/docs/_index.html +171 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +496 -0
- data/docs/file.README.html +111 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +111 -0
- data/docs/js/app.js +303 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +387 -0
- data/docs/top-level-namespace.html +112 -0
- data/lib/pract06.rb +11 -0
- data/lib/pract06/list.rb +68 -0
- data/lib/pract06/menu.rb +33 -0
- data/lib/pract06/plato.rb +94 -0
- data/lib/pract06/plato_herencia.rb +129 -0
- data/lib/pract06/platodsl.rb +29 -0
- data/lib/pract06/pract06.rb +56 -0
- data/lib/pract06/version.rb +3 -0
- data/pract06.gemspec +33 -0
- metadata +173 -0
@@ -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
|
+
— 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> »
|
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="Pract06.html" title="Pract06 (module)">Pract06</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="List.html" title="List (class)">List</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</a></span>, <span class='object_link'><a href="Plato.html" title="Plato (class)">Plato</a></span>, <span class='object_link'><a href="Plato_herencia.html" title="Plato_herencia (class)">Plato_herencia</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 17:08:15 2019 by
|
106
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
|
+
0.9.20 (ruby-2.6.3).
|
108
|
+
</div>
|
109
|
+
|
110
|
+
</div>
|
111
|
+
</body>
|
112
|
+
</html>
|
data/lib/pract06.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "pract06/version"
|
2
|
+
require "pract06/pract06"
|
3
|
+
require "pract06/list"
|
4
|
+
require "pract06/plato"
|
5
|
+
require "pract06/plato_herencia"
|
6
|
+
require "pract06/platodsl"
|
7
|
+
require "pract06/menu"
|
8
|
+
module Pract06
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
end
|
data/lib/pract06/list.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Creación de la clase List con la estructura Node
|
2
|
+
#
|
3
|
+
|
4
|
+
Node = Struct.new(:value, :next, :prev) #Debe existir un nodo con su dato, su siguiente y su previo
|
5
|
+
|
6
|
+
class List
|
7
|
+
attr_accessor :head, :nodo_actual,:tail #Debe existir una Lista con su cabeza y su cola
|
8
|
+
|
9
|
+
include Enumerable
|
10
|
+
|
11
|
+
# Metodo initialize
|
12
|
+
# @param parametros head y tail de la lista
|
13
|
+
|
14
|
+
def initialize(head,tail)
|
15
|
+
@head = nil
|
16
|
+
@tail = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
# Se puede insertar un elemento por la cabeza
|
20
|
+
# @param value para insertar elementos
|
21
|
+
|
22
|
+
def insert(value)
|
23
|
+
node = Node.new(value,nil)
|
24
|
+
if (@head == nil)
|
25
|
+
@head = node
|
26
|
+
else
|
27
|
+
@tail.next = node
|
28
|
+
node.prev = @tail
|
29
|
+
end
|
30
|
+
|
31
|
+
@tail=node
|
32
|
+
end
|
33
|
+
|
34
|
+
# Metodo extract_head
|
35
|
+
# @deprecated Sirve para la extracción de la cabeza de la lista
|
36
|
+
|
37
|
+
def extract_head
|
38
|
+
aux=""
|
39
|
+
if (@head!=nil)
|
40
|
+
aux = @head.value
|
41
|
+
@head = @head.next
|
42
|
+
return aux
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Metodo extract_tail
|
47
|
+
# @deprecated Sirve para la extracción por la cola de la lista
|
48
|
+
|
49
|
+
def extract_tail
|
50
|
+
aux=""
|
51
|
+
if(@tail!=nil)
|
52
|
+
aux = @tail.value
|
53
|
+
@tail = @tail.prev
|
54
|
+
return aux
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Metodo each
|
59
|
+
# @deprecated Sirve para recorrer la lista dando el valor del nodo
|
60
|
+
|
61
|
+
def each
|
62
|
+
node = head
|
63
|
+
while (node!=nil)
|
64
|
+
yield node.value
|
65
|
+
node = node.next
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/pract06/menu.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#Clase para representar un Menu con DSL
|
2
|
+
class Menu
|
3
|
+
attr_accessor :nombre,:platos,:precio
|
4
|
+
def initialize(nombre,&block)
|
5
|
+
@nombre = nombre
|
6
|
+
@platos = []
|
7
|
+
@precios=[]
|
8
|
+
@preciototal =0.0
|
9
|
+
|
10
|
+
if block_given?
|
11
|
+
instance_eval(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def componente(options={})
|
16
|
+
@platos << options[:plato]
|
17
|
+
@precios << options[:precio]
|
18
|
+
end
|
19
|
+
|
20
|
+
def precio(total)
|
21
|
+
@preciototal = total
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
output = "#{@nombre}"
|
26
|
+
output << " = #{@preciototal}€\n"
|
27
|
+
output << "Contiene: \n"
|
28
|
+
@platos.zip(@precios).each do |x,y|
|
29
|
+
output << "#{x} = #{y}€\n"
|
30
|
+
end
|
31
|
+
output
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# Implementación de la clase Plato
|
2
|
+
class Plato
|
3
|
+
attr_accessor :nombre_plato, :conjunto_alimentos, :cantidades_engramos, :cantidades_totales_engramos
|
4
|
+
|
5
|
+
# Método initialize
|
6
|
+
# @param recibe los distintos parámetros para el plato
|
7
|
+
|
8
|
+
def initialize(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos)
|
9
|
+
@nombre_plato, @conjunto_alimentos, @cantidades_engramos, @cantidades_totales_engramos = nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos
|
10
|
+
end
|
11
|
+
|
12
|
+
# Metodo de porcentaje_proteinas
|
13
|
+
# @deprecated Sirve para hallar el porcentaje total de proteinas del plato a tratar
|
14
|
+
# @return retorna el valor un string con el porcentaje de proteinas
|
15
|
+
|
16
|
+
def porcentaje_proteinas
|
17
|
+
|
18
|
+
total_proteinas = 0
|
19
|
+
i = 0
|
20
|
+
while i < conjunto_alimentos.length do
|
21
|
+
aux = conjunto_alimentos[i].proteinas * cantidades_engramos[i]
|
22
|
+
total_proteinas += aux
|
23
|
+
i += 1
|
24
|
+
end
|
25
|
+
|
26
|
+
tporcentaje_proteinas = 0
|
27
|
+
tporcentaje_proteinas = ((total_proteinas/cantidades_totales_engramos)*100).round(1)
|
28
|
+
return "#{tporcentaje_proteinas}%"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Metodos de porcentaje de lipidos
|
32
|
+
# @deprecated Sirve para hallar el porcentaje de lipidos de un plato
|
33
|
+
# @return Devuelve un string con el porcentaje total de lipidos que posee el plato
|
34
|
+
|
35
|
+
def porcentaje_lipidos
|
36
|
+
|
37
|
+
total_lipidos = 0
|
38
|
+
i = 0
|
39
|
+
while i < conjunto_alimentos.length do
|
40
|
+
aux = conjunto_alimentos[i].lipidos * cantidades_engramos[i]
|
41
|
+
total_lipidos += aux
|
42
|
+
i += 1
|
43
|
+
end
|
44
|
+
|
45
|
+
tporcentaje_lipidos = 0
|
46
|
+
tporcentaje_lipidos = ((total_lipidos/cantidades_totales_engramos)*100).round(1)
|
47
|
+
return "#{tporcentaje_lipidos}%"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
# Metodo porcentaje de carbohidratos
|
52
|
+
# @deprecated Sirve para hallar el porcentaje de carbohidratos de un plato
|
53
|
+
# @return Retorna un string con el total de porcentaje de carbohidratos
|
54
|
+
def porcentaje_carbohidratos
|
55
|
+
|
56
|
+
total_carbohidratos = 0
|
57
|
+
i = 0
|
58
|
+
while i < conjunto_alimentos.length do
|
59
|
+
aux = conjunto_alimentos[i].carbohidratos * cantidades_engramos[i]
|
60
|
+
total_carbohidratos += aux
|
61
|
+
i += 1
|
62
|
+
end
|
63
|
+
|
64
|
+
tporcentaje_carbohidratos = 0
|
65
|
+
tporcentaje_carbohidratos = ((total_carbohidratos/cantidades_totales_engramos)*100).round(1)
|
66
|
+
return "#{tporcentaje_carbohidratos}%"
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
# Metodo valor calorico
|
71
|
+
# @deprecated Sirve para hallar el valor calorico total del plato
|
72
|
+
# @return Devuelve un entero con el valor calorico total del plato
|
73
|
+
|
74
|
+
def valor_calorico_total
|
75
|
+
|
76
|
+
total_vc = 0
|
77
|
+
i = 0
|
78
|
+
while i < conjunto_alimentos.length do
|
79
|
+
total_vc += conjunto_alimentos[i].valor_energetico + total_vc
|
80
|
+
i += 1
|
81
|
+
end
|
82
|
+
|
83
|
+
return total_vc
|
84
|
+
end
|
85
|
+
|
86
|
+
# Metodo to_s
|
87
|
+
# @deprecated Sirve para dar el plato en su forma formateada
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
|
91
|
+
"Plato: #{@nombre_plato}, \nIngredientes: #{@conjunto_alimentos},\nCantidad total del plato: #{@cantidades_totales_engramos}, separados en las siguientes cantidades por alimento #{@cantidades_engramos}"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# Implementacion de la clase heredada Plato_herencia
|
2
|
+
|
3
|
+
class Plato_herencia < Plato
|
4
|
+
|
5
|
+
attr_reader :valor_energetico_plato_alimentos
|
6
|
+
|
7
|
+
include Comparable
|
8
|
+
|
9
|
+
# Metodo initialize
|
10
|
+
# @deprecated Metodo para inicializar plato heredado
|
11
|
+
# @param parametros del plato más la utilizacion de la funcion super
|
12
|
+
|
13
|
+
def initialize(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos)
|
14
|
+
|
15
|
+
super(nombre_plato, conjunto_alimentos, cantidades_engramos, cantidades_totales_engramos)
|
16
|
+
@valor_energetico_plato_alimentos = valor_energetico_plato_alimentos
|
17
|
+
@valor = valor
|
18
|
+
@total_ve = total_ve
|
19
|
+
@huella_nutricional = huella_nutricional
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
# Metodo Emisiones totales del plato
|
24
|
+
# @deprecated Funcion para hallar las emisiones totales del plato
|
25
|
+
# @return Devuelve un entero con las emisiones totales del plato
|
26
|
+
|
27
|
+
def total_ve
|
28
|
+
|
29
|
+
total_ve = 0
|
30
|
+
i = 0
|
31
|
+
|
32
|
+
while i < conjunto_alimentos.length do
|
33
|
+
|
34
|
+
total_ve += conjunto_alimentos[i].gei + total_ve
|
35
|
+
i += 1
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
return total_ve
|
40
|
+
end
|
41
|
+
|
42
|
+
# Metodo metros_cuadrados
|
43
|
+
# @deprecated Sirve para hallar los metodos cuadrados del plato
|
44
|
+
# @param Se le pasa el vector de metros cuadrados de los distintos alimentos que componen el plato
|
45
|
+
# @return Devuelve el valor de los metros cuadrados totales del plato
|
46
|
+
|
47
|
+
def metros_cuadrados(x_metros_cuadrados)
|
48
|
+
|
49
|
+
total_mc = 0
|
50
|
+
i = 0
|
51
|
+
|
52
|
+
while i < x_metros_cuadrados.length do
|
53
|
+
|
54
|
+
total_mc += x_metros_cuadrados[i] + total_mc
|
55
|
+
|
56
|
+
i += 1
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
return total_mc
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
# Metodo valor
|
65
|
+
# @deprecated Funcion para hallar el valor energetico del plato heredado
|
66
|
+
# @return Retorna el valor energetico total del plato
|
67
|
+
|
68
|
+
def valor
|
69
|
+
|
70
|
+
i = 0
|
71
|
+
valor = 0
|
72
|
+
while i < conjunto_alimentos.length do
|
73
|
+
|
74
|
+
valor = conjunto_alimentos[i].valor_energetico + valor
|
75
|
+
|
76
|
+
i += 1
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
return valor
|
81
|
+
end
|
82
|
+
|
83
|
+
# Metodo huella nutricional
|
84
|
+
# @deprecated Funcion que halla la huella nutricional
|
85
|
+
# @return Devuelve el resultado de la huella_nutricional
|
86
|
+
|
87
|
+
def huella_nutricional
|
88
|
+
|
89
|
+
@huella_energetica
|
90
|
+
|
91
|
+
if @valor <= 670
|
92
|
+
@huella_energetica = 1.0
|
93
|
+
elsif @valor > 670 && @valor <= 830
|
94
|
+
@huella_energetica = 2.0
|
95
|
+
else
|
96
|
+
@huella_energetica = 3.0
|
97
|
+
end
|
98
|
+
|
99
|
+
@huella_carbono
|
100
|
+
|
101
|
+
if @total_ve <= 800
|
102
|
+
@huella_carbono = 1.0
|
103
|
+
elsif @total_ve > 800 && @total_ve <= 1200
|
104
|
+
@huella_carbono = 2.0
|
105
|
+
else
|
106
|
+
@huella_carbono = 3.0
|
107
|
+
end
|
108
|
+
|
109
|
+
return (@huella_energetica+@huella_carbono)/2
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
# Metodo to_s
|
114
|
+
# @deprecated Da la eficiencia energetica formateada
|
115
|
+
|
116
|
+
def to_s
|
117
|
+
|
118
|
+
"Eficiencia energética = #{valor}"
|
119
|
+
end
|
120
|
+
|
121
|
+
# Metodo <=>
|
122
|
+
# @deprecated Sirve para comparar la eficiencia energetica entre platos
|
123
|
+
|
124
|
+
def <=>(other)
|
125
|
+
return nil unless other.kind_of? Plato_herencia
|
126
|
+
@valor <=> other.valor
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|