prct06 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/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/documentation/Dieta.html +1061 -0
- data/documentation/DietaEdad.html +396 -0
- data/documentation/DietaGrupo.html +396 -0
- data/documentation/LinkedList.html +984 -0
- data/documentation/Node.html +411 -0
- data/documentation/Prct06.html +119 -0
- data/documentation/_index.html +158 -0
- data/documentation/class_list.html +51 -0
- data/documentation/css/common.css +1 -0
- data/documentation/css/full_list.css +58 -0
- data/documentation/css/style.css +481 -0
- data/documentation/file.README.html +128 -0
- data/documentation/file_list.html +56 -0
- data/documentation/frames.html +17 -0
- data/documentation/index.html +128 -0
- data/documentation/js/app.js +243 -0
- data/documentation/js/full_list.js +216 -0
- data/documentation/js/jquery.js +4 -0
- data/documentation/method_list.html +299 -0
- data/documentation/top-level-namespace.html +114 -0
- data/lib/.DS_Store +0 -0
- data/lib/prct06.rb +5 -0
- data/lib/prct06/Dieta.rb +196 -0
- data/lib/prct06/LinkedList.rb +141 -0
- data/lib/prct06/version.rb +3 -0
- data/prct06.gemspec +40 -0
- metadata +168 -0
|
@@ -0,0 +1,114 @@
|
|
|
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.5
|
|
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"></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
|
+
<iframe id="search_frame" src="class_list.html"></iframe>
|
|
63
|
+
|
|
64
|
+
<div id="content"><h1>Top Level Namespace
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
</h1>
|
|
69
|
+
<div class="box_info">
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<h2>Defined Under Namespace</h2>
|
|
84
|
+
<p class="children">
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Prct06.html" title="Prct06 (module)">Prct06</a></span>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Dieta.html" title="Dieta (class)">Dieta</a></span>, <span class='object_link'><a href="DietaEdad.html" title="DietaEdad (class)">DietaEdad</a></span>, <span class='object_link'><a href="DietaGrupo.html" title="DietaGrupo (class)">DietaGrupo</a></span>, <span class='object_link'><a href="LinkedList.html" title="LinkedList (class)">LinkedList</a></span>, <span class='object_link'><a href="Node.html" title="Node (class)">Node</a></span>
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
</p>
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div id="footer">
|
|
107
|
+
Generated on Wed Nov 23 12:08:16 2016 by
|
|
108
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
109
|
+
0.9.5 (ruby-2.3.0).
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
</div>
|
|
113
|
+
</body>
|
|
114
|
+
</html>
|
data/lib/.DS_Store
ADDED
|
Binary file
|
data/lib/prct06.rb
ADDED
data/lib/prct06/Dieta.rb
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
require "version"
|
|
2
|
+
|
|
3
|
+
#clase principal de la jerarquía
|
|
4
|
+
class Dieta
|
|
5
|
+
|
|
6
|
+
#Módulo
|
|
7
|
+
include Comparable
|
|
8
|
+
|
|
9
|
+
#attr
|
|
10
|
+
attr_accessor :nombre, :titulo, :porcentaje_ingesta, :vct, :proteinas, :grasas, :hidratos, :platos, :nplatos
|
|
11
|
+
|
|
12
|
+
#constructor
|
|
13
|
+
def initialize (nombre, &block)
|
|
14
|
+
self.nombre = nombre
|
|
15
|
+
self.titulo
|
|
16
|
+
self.porcentaje_ingesta
|
|
17
|
+
self.nplatos
|
|
18
|
+
|
|
19
|
+
self.platos = []
|
|
20
|
+
|
|
21
|
+
self.vct
|
|
22
|
+
self.proteinas
|
|
23
|
+
self.grasas
|
|
24
|
+
self.hidratos
|
|
25
|
+
|
|
26
|
+
if block_given?
|
|
27
|
+
if block.arity == 1
|
|
28
|
+
yield self
|
|
29
|
+
else
|
|
30
|
+
instance_eval &block
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
#función para definir el título del menú: almuerzo, cena, etc.
|
|
36
|
+
def tipo(ntitulo)
|
|
37
|
+
self.titulo = ntitulo
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
#función para definir el porcentaje de ingesta. Podría darse una estimación entre dos
|
|
41
|
+
def ingesta(porcentaje = {})
|
|
42
|
+
standard = porcentaje[:fijo] if porcentaje[:fijo]
|
|
43
|
+
low = porcentaje[:min] if porcentaje[:min]
|
|
44
|
+
up = porcentaje[:max] if porcentaje[:max]
|
|
45
|
+
|
|
46
|
+
if porcentaje[:fijo] then
|
|
47
|
+
self.porcentaje_ingesta = "#{standard}%"
|
|
48
|
+
else
|
|
49
|
+
self.porcentaje_ingesta = "#{low}% - #{up}%"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
#función para definir los porcentajes de grasa, proteínas, hidratos y el valor calórico total
|
|
54
|
+
def porcentajes(options = {})
|
|
55
|
+
self.vct = options[:vct] if options[:vct]
|
|
56
|
+
self.proteinas = options[:proteinas] if options[:proteinas]
|
|
57
|
+
self.grasas = options[:grasas] if options[:grasas]
|
|
58
|
+
self.hidratos = options[:hidratos] if options[:hidratos]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
#función para definir platos nuevos
|
|
62
|
+
def plato(options = {})
|
|
63
|
+
nuevo = []
|
|
64
|
+
nuevo << "#{options[:descripcion]}" if options[:descripcion]
|
|
65
|
+
nuevo << "#{options[:porcion]}" if options[:porcion]
|
|
66
|
+
nuevo << options[:gramos] if options[:gramos]
|
|
67
|
+
platos << nuevo
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
#acceso a un plato en concreto
|
|
71
|
+
def get_plato (n)
|
|
72
|
+
if n < 1 then
|
|
73
|
+
return ""
|
|
74
|
+
end
|
|
75
|
+
return platos[n-1]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
#invalidación del <=> para hacer los objetos comparables
|
|
79
|
+
def <=> (other)
|
|
80
|
+
return nil unless other.is_a?Dieta
|
|
81
|
+
self.vct <=> other.vct
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#formateo a string
|
|
85
|
+
def to_s
|
|
86
|
+
x = ""
|
|
87
|
+
x << "#{titulo} (#{porcentaje_ingesta})\n"
|
|
88
|
+
|
|
89
|
+
platos.each do |i|
|
|
90
|
+
x << "- #{i[0]}, #{i[1]}, #{i[2]}g\n"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
x << "V.C.T | % #{vct} kcal | #{proteinas} #{grasas} #{hidratos}\n\n"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
#clase hija que representa grupos de alimentos
|
|
101
|
+
class DietaGrupo < Dieta
|
|
102
|
+
|
|
103
|
+
#attr
|
|
104
|
+
attr_accessor :grupo
|
|
105
|
+
|
|
106
|
+
#initialize
|
|
107
|
+
def initialize (nombre)
|
|
108
|
+
super(nombre)
|
|
109
|
+
self.grupo
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
#función que permite especificar el grupo de alimentos al que pertenece la receta a modo de DSL
|
|
113
|
+
def grupo_alimentos (text)
|
|
114
|
+
self.grupo = text
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#formateo que añade el grupo de alimentos con respecto al de la clase madre
|
|
118
|
+
def to_s
|
|
119
|
+
output = ""
|
|
120
|
+
output << super.to_s
|
|
121
|
+
output << "Perteneciente a: #{grupo}\n\n"
|
|
122
|
+
output
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
#clase hija que representa menús para grupos de personas según su edad
|
|
130
|
+
class DietaEdad < Dieta
|
|
131
|
+
|
|
132
|
+
#attr
|
|
133
|
+
attr_accessor :edades
|
|
134
|
+
|
|
135
|
+
#initialize
|
|
136
|
+
def initialize (nombre, &block)
|
|
137
|
+
super(nombre)
|
|
138
|
+
self.edades
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
#función que permite definir el grupo de edades a modo de DSL
|
|
142
|
+
def grupo_edades (text)
|
|
143
|
+
self.edades = text
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
#formateo que añade el grupo de alimentos con respecto al de la clase madre
|
|
147
|
+
def to_s
|
|
148
|
+
output = ""
|
|
149
|
+
output << super.to_s
|
|
150
|
+
output << "Para personas de: #{edades}\n\n"
|
|
151
|
+
output
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
#END
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
require "version"
|
|
2
|
+
|
|
3
|
+
#estructura para los nodos de la lista
|
|
4
|
+
Node = Struct.new(:value, :next, :prev)
|
|
5
|
+
|
|
6
|
+
#lista doblemente enlazada
|
|
7
|
+
class LinkedList
|
|
8
|
+
|
|
9
|
+
#módulo enumerable
|
|
10
|
+
include Enumerable
|
|
11
|
+
|
|
12
|
+
#attr
|
|
13
|
+
attr_reader :head
|
|
14
|
+
|
|
15
|
+
#initialize que crea una lista con tantos nodos como argumentos le pasemos
|
|
16
|
+
def initialize (value, *more)
|
|
17
|
+
@head = Node.new(value)
|
|
18
|
+
aux = @head
|
|
19
|
+
more.each do |i|
|
|
20
|
+
aux.next = Node.new(i, nil, aux)
|
|
21
|
+
aux = aux.next
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#método que devuelve el número de elementos en la lista
|
|
26
|
+
def length
|
|
27
|
+
aux = @head
|
|
28
|
+
cnt = 0
|
|
29
|
+
while aux != nil do
|
|
30
|
+
aux = aux.next
|
|
31
|
+
cnt = cnt + 1
|
|
32
|
+
end
|
|
33
|
+
return cnt
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#método que accede a los valores de cada nodo según el iterador pos
|
|
37
|
+
def access (pos)
|
|
38
|
+
p = pos-1
|
|
39
|
+
aux = @head
|
|
40
|
+
for i in 0..p-1 do
|
|
41
|
+
aux = aux.next
|
|
42
|
+
end
|
|
43
|
+
return aux[:value]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
#método que accede a los nodos de la lista según el iterador pos
|
|
47
|
+
def access_node (pos)
|
|
48
|
+
p = pos-1
|
|
49
|
+
aux = @head
|
|
50
|
+
for i in 0..p-1 do
|
|
51
|
+
aux = aux.next
|
|
52
|
+
end
|
|
53
|
+
return aux
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
#saca un elemento de la lista, eliminando el nodo, según el iterador p
|
|
58
|
+
def pop (pos)
|
|
59
|
+
if pos == 1 then
|
|
60
|
+
aux = @head
|
|
61
|
+
@head = @head.next
|
|
62
|
+
aux.prev = nil
|
|
63
|
+
aux.next = nil
|
|
64
|
+
return aux[:value]
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
p = pos-2
|
|
68
|
+
aux = @head
|
|
69
|
+
for i in 0..p-1 do
|
|
70
|
+
prev = aux
|
|
71
|
+
aux = aux.next
|
|
72
|
+
end
|
|
73
|
+
popping = aux.next
|
|
74
|
+
aux.next = popping.next
|
|
75
|
+
(popping.next).prev = aux unless popping.next == nil
|
|
76
|
+
return popping[:value]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#introduce un elemento en un nuevo nodo de la lista
|
|
80
|
+
#si no se especifica la posición deseada, hace push al final de la lista
|
|
81
|
+
def push (value, pos = 0)
|
|
82
|
+
if pos == 0 then
|
|
83
|
+
aux = @head
|
|
84
|
+
for i in 0..length-2 do
|
|
85
|
+
aux = aux.next
|
|
86
|
+
end
|
|
87
|
+
aux.next = Node.new(value, nil, aux)
|
|
88
|
+
elsif pos == 1 then
|
|
89
|
+
aux = @head
|
|
90
|
+
@head = Node.new(value)
|
|
91
|
+
@head.next = aux unless aux == nil
|
|
92
|
+
else
|
|
93
|
+
p = pos-2
|
|
94
|
+
aux = @head
|
|
95
|
+
for i in 0..p-1 do
|
|
96
|
+
aux = aux.next
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
save = aux.next
|
|
100
|
+
aux.next = Node.new(value, save, aux)
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
#crea tantos nodos nuevos al final de la lista como elementos se pase como argumentos
|
|
105
|
+
def push_multiple (*values)
|
|
106
|
+
aux = @head
|
|
107
|
+
for i in 0..length-2 do
|
|
108
|
+
aux = aux.next
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
values.each do |i|
|
|
112
|
+
aux.next = Node.new(i, nil, aux)
|
|
113
|
+
aux = aux.next
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
#invalidación de each para el correcto funcionamiento del módulo enumerable
|
|
118
|
+
def each
|
|
119
|
+
aux = @head
|
|
120
|
+
while aux != nil do
|
|
121
|
+
yield aux.value
|
|
122
|
+
aux = aux.next
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
#formateo a string de la lista completa
|
|
129
|
+
def to_s
|
|
130
|
+
output = "{ "
|
|
131
|
+
aux = @head
|
|
132
|
+
while aux != nil do
|
|
133
|
+
output << "#{aux[:value]} "
|
|
134
|
+
aux = aux[:next]
|
|
135
|
+
end
|
|
136
|
+
output << "}"
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
end
|