alimento0100886306 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.
@@ -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.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> &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="Alimento.html" title="Alimento (module)">Alimento</a></span>
86
+
87
+
88
+
89
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Lista.html" title="Lista (class)">Lista</a></span>, <span class='object_link'><a href="Nodo.html" title="Nodo (class)">Nodo</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 Tue Nov 14 14:50:59 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>
Binary file
Binary file
@@ -0,0 +1,124 @@
1
+ require "alimento/version"
2
+ require "alimento/lista"
3
+ require "alimento/IG_fun"
4
+ require "alimento/ordenar"
5
+ require "benchmark"
6
+
7
+ module Alimento
8
+ class Alimento
9
+ attr_reader :nombre, :prt, :gluc, :lip
10
+ include Comparable
11
+
12
+ def <=>(another)
13
+ kcal <=> another.kcal
14
+ end
15
+
16
+ def initialize(nombre,prt,gluc,lip)
17
+ @nombre=nombre
18
+ @prt=prt
19
+ @gluc=gluc
20
+ @lip=lip
21
+ end
22
+
23
+ def to_s()
24
+ "#{@nombre} prt=#{@prt}g gluc=#{@gluc}g lip=#{@lip}g"
25
+ end
26
+
27
+ def kcal()
28
+ @prt*4+@gluc*4+@lip*9
29
+ end
30
+ end
31
+
32
+ class Grupoal < Alimento
33
+
34
+ def initialize(grupo,nombre,prt,gluc,lip)
35
+ super(nombre,prt,gluc,lip)
36
+ @grupo=grupo
37
+ end
38
+ def to_s
39
+ puts @grupo+"\n\t"+super.to_s
40
+ end
41
+ end
42
+
43
+ class Plato
44
+ @@talimentos=[
45
+ Alimento.new("Huevo", 14.1, 0.0, 19.5),
46
+ Alimento.new("Leche", 3.3, 4.8, 3.2),
47
+ Alimento.new("Mantequilla" , 0.7, 0.0, 83.2),
48
+ Alimento.new("Yogurt", 3.8, 4.9, 3.8),
49
+ Alimento.new("Cerdo", 21.5, 0.0, 6.3),
50
+ Alimento.new("Ternera", 21.1, 0.0, 3.1),
51
+ Alimento.new("Pollo", 20.6, 0.0, 5.6),
52
+ Alimento.new("Bacalao", 17.7, 0.0, 0.4),
53
+ Alimento.new("Atun", 21.5, 0.0, 15.5),
54
+ Alimento.new("Salmon", 19.9, 0.0, 13.6),
55
+ Alimento.new("Aceite de oliva", 0.0, 0.2, 99.6),
56
+ Alimento.new("Chocolate", 5.3, 47.0, 30.0),
57
+ Alimento.new("Azucar", 0.0, 99.8, 0.0),
58
+ Alimento.new("Arroz", 6.8, 77.7, 0.6),
59
+ Alimento.new("Lentejas", 23.5, 52.0, 1.4),
60
+ Alimento.new("Papas", 2.0, 15.4, 0.1),
61
+ Alimento.new("Tomate", 1.0, 3.5, 0.2),
62
+ Alimento.new("Cebolla", 1.3, 5.8, 0.3),
63
+ Alimento.new("Calabaza", 1.1, 4.8, 0.1),
64
+ Alimento.new("Manzana", 0.3, 12.4, 0.4),
65
+ Alimento.new("Platano", 1.2, 21.4, 0.2),
66
+ Alimento.new("Pera", 0.5, 12.7, 0.3)
67
+ ]
68
+ @@tmediciones=[
69
+ ["pieza",40],
70
+ ["taza",30],
71
+ ["cucharon",10],
72
+ ["cucharada",5],
73
+ ["pizca",2],
74
+ ["cucharilla",3]
75
+ ]
76
+
77
+ def initialize(nombre, &bloque)
78
+ @nombre=nombre
79
+ @alimentos=[]
80
+ @kcal=0
81
+ if block_given?
82
+ if bloque.arity == 1
83
+ yield self
84
+ else
85
+ instance_eval(&bloque)
86
+ end
87
+ end
88
+ end
89
+
90
+ def to_s
91
+ output = @nombre
92
+ output << "\n#{'=' * @nombre.size}\nComposición nutricional:\n"
93
+ @alimentos.each do |alimento|
94
+ output << alimento[0].to_s << " kcal=#{alimento[1]}\n"
95
+ end
96
+ output << "Valor energético total: #{@kcal}\n"
97
+ end
98
+
99
+ def vegetal(nombre, cantidad={})
100
+ aux=[]
101
+ @@talimentos.each do |alimento|
102
+ if nombre==alimento.nombre
103
+ aux << alimento
104
+ aux << alimento.kcal*cantidad[:gramos] if cantidad[:gramos]
105
+ if cantidad[:porcion]
106
+ @@tmediciones.each do |unidad|
107
+ porc=cantidad[:porcion].each_line(" ").to_a
108
+ aux << aux[0].kcal*unidad[1]*porc[0].to_f if unidad[0]=porc[1]
109
+ end
110
+ end
111
+ @alimentos << aux
112
+ @kcal+=aux[1]
113
+ end
114
+ end
115
+ end
116
+ #def fruta end
117
+ #def cereal end
118
+ #def proteina end
119
+ #def aceite end
120
+ #def agua end
121
+ end
122
+
123
+ end
124
+
@@ -0,0 +1,15 @@
1
+ def ig_func (vpruebas,vglucosas)
2
+ a=vpruebas.collect do
3
+ |pruebas| pruebas.collect do
4
+ |prueba| (prueba-pruebas[0])*5-(pruebas[pruebas.length-1]-pruebas[0])*5/(2*pruebas.length)
5
+ end.reduce('+')
6
+ end #Array con los AIBC de cada prueba
7
+ b=vglucosas.collect do
8
+ |glucosas| glucosas.collect do
9
+ |glucosa| (glucosa-glucosas[0])*5-(glucosas[glucosas.length-1]-glucosas[0])*5/(2*glucosas.length)
10
+ end.reduce('+')
11
+ end #Array con los AIBC de cada glucosa
12
+ ig=a.zip(b).collect { |v1,v2| v1*100/v2 }.reduce('+')
13
+ ig/=vpruebas.length #IG
14
+ return ig
15
+ end
@@ -0,0 +1,35 @@
1
+ class Alimento
2
+ attr_reader :nombre, :prt, :gluc, :lip
3
+ include Comparable
4
+
5
+ def <=>(another)
6
+ kcal <=> another.kcal
7
+ end
8
+
9
+ def initialize(nombre,prt,gluc,lip)
10
+ @nombre=nombre
11
+ @prt=prt
12
+ @gluc=gluc
13
+ @lip=lip
14
+ end
15
+
16
+ def to_s()
17
+ "#{@nombre} prt=#{@prt}g gluc=#{@gluc}g lip=#{@lip}g"
18
+ end
19
+
20
+ def kcal()
21
+ @prt*4+@gluc*4+@lip*9
22
+ end
23
+ end
24
+
25
+ class Grupoal < Alimento
26
+
27
+ def initialize(grupo,nombre,prt,gluc,lip)
28
+ super(nombre,prt,gluc,lip)
29
+ @grupo=grupo
30
+ end
31
+ def to_s
32
+ puts @grupo+"\n\t"+super.to_s
33
+ end
34
+ end
35
+
@@ -0,0 +1,115 @@
1
+ Nodo = Struct.new(:dato,:next_,:prev_)
2
+
3
+ class Lista
4
+
5
+ attr_reader :head, :tail
6
+ include Enumerable
7
+
8
+ def initialize()
9
+ @head=@tail=nil
10
+ end
11
+
12
+ def add_back(dato)
13
+ if dato.instance_of?Alimento
14
+ node=Nodo.new(dato,nil,nil)
15
+
16
+ @head=node if @head.nil?
17
+ node.prev_=@tail unless @tail.nil?
18
+ @tail.next_=node unless @tail.nil?
19
+ @tail=node
20
+ end
21
+ if dato.instance_of?Array
22
+ i=0
23
+ while i<dato.length do
24
+ node=Nodo.new(dato[i],nil,nil)
25
+
26
+ @head=node if @head.nil?
27
+ node.prev_=@tail unless @tail.nil?
28
+ @tail.next_=node unless @tail.nil?
29
+ @tail=node
30
+ i+=1
31
+ end
32
+ end
33
+ end
34
+
35
+ def add_front(dato)
36
+ if dato.instance_of?Alimento
37
+ node=Nodo.new(dato,nil,nil)
38
+
39
+ @tail = node if @tail.nil?
40
+ node.next_ = @head unless @head.nil?
41
+ @head.prev_ = node unless @head.nil?
42
+ @head = node
43
+ end
44
+ if dato.instance_of?Array
45
+ i=0
46
+ while i<dato.length do
47
+ @tail = node if @tail.nil?
48
+ node.next_ = @head unless @head.nil?
49
+ @head.prev_ = node unless @head.nil?
50
+ @head = node
51
+ i+=1
52
+ end
53
+ end
54
+ end
55
+
56
+ def pop_back
57
+ if (@tail==@head)&&(@tail==nil)
58
+ return nil
59
+ elsif @tail==@head
60
+ aux=@tail.dup
61
+ @tail=@head=nil
62
+ return aux
63
+ else
64
+ aux=@tail.dup
65
+ @tail=@tail.prev_
66
+ @tail.next_=nil
67
+ aux.prev_=nil
68
+ return aux
69
+ end
70
+ end
71
+
72
+ def pop_front
73
+ if (@tail==@head)&&(@tail==nil)
74
+ return nil
75
+ elsif @tail==@head
76
+ aux=@head.dup
77
+ @head=@tail=nil
78
+ return aux
79
+ else
80
+ aux=@head.dup
81
+ @head=@head.next_
82
+ @head.prev_=nil
83
+ aux.next_=nil
84
+ return aux
85
+ end
86
+ end
87
+
88
+ def mostrar
89
+ str= ""
90
+ aux=@head
91
+ while aux!=nil do
92
+ str+="\t"+aux.dato.to_s+"\n"
93
+ aux=aux.next_
94
+ end
95
+ str
96
+ end
97
+
98
+ def [] (index)
99
+ i=0
100
+ aux=@head
101
+ while i<index&&aux!=nil do
102
+ i+=1
103
+ aux=aux.next_
104
+ end
105
+ aux
106
+ end
107
+
108
+ def each
109
+ aux=@head
110
+ while aux!=nil do
111
+ yield aux.dato
112
+ aux=aux.next_
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,28 @@
1
+ def ord_for (valimentos)
2
+
3
+ for i in 0...valimentos.length
4
+ max=valimentos[i]
5
+ for j in i...valimentos.length
6
+ if max.kcal < valimentos[j].kcal
7
+ max,valimentos[j]=valimentos[j],max
8
+ end
9
+ end
10
+ valimentos[i]=max
11
+ end
12
+ valimentos
13
+
14
+ end
15
+ def ord_each (valimentos) #Buscar otra forma
16
+
17
+ valimentos.each_index do
18
+ |i| valimentos.each_index do
19
+ |j| if valimentos[j].kcal<valimentos[i].kcal
20
+ valimentos[i],valimentos[j]=valimentos[j],valimentos[i]
21
+ end
22
+ end
23
+ end
24
+
25
+ end
26
+ def ord_sort (valimentos)
27
+ valimentos.sort.reverse {|x,y| y.kcal<=>x.kcal }
28
+ end
@@ -0,0 +1,70 @@
1
+ class Plato
2
+ @@talimentos=[
3
+ Alimento.new("Huevo frito", 14.1, 0.0, 19.5),
4
+ Alimento.new("Leche", 3.3, 4.8, 3.2),
5
+ Alimento.new("Mantequilla" , 0.7, 0.0, 83.2),
6
+ Alimento.new("Yogurt", 3.8, 4.9, 3.8),
7
+ Alimento.new("Cerdo", 21.5, 0.0, 6.3),
8
+ Alimento.new("Ternera", 21.1, 0.0, 3.1),
9
+ Alimento.new("Pollo", 20.6, 0.0, 5.6),
10
+ Alimento.new("Bacalao", 17.7, 0.0, 0.4),
11
+ Alimento.new("Atun", 21.5, 0.0, 15.5),
12
+ Alimento.new("Salmon", 19.9, 0.0, 13.6),
13
+ Alimento.new("Aceite de oliva", 0.0, 0.2, 99.6),
14
+ Alimento.new("Chocolate", 5.3, 47.0, 30.0),
15
+ Alimento.new("Azucar", 0.0, 99.8, 0.0),
16
+ Alimento.new("Arroz", 6.8, 77.7, 0.6),
17
+ Alimento.new("Lentejas", 23.5, 52.0, 1.4),
18
+ Alimento.new("Papas", 2.0, 15.4, 0.1),
19
+ Alimento.new("Tomate", 1.0, 3.5, 0.2),
20
+ Alimento.new("Cebolla", 1.3, 5.8, 0.3),
21
+ Alimento.new("Calabaza", 1.1, 4.8, 0.1),
22
+ Alimento.new("Manzana", 0.3, 12.4, 0.4),
23
+ Alimento.new("Platanos", 1.2, 21.4, 0.2),
24
+ Alimento.new("Pera", 0.5, 12.7, 0.3)
25
+ ]
26
+ @@tmediciones=[
27
+ ["pieza",40],
28
+ ["taza",30],
29
+ ["cucharon",10],
30
+ ["cucharada",5],
31
+ ["pizca",2],
32
+ ["cucharilla",3]
33
+ ]
34
+
35
+ def initialize(nombre, &bloque)
36
+ @nombre=nombre
37
+ @alimentos=[]
38
+ @kcal=0
39
+ if block_given?
40
+ if block.arity == 1
41
+ yield self
42
+ else
43
+ instance_eval(&bloque)
44
+ end
45
+ end
46
+ end
47
+
48
+ def to_s
49
+ output = @nombre
50
+ output << "\n#{'=' * @nombre.size}\nComposición nutricional:\n"
51
+ @alimentos.each do |alimento|
52
+ output << alimento[0].to_s << " kcal=#{alimento[1]}\n"
53
+ end
54
+ output << "Valor energético total: #{@kcal}\n"
55
+ end
56
+
57
+ def vegetal(nombre, cantidad={})
58
+ aux=[]
59
+ @@talimentos.each{|alimento| aux << alimento if nombre=alimento.aux }
60
+ aux << alimento.kcal*cantidad[:gramos] if cantidad[:gramos]
61
+ @@tmediciones.each{|unidad| aux << aux[0].kcal*unidad[1] if unidad[0]=cantidad[:porcion] } if cantidad[:porcion]
62
+
63
+ @alimentos << aux
64
+ end
65
+ #def fruta end
66
+ #def cereal end
67
+ #def proteina end
68
+ #def aceite end
69
+ #def agua end
70
+ end