nutrientes_AkaiBF 1.3.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 +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento.html +927 -0
- data/docs/Carbohidratado.html +301 -0
- data/docs/Carnido.html +301 -0
- data/docs/Fruta.html +301 -0
- data/docs/Graso.html +301 -0
- data/docs/List.html +1469 -0
- data/docs/Node.html +410 -0
- data/docs/Nutrientes.html +139 -0
- data/docs/OvoLacteo.html +301 -0
- data/docs/Pescado.html +301 -0
- data/docs/Verdura.html +301 -0
- data/docs/_index.html +224 -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 +492 -0
- data/docs/file.README.html +135 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +135 -0
- data/docs/js/app.js +248 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +267 -0
- data/docs/top-level-namespace.html +112 -0
- data/lib/nutrientes.rb +8 -0
- data/lib/nutrientes/alimento.rb +165 -0
- data/lib/nutrientes/glucosa.rb +40 -0
- data/lib/nutrientes/harvard_dish.rb +94 -0
- data/lib/nutrientes/list.rb +109 -0
- data/lib/nutrientes/version.rb +4 -0
- data/nutrientes.gemspec +39 -0
- metadata +187 -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.9
|
|
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="Nutrientes.html" title="Nutrientes (module)">Nutrientes</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="Carbohidratado.html" title="Carbohidratado (class)">Carbohidratado</a></span>, <span class='object_link'><a href="Carnido.html" title="Carnido (class)">Carnido</a></span>, <span class='object_link'><a href="Fruta.html" title="Fruta (class)">Fruta</a></span>, <span class='object_link'><a href="Graso.html" title="Graso (class)">Graso</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="OvoLacteo.html" title="OvoLacteo (class)">OvoLacteo</a></span>, <span class='object_link'><a href="Pescado.html" title="Pescado (class)">Pescado</a></span>, <span class='object_link'><a href="Verdura.html" title="Verdura (class)">Verdura</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 Nov 15 09:37:57 2017 by
|
|
106
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
107
|
+
0.9.9 (ruby-2.3.0).
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
</div>
|
|
111
|
+
</body>
|
|
112
|
+
</html>
|
data/lib/nutrientes.rb
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# Alimento class that stores different kinds of food for Lenguajes y Paradigmas de la Programación
|
|
2
|
+
# Universidad de La Laguna
|
|
3
|
+
#
|
|
4
|
+
# @author Ernesto Echeverría González
|
|
5
|
+
# @since 10-11-2017
|
|
6
|
+
# @email alu0100881622@ull.edu.es
|
|
7
|
+
# @version 1.2.0
|
|
8
|
+
|
|
9
|
+
# Class Alimento
|
|
10
|
+
# Stores a food and some values of its elements.
|
|
11
|
+
class Alimento
|
|
12
|
+
include Comparable
|
|
13
|
+
attr_reader :name, :proteins, :glucids, :lipids
|
|
14
|
+
|
|
15
|
+
# Method to implement the comparison between two Alimentos
|
|
16
|
+
# @param another [Object] Object to compare with
|
|
17
|
+
# @return [Fixnum] 1 if the first object is bigger, 0 if equal and -1 if minor
|
|
18
|
+
def <=>(another)
|
|
19
|
+
if(another.caloric_value > caloric_value)
|
|
20
|
+
return -1
|
|
21
|
+
else
|
|
22
|
+
if(another.caloric_value < caloric_value)
|
|
23
|
+
return 1
|
|
24
|
+
end
|
|
25
|
+
if (another.proteins > proteins)
|
|
26
|
+
return -1
|
|
27
|
+
else
|
|
28
|
+
if(another.proteins < proteins)
|
|
29
|
+
return 1
|
|
30
|
+
end
|
|
31
|
+
if(another.glucids > glucids)
|
|
32
|
+
return -1
|
|
33
|
+
else
|
|
34
|
+
if(another.glucids < glucids)
|
|
35
|
+
return 1
|
|
36
|
+
end
|
|
37
|
+
if(another.lipids > lipids)
|
|
38
|
+
return -1
|
|
39
|
+
else
|
|
40
|
+
if(another.lipids < lipids)
|
|
41
|
+
return 1
|
|
42
|
+
else return 0
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Initialization of the object given its attributes
|
|
51
|
+
# @param name [String] Name of the Alimento
|
|
52
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
53
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
54
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
55
|
+
def initialize (name, proteins, glucids, lipids)
|
|
56
|
+
@name = name
|
|
57
|
+
@proteins = proteins
|
|
58
|
+
@glucids = glucids
|
|
59
|
+
@lipids = lipids
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Method to transform an object of Alimento to a string
|
|
63
|
+
# @return [String] the object as a string
|
|
64
|
+
def to_s()
|
|
65
|
+
return String.new(@name + ", " + @proteins.to_s + "g proteins, " + @glucids.to_s + "g glucids, " + @lipids.to_s + "g lipids")
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Calculates the caloric value of the Alimento
|
|
69
|
+
# @return [Fixnum] The caloric value
|
|
70
|
+
def caloric_value()
|
|
71
|
+
return (@proteins * 4 + @lipids * 9 + @glucids * 4)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Class OvoLacteo
|
|
77
|
+
# Defines an Alimento (or food) derived from milk or eggs
|
|
78
|
+
class OvoLacteo < Alimento
|
|
79
|
+
# Initialization of the object given its attributes
|
|
80
|
+
# @param name [String] Name of the Alimento
|
|
81
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
82
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
83
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
84
|
+
def initialize(name, proteins, glucids, lipids)
|
|
85
|
+
super(name, proteins, glucids, lipids)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Class Carnido
|
|
90
|
+
# Defines meat and derivates
|
|
91
|
+
class Carnido < Alimento
|
|
92
|
+
# Initialization of the object given its attributes
|
|
93
|
+
# @param name [String] Name of the Alimento
|
|
94
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
95
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
96
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
97
|
+
def initialize(name, proteins, glucids, lipids)
|
|
98
|
+
super(name, proteins, glucids, lipids)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Class Pescado
|
|
103
|
+
# Defines Fish and Shelfish
|
|
104
|
+
class Pescado < Alimento
|
|
105
|
+
# Initialization of the object given its attributes
|
|
106
|
+
# @param name [String] Name of the Alimento
|
|
107
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
108
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
109
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
110
|
+
def initialize(name, proteins, glucids, lipids)
|
|
111
|
+
super(name, proteins, glucids, lipids)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Class Graso
|
|
116
|
+
# Defines a food with high fat content
|
|
117
|
+
class Graso < Alimento
|
|
118
|
+
# Initialization of the object given its attributes
|
|
119
|
+
# @param name [String] Name of the Alimento
|
|
120
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
121
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
122
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
123
|
+
def initialize(name, proteins, glucids, lipids)
|
|
124
|
+
super(name, proteins, glucids, lipids)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Class Carbohidratado
|
|
129
|
+
# Defines food mainly componed by carbohydrates
|
|
130
|
+
class Carbohidratado < Alimento
|
|
131
|
+
# Initialization of the object given its attributes
|
|
132
|
+
# @param name [String] Name of the Alimento
|
|
133
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
134
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
135
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
136
|
+
def initialize(name, proteins, glucids, lipids)
|
|
137
|
+
super(name, proteins, glucids, lipids)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Class Verdura
|
|
142
|
+
# Defines vegetables
|
|
143
|
+
class Verdura < Alimento
|
|
144
|
+
# Initialization of the object given its attributes
|
|
145
|
+
# @param name [String] Name of the Alimento
|
|
146
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
147
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
148
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
149
|
+
def initialize(name, proteins, glucids, lipids)
|
|
150
|
+
super(name, proteins, glucids, lipids)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# Class Fruta
|
|
155
|
+
# Defines fruits
|
|
156
|
+
class Fruta < Alimento
|
|
157
|
+
# Initialization of the object given its attributes
|
|
158
|
+
# @param name [String] Name of the Alimento
|
|
159
|
+
# @param proteins [Fixnum] Proteins ammount of the Alimento
|
|
160
|
+
# @param glucids [Fixnum] Glucids ammount of the Alimento
|
|
161
|
+
# @param lipids [Fixnum] Lipids ammount of the Alimento
|
|
162
|
+
def initialize(name, proteins, glucids, lipids)
|
|
163
|
+
super(name, proteins, glucids, lipids)
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Experimento class that calculates the glucemic index for Lenguajes y Paradigmas de la Programación
|
|
2
|
+
# Universidad de La Laguna
|
|
3
|
+
#
|
|
4
|
+
# @author Ernesto Echeverría González
|
|
5
|
+
# @since 22-11-2017
|
|
6
|
+
# @email alu0100881622@ull.edu.es
|
|
7
|
+
# @version 1.0.0
|
|
8
|
+
|
|
9
|
+
# Class Experimento
|
|
10
|
+
# Calculates the glucemic value of a food
|
|
11
|
+
class Experimento
|
|
12
|
+
|
|
13
|
+
# Initialization of the object given its attributes
|
|
14
|
+
# @param alimento [Object] Test target
|
|
15
|
+
# @param medidas [Array] Measures from a subject
|
|
16
|
+
# @param glucosa [Array] Measures of glucose
|
|
17
|
+
def initialize(alimento, medidas, glucosa)
|
|
18
|
+
@alimento = alimento
|
|
19
|
+
@medidas = medidas
|
|
20
|
+
@glucosa = glucosa
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Calculates the AIBC recursively
|
|
24
|
+
# @param i [FixNum] Index of the current element
|
|
25
|
+
# @return [FixNum] AIBC
|
|
26
|
+
def get_AIBC(i)
|
|
27
|
+
@@tam = @medidas.length
|
|
28
|
+
if i >= @@tam
|
|
29
|
+
return 0
|
|
30
|
+
else
|
|
31
|
+
return (((@medidas[i] - @medidas[0]) + (@medidas[i - 1] - @medidas[0])) / 24) + get_AIBC(i + 1)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Calculates the Glucemic index
|
|
36
|
+
# @return [FixNum] Glucemic index
|
|
37
|
+
def get_IG()
|
|
38
|
+
return (get_AIBC(1) / Experimento.new(nil, @glucosa, @glucosa).get_AIBC(1)) * 100
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# Processor of a DSL that allows to create Harvard dishes
|
|
2
|
+
#
|
|
3
|
+
# @author Ernesto Echeverría González
|
|
4
|
+
# @since 13-12-2017
|
|
5
|
+
# @email alu0100881622@ull.edu.es
|
|
6
|
+
# @version 1.0.0
|
|
7
|
+
require './alimento'
|
|
8
|
+
|
|
9
|
+
class HarvardDish
|
|
10
|
+
@@list =
|
|
11
|
+
[OvoLacteo.new("Huevo frito", 14.1, 0.0, 19.5),
|
|
12
|
+
OvoLacteo.new("Leche de vaca", 3.3, 4.8, 3.2),
|
|
13
|
+
OvoLacteo.new("Yogurt", 3.8, 4.9, 3.8),
|
|
14
|
+
Carnido.new("Cerdo", 21.5, 0.0, 6.3),
|
|
15
|
+
Carnido.new("Ternera", 21.1, 0.0, 3.1),
|
|
16
|
+
Carnido.new("Pollo", 20.6, 0.0, 5.6),
|
|
17
|
+
Pescado.new("Bacalao", 17.7, 0.0, 0.4),
|
|
18
|
+
Pescado.new("Atún", 21.5, 0.0, 15.5),
|
|
19
|
+
Pescado.new("Salmón", 19.9, 0.0, 13.6),
|
|
20
|
+
Graso.new("Aceite de oliva", 0.0, 0.2, 99.6),
|
|
21
|
+
Graso.new("Mantequilla", 0.7, 0.0, 83.2),
|
|
22
|
+
Graso.new("Chocolate", 5.3, 47.0, 30.0),
|
|
23
|
+
Carbohidratado.new("Azúcar", 0.0, 99.8, 0.0),
|
|
24
|
+
Carbohidratado.new("Arroz", 6.8, 77.7, 0.6),
|
|
25
|
+
Carbohidratado.new("Lentejas", 23.5, 52.0, 1.4),
|
|
26
|
+
Carbohidratado.new("Papas", 2.0, 15.4, 0.1),
|
|
27
|
+
Verdura.new("Tomate", 1.0, 3.5, 0.2),
|
|
28
|
+
Verdura.new("Cebolla", 1.3, 5.8, 0.3),
|
|
29
|
+
Verdura.new("Calabaza", 1.1, 4.8, 0.1),
|
|
30
|
+
Fruta.new("Manzana", 0.3, 12.4, 0.4),
|
|
31
|
+
Fruta.new("Plátano", 1.2, 21.4, 0.2),
|
|
32
|
+
Fruta.new("Pera", 0.5 ,12.7, 0.3)]
|
|
33
|
+
@@proportions = [["/piezas? pequeña/", 2],
|
|
34
|
+
["/pieza/" , 4],
|
|
35
|
+
["/taza/" , 0.6],
|
|
36
|
+
["/cuchara/" , 0.4],
|
|
37
|
+
["/cuchar[o|ó]n/" , 0.8],
|
|
38
|
+
["/vaso/" , 1.2],
|
|
39
|
+
["/gramo/" , 1],
|
|
40
|
+
["/pizca/" , 0.5]]
|
|
41
|
+
def initialize(name, &block)
|
|
42
|
+
@name = name
|
|
43
|
+
@ingredients = []
|
|
44
|
+
@amounts = []
|
|
45
|
+
@cv_total = 0
|
|
46
|
+
|
|
47
|
+
if block_given?
|
|
48
|
+
if block.arity == 1 then
|
|
49
|
+
yield self
|
|
50
|
+
else
|
|
51
|
+
instance_eval(&block)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def to_s()
|
|
57
|
+
output = @name
|
|
58
|
+
output << "\n#{'=' * @name.size}\n"
|
|
59
|
+
output << "Nombre Proteínas Glúcidos Lípidos Valor calórico\n"
|
|
60
|
+
@ingredients.each_index do |i|
|
|
61
|
+
output << @ingredients[i].name << " " << @ingredients[i].proteins.to_s << " " << @ingredients[i].glucids.to_s << " " << @ingredients[i].lipids.to_s << " " << (@ingredients[i].caloric_value * @amounts[i]).to_s << "\n"
|
|
62
|
+
@cv_total += (@ingredients[i].caloric_value * @amounts[i])
|
|
63
|
+
end
|
|
64
|
+
output << "Valor calórico total: " << @cv_total.to_s << "\n"
|
|
65
|
+
return output
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def ingredient(nombre, cantidad)
|
|
69
|
+
@@list.each_index do |i|
|
|
70
|
+
if @@list[i].name == nombre then
|
|
71
|
+
@ingredients << @@list[i]
|
|
72
|
+
numero = /\d/.match(cantidad)
|
|
73
|
+
multiplier = 0
|
|
74
|
+
@@proportions.each_index do |j|
|
|
75
|
+
expr = Regexp.new @@proportions[j][0]
|
|
76
|
+
if expr.match(cantidad) != nil then
|
|
77
|
+
multiplier = @@proportions[j][1]
|
|
78
|
+
break;
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
multiplier += numero[0].to_i
|
|
82
|
+
@amounts << multiplier
|
|
83
|
+
break
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
testo = HarvardDish.new("Menú para niños") do
|
|
90
|
+
ingredient("Pollo", "3 cucharas")
|
|
91
|
+
ingredient("Arroz", "2 cucharones")
|
|
92
|
+
ingredient("Huevo frito", "1 vaso")
|
|
93
|
+
end
|
|
94
|
+
print testo
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# A list class implementation for Lenguajes y Paradigmas de la Programación
|
|
2
|
+
# Universidad de La Laguna
|
|
3
|
+
#
|
|
4
|
+
# @author Ernesto Echeverría González
|
|
5
|
+
# @since 10-11-2017
|
|
6
|
+
# @email alu0100881622@ull.edu.es
|
|
7
|
+
# @version 1.0.0
|
|
8
|
+
|
|
9
|
+
# Class Node
|
|
10
|
+
# Defines the container of each element of the list
|
|
11
|
+
# @!attribute r nodo
|
|
12
|
+
class Node
|
|
13
|
+
@@estructura = Struct.new(:value, :next_, :prev_)
|
|
14
|
+
attr_reader :nodo
|
|
15
|
+
|
|
16
|
+
# Initialization of a node
|
|
17
|
+
# @param val [Object] Value to store at the node
|
|
18
|
+
def initialize(val)
|
|
19
|
+
@nodo = @@estructura.new(val, nil, nil)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Class List
|
|
24
|
+
# Defines the list
|
|
25
|
+
# @!attribute [r] head
|
|
26
|
+
# @return [Object] The first element of the list
|
|
27
|
+
# @!attribute [r] tail
|
|
28
|
+
# @return [Object] The last element of the list
|
|
29
|
+
# @!attribute [r] size
|
|
30
|
+
# @return [Fixnum] Size of the list
|
|
31
|
+
class List
|
|
32
|
+
attr_reader :head, :tail, :size
|
|
33
|
+
include Enumerable
|
|
34
|
+
|
|
35
|
+
# Initialization of the list
|
|
36
|
+
def initialize()
|
|
37
|
+
@size = 0
|
|
38
|
+
@head = nil
|
|
39
|
+
@tail = nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Defines the each method to make use of the Enumerable module
|
|
43
|
+
def each
|
|
44
|
+
actual = @head
|
|
45
|
+
while actual != nil do
|
|
46
|
+
yield actual
|
|
47
|
+
actual = actual.nodo[:next_]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Inserts a node at the beginning of the list
|
|
52
|
+
# @param [Object] nodo node to insert
|
|
53
|
+
# @return nil
|
|
54
|
+
def push(nodo)
|
|
55
|
+
if @size == 0 then
|
|
56
|
+
@head = nodo
|
|
57
|
+
@tail = nodo
|
|
58
|
+
else
|
|
59
|
+
@tail.nodo[:next_] = nodo
|
|
60
|
+
nodo.nodo[:prev_] = @tail
|
|
61
|
+
@tail = nodo
|
|
62
|
+
end
|
|
63
|
+
@size += 1
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Inserts a node at the end of the list
|
|
67
|
+
# @param nodo [Object] node to insert
|
|
68
|
+
# @return nil
|
|
69
|
+
def insert(nodo)
|
|
70
|
+
if @size == 0 then
|
|
71
|
+
@head = nodo
|
|
72
|
+
@tail = nodo
|
|
73
|
+
else
|
|
74
|
+
@head.nodo[:prev_] = nodo
|
|
75
|
+
nodo.nodo[:next_] = @head
|
|
76
|
+
@head = nodo
|
|
77
|
+
end
|
|
78
|
+
@size += 1
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Deletes a node from the beginning of the list
|
|
82
|
+
# @return nil
|
|
83
|
+
def truncate
|
|
84
|
+
if size > 1
|
|
85
|
+
@head = @head.nodo[:next_]
|
|
86
|
+
@head.nodo[:prev_] = nil
|
|
87
|
+
@size -= 1
|
|
88
|
+
elsif size == 1
|
|
89
|
+
@head = nil
|
|
90
|
+
@tail = nil
|
|
91
|
+
@size -= 1
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Deletes a node from the end of the list
|
|
96
|
+
# @return nil
|
|
97
|
+
def pop
|
|
98
|
+
if size > 1
|
|
99
|
+
@tail = @tail.nodo[:prev_]
|
|
100
|
+
@tail.nodo[:next_] = nil
|
|
101
|
+
@size -= 1
|
|
102
|
+
elsif size == 1
|
|
103
|
+
@tail = nil
|
|
104
|
+
@head = nil
|
|
105
|
+
@size -= 1
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|