nutritag 0.1.1

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.16
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="Nutritag.html" title="Nutritag (module)">Nutritag</a></span>
86
+
87
+
88
+
89
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="Anthro_data.html" title="Anthro_data (class)">Anthro_data</a></span>, <span class='object_link'><a href="Etiqueta.html" title="Etiqueta (class)">Etiqueta</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="Patient.html" title="Patient (class)">Patient</a></span>, <span class='object_link'><a href="Person.html" title="Person (class)">Person</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 27 02:51:57 2018 by
106
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
107
+ 0.9.16 (ruby-2.5.1).
108
+ </div>
109
+
110
+ </div>
111
+ </body>
112
+ </html>
@@ -0,0 +1,8 @@
1
+ require "nutritag/version"
2
+ require "nutritag/label"
3
+ require "nutritag/list"
4
+ require "nutritag/person"
5
+
6
+ module Nutritag
7
+ #Code
8
+ end
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+ # Autor:: Alberto Dorta Darias
3
+ # Web:: https://github.com/alu0100785630
4
+ #
5
+ # == Ejemplo
6
+ #
7
+ # Objetivos:
8
+ # - Información de una etiqueta nutricional
9
+ # - Cáclulo del valor nutricional
10
+ # - Cálculo por porciones
11
+ # - Cálculo del IR
12
+ #
13
+ # === Clase Etiqueta
14
+ #
15
+ # Definición de la clase *Etiqueta* compuesta por:
16
+ # * metodo initialize
17
+ # * metodo conver_kJ
18
+ # * metodo conver_kcal
19
+ # * metodo portion_calc
20
+ # * metodo ir_calc
21
+ # * metodo <=>
22
+ # * metodo to_s
23
+
24
+
25
+ class Etiqueta
26
+
27
+ attr_reader :nombre, :fat, :sat_fat, :carbs, :sugar, :proteins, :salt, :v_energetic, :portion, :p, :ir, :ir_percent
28
+
29
+ include Comparable
30
+
31
+ # Método initialize => Se crea la etiqueta
32
+ #
33
+ # @param nombre [String] nombre del alimento
34
+ # @param fat [Numeric] grasas
35
+ # @param sat_fat [Numeric] grasas saturadas
36
+ # @param carbs [Numeric] hidratos de carbono
37
+ # @param sugar [Numeric] azúcares
38
+ # @param proteins [Numeric] proteinas
39
+ # @param salt [Numeric] sal
40
+
41
+ def initialize(nombre, fat, sat_fat, carbs, sugar, proteins, salt)
42
+
43
+ @nombre=nombre
44
+ @fat=fat
45
+ @sat_fat=sat_fat
46
+ @carbs=carbs
47
+ @sugar=sugar
48
+ @proteins=proteins
49
+ @salt=salt
50
+ @v_energetic=[self.conver_kJ,self.conver_kcal]
51
+ @portion=0.35
52
+ @p=self.portion_calc
53
+ @ir=[8400.0,2000.0,70.0,20.0,260.0,90.0,50.0,6.0]
54
+ @ir_percent=self.ir_calc
55
+
56
+ end
57
+
58
+ # Método conver_kJ => Conversión de los diferentes nutrientes
59
+ #
60
+ # @return [Numeric] devuelve el valor energético en kJ
61
+ def conver_kJ
62
+ (37.0*@fat) + (17.0*@carbs) + (17.0*@proteins) + (25.0*@salt)
63
+ end
64
+
65
+ # Método conver_kcal => Conversión de los diferentes nutrientes
66
+ #
67
+ # @return [Numeric] devuelve el valor energético en kcal
68
+ def conver_kcal
69
+ (9.0*@fat) + (4.0*@carbs) + (4.0*@proteins) + (6.0*@salt)
70
+ end
71
+
72
+ # Método portion_calc => Calcula la porción
73
+ #
74
+ # @return [Array] devuelve un array con los nutrientes por porción
75
+ def portion_calc
76
+ [(self.conver_kJ*@portion).round(1),(self.conver_kcal*@portion).round(1),(@fat*@portion).round(1),(@sat_fat*@portion).round(1),(@carbs*@portion).round(1),(@sugar*@portion).round(1),(@proteins*@portion).round(1),(@salt*@portion).round(1)]
77
+ end
78
+
79
+ # Método ir_calc => Calcula el IR
80
+ #
81
+ # @return [Array] devuele la ingesta recomendada
82
+ def ir_calc
83
+ [((@v_energetic[0]/@ir[0]).round(1)*100),((@v_energetic[1]/@ir[1]).round(1)*100),((@fat/@ir[2]).round(1)*100),((@sat_fat/@ir[3]).round(1)*100),((@carbs/@ir[4]).round(1)*100),((@sugar/@ir[5]).round(1)*100),((@proteins/@ir[6]).round(1)*100),((@salt/@ir[7]).round(1)*100)]
84
+ end
85
+
86
+ #Método del módulo comparable
87
+ def <=>(other)
88
+ return nil unless other.is_a?Etiqueta
89
+ conver_kcal <=> other.conver_kcal
90
+ end
91
+
92
+ # Método to_s => Imprime por pantalla
93
+ #
94
+ # @return [String] devuelve la etiqueta formateada
95
+ def to_s
96
+ puts "Nombre del Producto: #{@nombre}"
97
+ puts "\t\t\t\t\tPor 100g| Por porción de #{@portion*100}g | IR (por 100g) |"
98
+ puts "Valor energético: \t #{@v_energetic[0]}(kJ)/#{@v_energetic[1]}(kcal)| #{@p[0]}(kJ)/ #{@p[1]}(kcal)|\t#{@ir_percent[0]}%\t|"
99
+ puts "Grasas \t\t\t\t\t#{@fat} g\t|\t\t#{@p[2]} g\t|\t#{@ir_percent[2]}%\t|"
100
+ puts "de las cuales saturadas: \t\t#{@sat_fat} g\t|\t\t#{@p[3]} g\t|\t#{@ir_percent[3]}%\t|"
101
+ puts "Hidratos \t\t\t\t#{@carbs} g\t|\t\t#{@p[4]} g\t|\t#{@ir_percent[4]}%\t|"
102
+ puts "de los cuales azúcares: \t\t#{@sugar} g\t|\t\t#{@p[5]} g\t|\t#{@ir_percent[5]}%\t|"
103
+ puts "Proteínas: \t\t\t\t#{@proteins} g\t|\t\t#{@p[6]} g\t|\t#{@ir_percent[6]}%\t|"
104
+ puts "Sal: \t\t\t\t\t#{@salt} g\t|\t\t#{@p[7]} g\t|\t#{@ir_percent[7]}%\t|"
105
+ end
106
+
107
+ end
@@ -0,0 +1,110 @@
1
+ require './lib/nutritag/person.rb'
2
+ Node = Struct.new(:value, :next, :prev)
3
+
4
+ # Clase *List*
5
+ #
6
+ # Representa las funcionalidades de una Lista Doblemente Enlazada
7
+ class List
8
+
9
+ attr_reader :head, :tail
10
+
11
+ include Enumerable
12
+
13
+ # Se inicializa la lista con un head y un tail
14
+ def initialize
15
+ @head=nil
16
+ @tail=nil
17
+ end
18
+
19
+ # El método empty indica que la lista está vacía
20
+ def empty
21
+ @head==nil
22
+ @tail==nil
23
+ end
24
+
25
+ # Se introducen elementos en la lista
26
+ #
27
+ # @param value [Type] se le pasa un elemento a insertar
28
+ # @return [Type] devuele una lista
29
+ def insert(value)
30
+
31
+ node = Node.new(value, nil, nil)
32
+
33
+ if (@head==nil&&@tail==nil)
34
+ @head=node
35
+ @tail=node
36
+ else
37
+ @tail.next=node
38
+ #node.prev=@tail
39
+ @tail=node
40
+ end
41
+
42
+ end
43
+
44
+ # Se extraen elementos de la lista
45
+ def extract
46
+ if (@head==nil&&@tail==nil)
47
+ return nil
48
+ else
49
+ aux = @head
50
+ @head.next = @head
51
+ @head.prev = nil unless @head.nil?
52
+ aux.next=nil
53
+ aux
54
+ end
55
+
56
+ end
57
+
58
+ # Se imprime la lista por pantalla
59
+ #
60
+ # @return [String] devuele la lista formateada
61
+ def to_s
62
+ n=@head
63
+ puts "{"
64
+ while (n!=nil)
65
+ "#{n.value.to_s}"
66
+ n=n.next
67
+ end
68
+ " }"
69
+ end
70
+ # Método mixin del módulo Enumerable para poder enumerar
71
+ def each
72
+ aux = @head
73
+ while (aux != nil)
74
+ yield aux.value
75
+ aux = aux.next
76
+ end
77
+ end
78
+
79
+ # Clasificación de pacientes según su IM
80
+ #
81
+ # @param lista [Type] se introduce una lista
82
+ # @return [Type] devuelve otra lista
83
+ def sort_imc(lista)
84
+ obesidad = List.new()
85
+ normalidad = List.new()
86
+
87
+ node = lista.head
88
+
89
+ while !(node.nil?)
90
+ if node.value.imc >= 30
91
+ obesidad.insert(node.value)
92
+ else
93
+ normalidad.insert(node.value)
94
+ end
95
+ node = node.next
96
+ end
97
+
98
+ puts "Pacientes con Obesidad"
99
+ obesidad.to_s
100
+ puts "Pacientes con Normalidad"
101
+ normalidad.to_s
102
+ end
103
+ end
104
+
105
+
106
+
107
+
108
+
109
+
110
+
@@ -0,0 +1,208 @@
1
+
2
+ class Menu
3
+ attr_accessor :day, :comp, :title, :ingesta, :desayuno, :almuerzo, :cena, :v_energetic
4
+
5
+ def initialize(day, comp, &block)
6
+ @day=day
7
+ @comp=comp
8
+ @title
9
+ @ingesta=[]
10
+ @desayuno=[]
11
+ @almuerzo=[]
12
+ @cena=[]
13
+ @v_energetic=0
14
+ @ve_total=0
15
+ @aux=[]
16
+ @nut= [" ", "Cantidad", "Gramos", "Grasas", "Hidratos", "Proteínas", "Fibra", "Sal", "V. Energético"]
17
+
18
+ if block_given?
19
+ if block.arity == 1
20
+ yield self
21
+ else
22
+ instance_eval(&block)
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ def to_s
29
+ puts "\n"
30
+ output = @day.rjust(20)
31
+ output << "#{' '*40} #{@comp}"
32
+ output << "\n#{'='*155}"
33
+ output << "\n#{@title}\n"
34
+
35
+ @nut.each do |i|
36
+ if( @aux.include?(i) == false)
37
+ @aux.push(i)
38
+ end
39
+ output << "#{i.ljust(17)}"
40
+ end
41
+ @aux.clear
42
+
43
+ output << "\n\nDesayuno"
44
+ @desayuno.each do |i|
45
+ if( @aux.include?(i) == false)
46
+ @aux.push(i)
47
+ end
48
+ output << "#{i.ljust(17)}"
49
+ end
50
+ @aux.clear
51
+
52
+ output << "\n\nAlmuerzo"
53
+ @almuerzo.each do |i|
54
+ if( @aux.include?(i) == false)
55
+ @aux.push(i)
56
+ end
57
+ output << "#{i.ljust(17)}"
58
+ end
59
+ @aux.clear
60
+
61
+ output << "\n\nCena"
62
+ @cena.each do |i|
63
+ if( @aux.include?(i) == false)
64
+ @aux.push(i)
65
+ end
66
+ output << "#{i.ljust(17)}"
67
+ end
68
+
69
+ output << "\n\n#{'-'*155}"
70
+ output << "\nIngesta -> #{@ingesta.join(' ')}\n"
71
+ output << "\nVALOR ENERGÉTICO TOTAL: #{@ve_total.round(2)} kcal"
72
+
73
+
74
+ output
75
+ end
76
+
77
+ def title (name)
78
+ @title = name
79
+ end
80
+
81
+ def ingesta(options={})
82
+ @ingesta << "Min:#{options[:min]} " if options[:min]
83
+ @ingesta << "Max:#{options[:max]}" if options[:max]
84
+ @ingesta
85
+ end
86
+
87
+ def desayuno(options={})
88
+ @desayuno << "\n'#{options[:descripcion]}'" if options[:descripcion]
89
+ @desayuno << if options[:porcion] then "#{options[:porcion]}" else "0.00" end
90
+ @desayuno << if options[:gramos] then "#{options[:gramos]}" else "0.00" end
91
+ @desayuno << if options[:grasas] then "#{options[:grasas]}" else "0.00" end
92
+ @desayuno << if options[:carbohidratos] then "#{options[:carbohidratos]}" else "0.00" end
93
+ @desayuno << if options[:proteinas] then "#{options[:proteinas]}" else "0.00" end
94
+ @desayuno << if options[:fibra] then "#{options[:fibra]}" else "0.00" end
95
+ @desayuno << if options[:sal] then "#{options[:sal]}" else "0.00" end
96
+ @v_energetic = ((options[:grasas]*9)+(options[:carbohidratos]*9)+(options[:proteinas]*4)).round(2)
97
+
98
+ if options[:fibra] then
99
+ @v_energetic +=(options[:fibra]*2).round
100
+ end
101
+ if options[:sal] then
102
+ @v_energetic +=(options[:sal]*6).round
103
+ end
104
+
105
+ @ve_total+=@v_energetic
106
+ @desayuno << "#{@v_energetic}"
107
+ @desayuno
108
+ end
109
+
110
+ def almuerzo(options={})
111
+ @almuerzo << "\n'#{options[:descripcion]}'" if options[:descripcion]
112
+ @almuerzo << if options[:porcion] then "#{options[:porcion]}" else "0.00" end
113
+ @almuerzo << if options[:gramos] then "#{options[:gramos]}" else "0.00" end
114
+ @almuerzo << if options[:grasas] then "#{options[:grasas]}" else "0.00" end
115
+ @almuerzo << if options[:carbohidratos] then "#{options[:carbohidratos]}" else "0.00" end
116
+ @almuerzo << if options[:proteinas] then "#{options[:proteinas]}" else "0.00" end
117
+ @almuerzo << if options[:fibra] then "#{options[:fibra]}" else "0.00" end
118
+ @almuerzo << if options[:sal] then "#{options[:sal]}" else "0.00" end
119
+ @v_energetic=((options[:grasas]*9)+(options[:carbohidratos]*4)+(options[:proteinas]*4)).round(2)
120
+
121
+ if options[:fibra] then
122
+ @v_energetic +=(options[:fibra]*2).round
123
+ end
124
+ if options[:sal] then
125
+ @v_energetic +=(options[:sal]*6).round
126
+ end
127
+
128
+ @ve_total+=@v_energetic
129
+ @almuerzo << "#{@v_energetic}"
130
+ @aalmuerzo
131
+ end
132
+
133
+ def cena(options={})
134
+ @cena << "\n'#{options[:descripcion]}'" if options[:descripcion]
135
+ @cena << if options[:porcion] then "#{options[:porcion]}" else "0.00" end
136
+ @cena << if options[:gramos] then "#{options[:gramos]}" else "0.00" end
137
+ @cena << if options[:grasas] then "#{options[:grasas]}" else "0.00" end
138
+ @cena << if options[:carbohidratos] then "#{options[:carbohidratos]}" else "0.00" end
139
+ @cena << if options[:proteinas] then "#{options[:proteinas]}" else "0.00" end
140
+ @cena << if options[:fibra] then "#{options[:fibra]}" else "0.00" end
141
+ @cena << if options[:sal] then "#{options[:sal]}" else "0.00" end
142
+ @v_energetic = ((options[:grasas]*9)+(options[:carbohidratos]*4)+(options[:proteinas]*4)).round(2)
143
+
144
+ if options[:fibra] then
145
+ @v_energetic +=(options[:fibra]*2).round
146
+ end
147
+ if options[:sal] then
148
+ @v_energetic +=(options[:sal]*6).round
149
+ end
150
+
151
+ @ve_total+=@v_energetic
152
+ @cena << "#{@v_energetic}"
153
+ @cena
154
+ end
155
+
156
+ end
157
+
158
+ menu = Menu.new("Miércoles", "Composición Nutricional") do
159
+
160
+ title = "Low Calories"
161
+ ingesta :min => 30, :max => 35
162
+ desayuno :descripcion => "Pan Integral",
163
+ :porcion => "1 rodaja",
164
+ :gramos => 100,
165
+ :grasas => 3.3,
166
+ :carbohidratos => 54.0,
167
+ :proteinas => 11.0,
168
+ :fibra => 2.3,
169
+ :sal => 0.06
170
+ desayuno :descripcion => "Actimel",
171
+ :porcion => "1 porción",
172
+ :gramos => 100,
173
+ :grasas => 3.4,
174
+ :carbohidratos => 4.4,
175
+ :proteinas => 3.6,
176
+ :sal => 0.05
177
+ almuerzo :descripcion => "Arroz",
178
+ :porcion => "1 taza",
179
+ :gramos => 100,
180
+ :grasas => 0.9,
181
+ :carbohidratos => 81.6,
182
+ :proteinas => 6.67,
183
+ :fibra => 1.4,
184
+ :sal => 0.04
185
+ almuerzo :descripcion => "Lentejas",
186
+ :porcion => "1/2 cucharón",
187
+ :grasas => 0.4,
188
+ :carbohidratos => 20.0,
189
+ :proteinas => 9.0,
190
+ :fibra => 8.0,
191
+ :sal => 0.02
192
+ almuerzo :descripcion => "Naranja",
193
+ :porcion => "1 pieza",
194
+ :gramos => 100,
195
+ :grasas => 0.12,
196
+ :carbohidratos => 11.75,
197
+ :proteinas => 0.94,
198
+ :fibra => 2.4
199
+ cena :descripcion => "Leche Entera",
200
+ :porcion => "1 vaso",
201
+ :gramos => 100,
202
+ :grasas => 3.6,
203
+ :carbohidratos => 4.6,
204
+ :proteinas => 3.1,
205
+ :sal => 0.13
206
+ end
207
+
208
+ puts menu