tddAlimentos 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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +13 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +7 -0
  6. data/Gemfile +5 -0
  7. data/Gemfile.lock +101 -0
  8. data/Guardfile +83 -0
  9. data/README.md +46 -0
  10. data/Rakefile +6 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/docs/Alimento.html +428 -0
  14. data/docs/Gemfile.html +98 -0
  15. data/docs/Gemfile_lock.html +183 -0
  16. data/docs/Guardfile.html +166 -0
  17. data/docs/List.html +682 -0
  18. data/docs/Object.html +128 -0
  19. data/docs/Plato.html +607 -0
  20. data/docs/PlatoAmbiental.html +492 -0
  21. data/docs/README_md.html +126 -0
  22. data/docs/Rakefile.html +100 -0
  23. data/docs/TddAlimentos.html +110 -0
  24. data/docs/TddAlimentos/Error.html +103 -0
  25. data/docs/bin/setup.html +100 -0
  26. data/docs/created.rid +17 -0
  27. data/docs/css/fonts.css +167 -0
  28. data/docs/css/rdoc.css +590 -0
  29. data/docs/fonts/Lato-Light.ttf +0 -0
  30. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  31. data/docs/fonts/Lato-Regular.ttf +0 -0
  32. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  33. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  34. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  35. data/docs/images/add.png +0 -0
  36. data/docs/images/arrow_up.png +0 -0
  37. data/docs/images/brick.png +0 -0
  38. data/docs/images/brick_link.png +0 -0
  39. data/docs/images/bug.png +0 -0
  40. data/docs/images/bullet_black.png +0 -0
  41. data/docs/images/bullet_toggle_minus.png +0 -0
  42. data/docs/images/bullet_toggle_plus.png +0 -0
  43. data/docs/images/date.png +0 -0
  44. data/docs/images/delete.png +0 -0
  45. data/docs/images/find.png +0 -0
  46. data/docs/images/loadingAnimation.gif +0 -0
  47. data/docs/images/macFFBgHack.png +0 -0
  48. data/docs/images/package.png +0 -0
  49. data/docs/images/page_green.png +0 -0
  50. data/docs/images/page_white_text.png +0 -0
  51. data/docs/images/page_white_width.png +0 -0
  52. data/docs/images/plugin.png +0 -0
  53. data/docs/images/ruby.png +0 -0
  54. data/docs/images/tag_blue.png +0 -0
  55. data/docs/images/tag_green.png +0 -0
  56. data/docs/images/transparent.png +0 -0
  57. data/docs/images/wrench.png +0 -0
  58. data/docs/images/wrench_orange.png +0 -0
  59. data/docs/images/zoom.png +0 -0
  60. data/docs/index.html +117 -0
  61. data/docs/js/darkfish.js +161 -0
  62. data/docs/js/jquery.js +4 -0
  63. data/docs/js/navigation.js +141 -0
  64. data/docs/js/navigation.js.gz +0 -0
  65. data/docs/js/search.js +109 -0
  66. data/docs/js/search_index.js +1 -0
  67. data/docs/js/search_index.js.gz +0 -0
  68. data/docs/js/searcher.js +229 -0
  69. data/docs/js/searcher.js.gz +0 -0
  70. data/docs/table_of_contents.html +307 -0
  71. data/docs/tddAlimentos_gemspec.html +133 -0
  72. data/lib/tddAlimentos.rb +12 -0
  73. data/lib/tddAlimentos/alimento.rb +56 -0
  74. data/lib/tddAlimentos/lista.rb +172 -0
  75. data/lib/tddAlimentos/menu.rb +51 -0
  76. data/lib/tddAlimentos/plato.rb +125 -0
  77. data/lib/tddAlimentos/platoAmbiental.rb +108 -0
  78. data/lib/tddAlimentos/platoDSL.rb +94 -0
  79. data/lib/tddAlimentos/version.rb +3 -0
  80. data/tddAlimentos.gemspec +39 -0
  81. metadata +249 -0
@@ -0,0 +1,133 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta charset="UTF-8">
6
+
7
+ <title>tddAlimentos.gemspec - RDoc Documentation</title>
8
+
9
+ <script type="text/javascript">
10
+ var rdoc_rel_prefix = "./";
11
+ var index_rel_prefix = "./";
12
+ </script>
13
+
14
+ <script src="./js/jquery.js"></script>
15
+ <script src="./js/darkfish.js"></script>
16
+
17
+ <link href="./css/fonts.css" rel="stylesheet">
18
+ <link href="./css/rdoc.css" rel="stylesheet">
19
+
20
+
21
+
22
+
23
+ <body id="top" role="document" class="file">
24
+ <nav role="navigation">
25
+ <div id="project-navigation">
26
+ <div id="home-section" role="region" title="Quick navigation" class="nav-section">
27
+ <h2>
28
+ <a href="./index.html" rel="home">Home</a>
29
+ </h2>
30
+
31
+ <div id="table-of-contents-navigation">
32
+ <a href="./table_of_contents.html#pages">Pages</a>
33
+ <a href="./table_of_contents.html#classes">Classes</a>
34
+ <a href="./table_of_contents.html#methods">Methods</a>
35
+ </div>
36
+ </div>
37
+
38
+ <div id="search-section" role="search" class="project-section initially-hidden">
39
+ <form action="#" method="get" accept-charset="utf-8">
40
+ <div id="search-field-wrapper">
41
+ <input id="search-field" role="combobox" aria-label="Search"
42
+ aria-autocomplete="list" aria-controls="search-results"
43
+ type="text" name="search" placeholder="Search" spellcheck="false"
44
+ title="Type to search, Up and Down to navigate, Enter to load">
45
+ </div>
46
+
47
+ <ul id="search-results" aria-label="Search Results"
48
+ aria-busy="false" aria-expanded="false"
49
+ aria-atomic="false" class="initially-hidden"></ul>
50
+ </form>
51
+ </div>
52
+
53
+ </div>
54
+
55
+
56
+
57
+ <div id="project-metadata">
58
+ <div id="fileindex-section" class="nav-section">
59
+ <h3>Pages</h3>
60
+
61
+ <ul class="link-list">
62
+
63
+ <li><a href="./Gemfile.html">Gemfile</a>
64
+
65
+ <li><a href="./Gemfile_lock.html">Gemfile.lock</a>
66
+
67
+ <li><a href="./Guardfile.html">Guardfile</a>
68
+
69
+ <li><a href="./README_md.html">README</a>
70
+
71
+ <li><a href="./Rakefile.html">Rakefile</a>
72
+
73
+ <li><a href="./bin/setup.html">setup</a>
74
+
75
+ <li><a href="./tddAlimentos_gemspec.html">tddAlimentos.gemspec</a>
76
+
77
+ </ul>
78
+ </div>
79
+
80
+ </div>
81
+ </nav>
82
+
83
+ <main role="main" aria-label="Page tddAlimentos.gemspec">
84
+
85
+ <p>lib = File.expand_path(“lib”, __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require “tddAlimentos/version”</p>
86
+
87
+ <p>Gem::Specification.new do |spec|</p>
88
+
89
+ <pre class="ruby"><span class="ruby-identifier">spec</span>.<span class="ruby-identifier">name</span> = <span class="ruby-string">&quot;tddAlimentos&quot;</span>
90
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">version</span> = <span class="ruby-constant">TddAlimentos</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span>
91
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">authors</span> = [<span class="ruby-string">&quot;Himar Barquin&quot;</span>]
92
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">email</span> = [<span class="ruby-string">&quot;alu0101119373@ull.edu.es&quot;</span>]
93
+
94
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">summary</span> = <span class="ruby-string">%q{Contiene la clase Alimento, que describe un alimento.}</span>
95
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">homepage</span> = <span class="ruby-string">&quot;https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373&quot;</span>
96
+
97
+ <span class="ruby-comment">#spec.metadata[&quot;allowed_push_host&quot;] = &quot;Set to &#39;http://mygemserver.com&#39;&quot;</span>
98
+
99
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">metadata</span>[<span class="ruby-string">&quot;homepage_uri&quot;</span>] = <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">homepage</span>
100
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">metadata</span>[<span class="ruby-string">&quot;source_code_uri&quot;</span>] = <span class="ruby-string">&quot;https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373&quot;</span>
101
+ <span class="ruby-comment">#spec.metadata[&quot;changelog_uri&quot;] = &quot;TODO: Put your gem&#39;s CHANGELOG.md URL here.&quot;</span>
102
+
103
+ <span class="ruby-comment"># Specify which files should be added to the gem when it is released.</span>
104
+ <span class="ruby-comment"># The `git ls-files -z` loads the files in the RubyGem that have been added into git.</span>
105
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">files</span> = <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-string">&#39;..&#39;</span>, <span class="ruby-keyword">__FILE__</span>)) <span class="ruby-keyword">do</span>
106
+ <span class="ruby-string">`git ls-files -z`</span>.<span class="ruby-identifier">split</span>(<span class="ruby-string">&quot;\x0&quot;</span>).<span class="ruby-identifier">reject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp">%r{^(test|spec|features)/}</span>) }
107
+ <span class="ruby-keyword">end</span>
108
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">bindir</span> = <span class="ruby-string">&quot;exe&quot;</span>
109
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">executables</span> = <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">files</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">%r{^exe/}</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">f</span>) }
110
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">require_paths</span> = [<span class="ruby-string">&quot;lib&quot;</span>]
111
+
112
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;bundler&quot;</span>, <span class="ruby-string">&quot;~&gt; 2.0&quot;</span>
113
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;rake&quot;</span>, <span class="ruby-string">&quot;~&gt; 10.0&quot;</span>
114
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;rspec&quot;</span>, <span class="ruby-string">&quot;~&gt; 3.0&quot;</span>
115
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;guard&quot;</span>
116
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;guard-rspec&quot;</span>
117
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;guard-bundler&quot;</span>
118
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;markup&quot;</span>
119
+ <span class="ruby-identifier">spec</span>.<span class="ruby-identifier">add_development_dependency</span> <span class="ruby-string">&quot;rdoc&quot;</span>
120
+ </pre>
121
+
122
+ <p>end</p>
123
+
124
+ </main>
125
+
126
+
127
+
128
+ <footer id="validator-badges" role="contentinfo">
129
+ <p><a href="https://validator.w3.org/check/referer">Validate</a>
130
+ <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.1.0.
131
+ <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
132
+ </footer>
133
+
@@ -0,0 +1,12 @@
1
+ require "tddAlimentos/version"
2
+ require "tddAlimentos/alimento"
3
+ require "tddAlimentos/lista.rb"
4
+ require "tddAlimentos/plato.rb"
5
+ require "tddAlimentos/platoAmbiental.rb"
6
+ require "tddAlimentos/platoDSL.rb"
7
+ require "tddAlimentos/menu.rb"
8
+
9
+ module TddAlimentos
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,56 @@
1
+ require 'markup'
2
+
3
+ # = alimento.rb
4
+ #
5
+ # Autor:: Himar Manuel Barquín Carrasco
6
+ # Web:: https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373
7
+ #
8
+ # == Descripción
9
+ #
10
+ # Clase que representa un alimento, con la información de las proteínas, carbohidratos, lípidos, gases de efecto invernadero y metros cuadrados de tierra consumida que provoca producir el alimento.
11
+ # == Métodos
12
+ # * to_s
13
+ # * energetic_value
14
+ # * <=>
15
+ class Alimento
16
+
17
+ include Comparable
18
+
19
+ attr_reader :name, :protein, :carbohydrates, :lipids, :gei, :terrain
20
+
21
+ # Constructor de la clase Alimento
22
+ # Parámetros::
23
+ # * name: Nombre del alimento
24
+ # * protein: Proteínas del alimento
25
+ # * carbohydrates: Carbohidratos del alimento
26
+ # * lipids: Lípidos del alimento
27
+ # * gei: Gases de Efecto Invernadero que se producen al producir el alimento
28
+ # * terrain: Terreno que se usa para la producción del alimento
29
+ def initialize (name, protein, carbohydrates, lipids, gei, terrain)
30
+ @name, @protein, @carbohydrates, @lipids, @gei, @terrain = name, protein, carbohydrates, lipids, gei, terrain
31
+ end
32
+
33
+ # Imprime la información del alimento
34
+ # Devuelve::
35
+ # Cadena de texto con la información del alimento
36
+ def to_s
37
+ "Nombre: #{@name}\nProteínas (g): #{@protein}\nCarbohidratos (g): #{@carbohydrates}\nLípidos (g): #{@lipids}\nGEI (kgCO2eq): #{@gei}\nTerreno (m2 año): #{@terrain}\n"
38
+ end
39
+
40
+ # Calcula el valor energético del alimento
41
+ # Devuelve::
42
+ # Valor decimal con el valor energético
43
+ def energetic_value
44
+ 4 * @protein + 4 * @carbohydrates + 9 * @lipids
45
+ end
46
+
47
+ # Nos permite comparar alimentos por su valor energético
48
+ # Parámetros::
49
+ # * another: Otro plato que se compara con el invocante
50
+ # Devuelve::
51
+ # 'true' si la comparación es verdadera. 'false' en otro caso
52
+ def <=> (another)
53
+ self.energetic_value <=> another.energetic_value
54
+ end
55
+
56
+ end
@@ -0,0 +1,172 @@
1
+ require 'markup'
2
+
3
+ # = Node
4
+ #
5
+ # Autor:: Himar Manuel Barquín Carrasco
6
+ # Web:: https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373
7
+ #
8
+ # == Descripción
9
+ #
10
+ # Estructura que representa un nodo. Contiene la información del valor que almacena, el nodo siguiente y el nodo previo
11
+ Node = Struct.new(:value, :next, :prev)
12
+
13
+ # = lista.rb
14
+ #
15
+ # Autor:: Himar Manuel Barquín Carrasco
16
+ # Web:: https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373
17
+ #
18
+ # == Descripción
19
+ #
20
+ # Clase que representa una lista, utilizando una estrucutura llamada *Node* que contiene la información del valor de ese nodo, junto a su nodo predecesor y su nodo antecesor. Además, la lista dispone de una cabeza, una cola, y un valor que representa el tamaño. De esta manera, la clase List es tipo LIFO (cola).
21
+ #
22
+ # == Métodos
23
+ # * empty?
24
+ # * to_s
25
+ # * to_rs
26
+ # * insert
27
+ # * insert_tail
28
+ # * insert_more
29
+ # * extract
30
+ # * extract_tail
31
+ # * each
32
+
33
+ class List
34
+
35
+ include Enumerable
36
+
37
+ attr_reader :head, :tail, :size
38
+
39
+ # Constructor de la clase List
40
+ def initialize
41
+ @head = nil
42
+ @tail = nil
43
+ @size = 0
44
+ end
45
+
46
+ # Comprueba si la lista está vacía
47
+ # Devuelve::
48
+ # 'true' si la lista está vacía. 'false' en otro caso
49
+ def empty?
50
+ @size == 0
51
+ end
52
+
53
+ # Muestra la lista desde la cabeza
54
+ # Devuelve::
55
+ # Cadena de texto con los elementos de la lista
56
+ def to_s
57
+ str = "["
58
+ aux = @head
59
+ while aux != nil do
60
+ str += aux.value.to_s
61
+ aux = aux.next
62
+ if aux != nil
63
+ str += ","
64
+ end
65
+ end
66
+ str += "]"
67
+ str
68
+ end
69
+
70
+ # Muestra la lista desde la cola
71
+ # Devuelve::
72
+ # Cadena de texto con los elementos de la lista en orden inverso
73
+ def to_rs
74
+ str = "["
75
+ aux = @tail
76
+ while aux != nil do
77
+ str += aux.value.to_s
78
+ aux = aux.prev
79
+ if aux != nil
80
+ str += ","
81
+ end
82
+ end
83
+ str += "]"
84
+ str
85
+ end
86
+
87
+ # Inserta un valor por la cabeza
88
+ # Parámetro::
89
+ # * valor: Valor a insertar
90
+ def insert (valor)
91
+ n = Node.new(valor, nil, nil)
92
+ if empty?
93
+ @head = n
94
+ @tail = n
95
+ else
96
+ n.next = @head
97
+ @head.prev = n
98
+ @head = n
99
+ end
100
+ @size += 1
101
+ end
102
+
103
+ # Inserta un valor por la cola
104
+ # Parámetro::
105
+ # * valor: Valor a insertar
106
+ def insert_tail (valor)
107
+ n = Node.new(valor, nil, nil)
108
+ if empty?
109
+ @head = n
110
+ @tail = n
111
+ else
112
+ n.prev = @tail
113
+ @tail.next = n
114
+ @tail = n
115
+ end
116
+ @size += 1
117
+ end
118
+
119
+ # Inserta un conjunto de elementos en la cabeza
120
+ # Parámetro::
121
+ # * arr: Array de elementos a insertar
122
+ def insert_more (arr)
123
+ arr.reverse_each do |value|
124
+ self.insert(value)
125
+ end
126
+ end
127
+
128
+ # Extrae el elemento en la cabeza
129
+ # Devuelve::
130
+ # Valor extraído
131
+ def extract ()
132
+ aux = nil
133
+ if @head == @tail
134
+ aux = @head
135
+ @head = nil
136
+ @tail = nil
137
+ else
138
+ aux = @head
139
+ @head = @head.next
140
+ @head.prev = nil
141
+ aux.next = nil
142
+ end
143
+ aux.value
144
+ end
145
+
146
+ # Extrae el elemento en la cola de la lista
147
+ # Devuelve::
148
+ # Valor extraído
149
+ def extract_tail ()
150
+ aux = nil
151
+ if @head == @tail
152
+ aux = @head
153
+ @head = nil
154
+ @tail = nil
155
+ else
156
+ aux = @tail
157
+ @tail = @tail.prev
158
+ @tail.next = nil
159
+ aux.prev = nil
160
+ end
161
+ aux.value
162
+ end
163
+
164
+ # Permite que la clase List sea enumerable, lo que nos deja utilizar métodos como max(), min(), reverse_each(), collect(), etc
165
+ def each
166
+ nodo = @head
167
+ while nodo != nil
168
+ yield nodo.value
169
+ nodo = nodo.next
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,51 @@
1
+ class Menu
2
+
3
+ attr_accessor :name, :description, :plates, :prices
4
+
5
+ def initialize (name, &block)
6
+
7
+ @name = name
8
+ @description = ""
9
+ @plates = []
10
+ @prices = []
11
+
12
+ if block_given?
13
+ if block.arity == 1
14
+ yield self
15
+ else
16
+ instance_eval(&block)
17
+ end
18
+ end
19
+
20
+ @vct = (@plates.collect{ |plate| plate.vct }).sum.round(2)
21
+ @gei = (@plates.collect{ |plate| plate.gei }).sum.round(2)
22
+ @terrain = (@plates.collect{ |plate| plate.terrain }).sum.round(2)
23
+ @price = @prices.sum
24
+
25
+ end
26
+
27
+ def descripcion (description)
28
+ @description = description
29
+ end
30
+
31
+ def plato (options = {})
32
+ @plates << options[:valor]
33
+ @prices << options[:precio]
34
+ end
35
+
36
+ def to_s
37
+ str = ""
38
+
39
+ str += @name + "\n"
40
+ str += @description + "\n\n"
41
+
42
+ @plates.each_with_index do |plate, index|
43
+ str += (index + 1).to_s + ". " + plate.to_s + "\nPrecio: #{@prices[index]} €\n\n"
44
+ end
45
+
46
+ str += "Valor calorico total del menu: #{@vct} kcal\n"
47
+ str += "GEI del menu: #{@gei}\n"
48
+ str += "Uso de terreno del menu: #{@terrain}\n"
49
+ str += "Precio total del menu: #{@price} €"
50
+ end
51
+ end
@@ -0,0 +1,125 @@
1
+ require 'markup'
2
+
3
+ # = plato.rb
4
+ #
5
+ # Autor:: Himar Manuel Barquín Carrasco
6
+ # Web:: https://github.com/ULL-ESIT-LPP-1920/tdd-alu0101119373
7
+ #
8
+ # == Descripción
9
+ #
10
+ # Clase que contiene una lista de alimentos, con sus cantidades. Además, nos informa del porcentaje de proteínas, lípidos y carbohidratos en proporción a las kilocalorías totales del plato.
11
+ # == Métodos
12
+ # * to_s
13
+ # * calc_vct
14
+ # * calc_perc_proteins
15
+ # * calc_perc_lipids
16
+ # * calc_perc_carbohydrates
17
+ # * <=>
18
+ class Plato
19
+
20
+ include Comparable
21
+
22
+ attr_reader :name, :food, :quantities, :vct, :percentage_proteins, :percentage_lipids, :percentage_carbohydrates
23
+
24
+ # Constructor de la clase Plato
25
+ # Parámetros::
26
+ # * name: Nombre del plato
27
+ # * alimentos: Conjunto de alimentos que componen el plato
28
+ # * gramos: Cantidades en gramos de cada alimento del plato
29
+ def initialize (name, alimentos = [], gramos = [])
30
+ @name = name
31
+
32
+ @food = List.new
33
+ @food.insert_more(alimentos)
34
+
35
+ @quantities = List.new
36
+ @quantities.insert_more(gramos)
37
+
38
+ @vct = calc_vct
39
+
40
+ # Calculamos los porcentajes
41
+ @percentage_proteins = calc_perc_proteins
42
+ @percentage_lipids = calc_perc_lipids
43
+ @percentage_carbohydrates = calc_perc_carbohydrates
44
+ end
45
+
46
+ # Método para imprimir la información del plato
47
+ # Devuelve::
48
+ # Cadena de texto con la información del plato
49
+ def to_s
50
+ alimentos = @food.collect { |x| x.name }
51
+ gramos = @quantities.collect { |x| x }
52
+ result = ""
53
+
54
+ result += "Nombre del plato: #{@name}.\nIngredientes:\n"
55
+ for i in 0...alimentos.size
56
+ result += "- #{alimentos[i]} (#{gramos[i]} gr)\n"
57
+ end
58
+ result += "Kilocalorias totales: #{self.vct} kcal"
59
+ end
60
+
61
+ # Calcula el Valor Calórico Total del plato
62
+ # Devuelve::
63
+ # Valor Calórico Total del plato
64
+ def calc_vct
65
+ alimentos = @food.collect { |x| x.energetic_value }
66
+ gramos = @quantities.collect { |x| x/100.0 }
67
+ result = 0.0
68
+
69
+ for i in 0...alimentos.size
70
+ result += (gramos[i] * alimentos[i])
71
+ end
72
+ result
73
+ end
74
+
75
+ # Calcula el porcetaje de proteínas del plato
76
+ # Devuelve::
77
+ # Porcentaje de proteínas
78
+ def calc_perc_proteins
79
+ alimentos = @food.collect { |x| x.protein }
80
+ gramos = @quantities.collect { |x| x/100.0 }
81
+ result = 0.0
82
+
83
+ for i in 0...alimentos.size
84
+ result += (gramos[i] * alimentos[i]) * 4
85
+ end
86
+ result /= @vct
87
+ end
88
+
89
+ # Calcula el porcentaje de lípidos del plato
90
+ # Devuelve::
91
+ # Porcentaje de lípidos
92
+ def calc_perc_lipids
93
+ alimentos = @food.collect { |x| x.lipids }
94
+ gramos = @quantities.collect { |x| x/100.0 }
95
+ result = 0.0
96
+
97
+ for i in 0...alimentos.size
98
+ result += (gramos[i] * alimentos[i]) * 9
99
+ end
100
+ result /= @vct
101
+ end
102
+
103
+ # Calcula el porcentaje de carbohidratos del plato
104
+ # Devuelve::
105
+ # Porcentaje de carbohidratos
106
+ def calc_perc_carbohydrates
107
+ alimentos = @food.collect { |x| x.carbohydrates }
108
+ gramos = @quantities.collect { |x| x/100.0 }
109
+ result = 0.0
110
+
111
+ for i in 0...alimentos.size
112
+ result += (gramos[i] * alimentos[i]) * 4
113
+ end
114
+ result /= @vct
115
+ end
116
+
117
+ # Nos permite comparar platos por su Valor Calórico Total
118
+ # Parámetros::
119
+ # * another: Otro plato que se compara con el invocante
120
+ # Devuelve::
121
+ # 'true' si la comparación es verdadera. 'false' en otro caso
122
+ def <=> (another)
123
+ self.vct <=> another.vct
124
+ end
125
+ end