nutritional_calculator 4.0.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/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/NutritionalCalculator.html +423 -0
- data/docs/NutritionalCalculator/Food.html +912 -0
- data/docs/NutritionalCalculator/FoodGroup.html +498 -0
- data/docs/NutritionalCalculator/LinkedList.html +1312 -0
- data/docs/NutritionalCalculator/LinkedList/Node.html +409 -0
- data/docs/_index.html +151 -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 +138 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +138 -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 +275 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/files/food_database.config +22 -0
- data/lib/files/glycemic_index.config +8 -0
- data/lib/files/nutritional_file.txt +5 -0
- data/lib/files/nutritional_group.config +22 -0
- data/lib/nutritional_calculator.rb +55 -0
- data/lib/nutritional_calculator/food.rb +99 -0
- data/lib/nutritional_calculator/foodgroup.rb +32 -0
- data/lib/nutritional_calculator/linkedlist.rb +194 -0
- data/lib/nutritional_calculator/plate.rb +294 -0
- data/lib/nutritional_calculator/sort_methods.rb +34 -0
- data/lib/nutritional_calculator/version.rb +4 -0
- data/nutritional_calculator.gemspec +40 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d421e17f093fa3a9a2370c8e4983308bfb3290ca
|
4
|
+
data.tar.gz: c9729a3da16e1c72151049fec473a7f47e866849
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50633bc24d6961141b29accd28476eefc6c1ab77407c13ce4bdd3622b014637a4d492b3f153b29a8df067a335989035cecc4877b33e800816221df6179cb1442
|
7
|
+
data.tar.gz: 55d33cb377e0dd50c93c7021f77a29ff9804086b6b82e8e21bd6aef2f43a03b7fd4be8033e1bcd0c1975f18121cf1c11334e3dd844bb5989863bb2eacd31b6ae
|
data/.DS_Store
ADDED
Binary file
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
7
|
+
|
8
|
+
## Note: if you are using the `directories` clause above and you are not
|
9
|
+
## watching the project directory ('.'), then you will want to move
|
10
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
11
|
+
#
|
12
|
+
# $ mkdir config
|
13
|
+
# $ mv Guardfile config/
|
14
|
+
# $ ln -s config/Guardfile .
|
15
|
+
#
|
16
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
17
|
+
|
18
|
+
guard :bundler do
|
19
|
+
require 'guard/bundler'
|
20
|
+
require 'guard/bundler/verify'
|
21
|
+
helper = Guard::Bundler::Verify.new
|
22
|
+
|
23
|
+
files = ['Gemfile']
|
24
|
+
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
|
25
|
+
|
26
|
+
# Assume files are symlinked from somewhere
|
27
|
+
files.each { |file| watch(helper.real_path(file)) }
|
28
|
+
end
|
29
|
+
|
30
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
31
|
+
# rspec may be run, below are examples of the most common uses.
|
32
|
+
# * bundler: 'bundle exec rspec'
|
33
|
+
# * bundler binstubs: 'bin/rspec'
|
34
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
35
|
+
# installed the spring binstubs per the docs)
|
36
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
37
|
+
# * 'just' rspec: 'rspec'
|
38
|
+
|
39
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
40
|
+
require "guard/rspec/dsl"
|
41
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
42
|
+
|
43
|
+
# Feel free to open issues for suggestions and improvements
|
44
|
+
|
45
|
+
# RSpec files
|
46
|
+
rspec = dsl.rspec
|
47
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
48
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
49
|
+
watch(rspec.spec_files)
|
50
|
+
|
51
|
+
# Ruby files
|
52
|
+
ruby = dsl.ruby
|
53
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
54
|
+
|
55
|
+
# Rails files
|
56
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
57
|
+
dsl.watch_spec_files_for(rails.app_files)
|
58
|
+
dsl.watch_spec_files_for(rails.views)
|
59
|
+
|
60
|
+
watch(rails.controllers) do |m|
|
61
|
+
[
|
62
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
63
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
64
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
65
|
+
]
|
66
|
+
end
|
67
|
+
|
68
|
+
# Rails config changes
|
69
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
70
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
71
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
72
|
+
|
73
|
+
# Capybara features specs
|
74
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
75
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
76
|
+
|
77
|
+
# Turnip features and steps
|
78
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
79
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
80
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
81
|
+
end
|
82
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Cristian Abrante
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# NutritionalCalculator
|
2
|
+
## TDD con Ruby
|
3
|
+
|
4
|
+
La gema nutritional_calculator nos permitirá realizar diversos cálculos nutricionales con alimentos. Es capaz de leer la información de los alimentos a través de un fichero además de permitirnos guardar dichos alimentos en una lista.
|
5
|
+
|
6
|
+
##### author: Cristian Abrante Dorta
|
7
|
+
##### email: alu0100945850@ull.edu.es
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'nutritional_calculator'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install nutritional_calculator
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
ESta gema permite a los usuarios calcular el valor nutricional actual (KCal) de un alimento concreto. Para hacer esto, creamos un objeto `NutritionalCalculator::Food` al que debemos especificarle los gramos de proteínas, glúcidos y lípidos que tiene. Además, la clase cuenta con un método `get_nutritional_value()` que nos permite tener acceso a este valor nutricional.
|
28
|
+
Por otra parte, contamos con la clase `NutritionalCalculator::FoodGroup` que además de los atributos de la clase anterior(herencia) también nos permite almacenar el grupo al que pertenece el alimento.
|
29
|
+
|
30
|
+
Finalmente, contaremos con una clase que simula a una lista enlazada en la que almacenamos los alimentos `NutritionalCalculator::LinkedList`.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alu0100945850/nutritional_calculator.
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nutritional_calculator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,423 @@
|
|
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
|
+
Module: NutritionalCalculator
|
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 = "NutritionalCalculator";
|
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 (N)</a> »
|
40
|
+
|
41
|
+
|
42
|
+
<span class="title">NutritionalCalculator</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>Module: NutritionalCalculator
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<dl>
|
80
|
+
<dt>Defined in:</dt>
|
81
|
+
<dd>lib/nutritional_calculator.rb<span class="defines">,<br />
|
82
|
+
lib/nutritional_calculator/food.rb,<br /> lib/nutritional_calculator/version.rb,<br /> lib/nutritional_calculator/foodgroup.rb,<br /> lib/nutritional_calculator/linkedlist.rb</span>
|
83
|
+
</dd>
|
84
|
+
</dl>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<h2>Overview</h2><div class="docstring">
|
89
|
+
<div class="discussion">
|
90
|
+
|
91
|
+
<p>El módulo se crea para describir los distintos elementos que compondrán una
|
92
|
+
calculadora nutricional de alimentos.</p>
|
93
|
+
<dl class="rdoc-list note-list"><dt>Author
|
94
|
+
<dd>
|
95
|
+
<p>Cristian Abrante (mailto: alu0100945850@ull.edu.es)</p>
|
96
|
+
</dd><dt>Copyright
|
97
|
+
<dd>
|
98
|
+
<p>Creative Commons</p>
|
99
|
+
</dd><dt>License
|
100
|
+
<dd>
|
101
|
+
<p>Distributed under the same license as Ruby.</p>
|
102
|
+
</dd></dl>
|
103
|
+
|
104
|
+
|
105
|
+
</div>
|
106
|
+
</div>
|
107
|
+
<div class="tags">
|
108
|
+
|
109
|
+
|
110
|
+
</div><h2>Defined Under Namespace</h2>
|
111
|
+
<p class="children">
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="NutritionalCalculator/Food.html" title="NutritionalCalculator::Food (class)">Food</a></span>, <span class='object_link'><a href="NutritionalCalculator/FoodGroup.html" title="NutritionalCalculator::FoodGroup (class)">FoodGroup</a></span>, <span class='object_link'><a href="NutritionalCalculator/LinkedList.html" title="NutritionalCalculator::LinkedList (class)">LinkedList</a></span>
|
117
|
+
|
118
|
+
|
119
|
+
</p>
|
120
|
+
|
121
|
+
<h2>Constant Summary</h2>
|
122
|
+
<dl class="constants">
|
123
|
+
|
124
|
+
<dt id="VERSION-constant" class="">VERSION =
|
125
|
+
<div class="docstring">
|
126
|
+
<div class="discussion">
|
127
|
+
|
128
|
+
<p>Versión actual de la gema.</p>
|
129
|
+
|
130
|
+
|
131
|
+
</div>
|
132
|
+
</div>
|
133
|
+
<div class="tags">
|
134
|
+
|
135
|
+
|
136
|
+
</div>
|
137
|
+
</dt>
|
138
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>3.0.0</span><span class='tstring_end'>"</span></span></pre></dd>
|
139
|
+
|
140
|
+
</dl>
|
141
|
+
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
<h2>
|
150
|
+
Class Method Summary
|
151
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
152
|
+
</h2>
|
153
|
+
|
154
|
+
<ul class="summary">
|
155
|
+
|
156
|
+
<li class="public ">
|
157
|
+
<span class="summary_signature">
|
158
|
+
|
159
|
+
<a href="#read_nutritional_file-class_method" title="read_nutritional_file (class method)">.<strong>read_nutritional_file</strong>(file_name) ⇒ Object </a>
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
</span>
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
<span class="summary_desc"><div class='inline'>
|
174
|
+
<p>Método que lee la configuración del fichero.</p>
|
175
|
+
</div></span>
|
176
|
+
|
177
|
+
</li>
|
178
|
+
|
179
|
+
|
180
|
+
<li class="public ">
|
181
|
+
<span class="summary_signature">
|
182
|
+
|
183
|
+
<a href="#read_nutritional_groups-class_method" title="read_nutritional_groups (class method)">.<strong>read_nutritional_groups</strong>(file_name) ⇒ Object </a>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
</span>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
<span class="summary_desc"><div class='inline'>
|
198
|
+
<p>Método que lee la configuración del fichero para un grupo de alimentos.</p>
|
199
|
+
</div></span>
|
200
|
+
|
201
|
+
</li>
|
202
|
+
|
203
|
+
|
204
|
+
</ul>
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
<div id="class_method_details" class="method_details_list">
|
210
|
+
<h2>Class Method Details</h2>
|
211
|
+
|
212
|
+
|
213
|
+
<div class="method_details first">
|
214
|
+
<h3 class="signature first" id="read_nutritional_file-class_method">
|
215
|
+
|
216
|
+
.<strong>read_nutritional_file</strong>(file_name) ⇒ <tt>Object</tt>
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
|
222
|
+
</h3><div class="docstring">
|
223
|
+
<div class="discussion">
|
224
|
+
|
225
|
+
<p>Método que lee la configuración del fichero.</p>
|
226
|
+
|
227
|
+
|
228
|
+
</div>
|
229
|
+
</div>
|
230
|
+
<div class="tags">
|
231
|
+
|
232
|
+
|
233
|
+
</div><table class="source_code">
|
234
|
+
<tr>
|
235
|
+
<td>
|
236
|
+
<pre class="lines">
|
237
|
+
|
238
|
+
|
239
|
+
13
|
240
|
+
14
|
241
|
+
15
|
242
|
+
16
|
243
|
+
17
|
244
|
+
18
|
245
|
+
19
|
246
|
+
20
|
247
|
+
21
|
248
|
+
22
|
249
|
+
23
|
250
|
+
24
|
251
|
+
25
|
252
|
+
26
|
253
|
+
27
|
254
|
+
28
|
255
|
+
29
|
256
|
+
30
|
257
|
+
31
|
258
|
+
32
|
259
|
+
33
|
260
|
+
34
|
261
|
+
35
|
262
|
+
36
|
263
|
+
37
|
264
|
+
38
|
265
|
+
39
|
266
|
+
40
|
267
|
+
41
|
268
|
+
42
|
269
|
+
43</pre>
|
270
|
+
</td>
|
271
|
+
<td>
|
272
|
+
<pre class="code"><span class="info file"># File 'lib/nutritional_calculator.rb', line 13</span>
|
273
|
+
|
274
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_read_nutritional_file'>read_nutritional_file</span><span class='lparen'>(</span><span class='id identifier rubyid_file_name'>file_name</span><span class='rparen'>)</span>
|
275
|
+
|
276
|
+
<span class='id identifier rubyid_nutritional_hash'>nutritional_hash</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
277
|
+
|
278
|
+
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_file_name'>file_name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>r</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span>
|
279
|
+
|
280
|
+
<span class='id identifier rubyid_f'>f</span><span class='period'>.</span><span class='id identifier rubyid_each_line'>each_line</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_line'>line</span><span class='op'>|</span>
|
281
|
+
<span class='id identifier rubyid_vector'>vector</span> <span class='op'>=</span> <span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
282
|
+
|
283
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_vector'>vector</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span> <span class='op'>==</span> <span class='int'>4</span>
|
284
|
+
<span class='id identifier rubyid_nutritional_hash'>nutritional_hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='int'>1</span><span class='op'>...</span><span class='int'>4</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='rbrace'>}</span>
|
285
|
+
<span class='kw'>else</span>
|
286
|
+
|
287
|
+
<span class='id identifier rubyid_pos'>pos</span> <span class='op'>=</span> <span class='int'>1</span>
|
288
|
+
<span class='id identifier rubyid_food_name'>food_name</span> <span class='op'>=</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span>
|
289
|
+
|
290
|
+
<span class='kw'>while</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_pos'>pos</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'>==</span> <span class='float'>0.0</span> <span class='op'>&&</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_pos'>pos</span><span class='rbracket'>]</span> <span class='op'>!=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_pos'>pos</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
291
|
+
<span class='id identifier rubyid_food_name'>food_name</span> <span class='op'>+=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span> <span class='op'>+</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_pos'>pos</span><span class='rbracket'>]</span>
|
292
|
+
<span class='id identifier rubyid_pos'>pos</span> <span class='op'>+=</span> <span class='int'>1</span>
|
293
|
+
<span class='kw'>end</span>
|
294
|
+
|
295
|
+
<span class='id identifier rubyid_nutritional_hash'>nutritional_hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_food_name'>food_name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_pos'>pos</span><span class='op'>...</span><span class='id identifier rubyid_vector'>vector</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='rbrace'>}</span>
|
296
|
+
<span class='kw'>end</span>
|
297
|
+
|
298
|
+
<span class='kw'>end</span>
|
299
|
+
|
300
|
+
<span class='kw'>end</span>
|
301
|
+
|
302
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_nutritional_hash'>nutritional_hash</span>
|
303
|
+
|
304
|
+
<span class='kw'>end</span></pre>
|
305
|
+
</td>
|
306
|
+
</tr>
|
307
|
+
</table>
|
308
|
+
</div>
|
309
|
+
|
310
|
+
<div class="method_details ">
|
311
|
+
<h3 class="signature " id="read_nutritional_groups-class_method">
|
312
|
+
|
313
|
+
.<strong>read_nutritional_groups</strong>(file_name) ⇒ <tt>Object</tt>
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
</h3><div class="docstring">
|
320
|
+
<div class="discussion">
|
321
|
+
|
322
|
+
<p>Método que lee la configuración del fichero para un grupo de alimentos.</p>
|
323
|
+
|
324
|
+
|
325
|
+
</div>
|
326
|
+
</div>
|
327
|
+
<div class="tags">
|
328
|
+
|
329
|
+
|
330
|
+
</div><table class="source_code">
|
331
|
+
<tr>
|
332
|
+
<td>
|
333
|
+
<pre class="lines">
|
334
|
+
|
335
|
+
|
336
|
+
47
|
337
|
+
48
|
338
|
+
49
|
339
|
+
50
|
340
|
+
51
|
341
|
+
52
|
342
|
+
53
|
343
|
+
54
|
344
|
+
55
|
345
|
+
56
|
346
|
+
57
|
347
|
+
58
|
348
|
+
59
|
349
|
+
60
|
350
|
+
61
|
351
|
+
62
|
352
|
+
63
|
353
|
+
64
|
354
|
+
65
|
355
|
+
66
|
356
|
+
67
|
357
|
+
68
|
358
|
+
69
|
359
|
+
70
|
360
|
+
71
|
361
|
+
72
|
362
|
+
73
|
363
|
+
74
|
364
|
+
75
|
365
|
+
76
|
366
|
+
77
|
367
|
+
78
|
368
|
+
79</pre>
|
369
|
+
</td>
|
370
|
+
<td>
|
371
|
+
<pre class="code"><span class="info file"># File 'lib/nutritional_calculator.rb', line 47</span>
|
372
|
+
|
373
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_read_nutritional_groups'>read_nutritional_groups</span><span class='lparen'>(</span><span class='id identifier rubyid_file_name'>file_name</span><span class='rparen'>)</span>
|
374
|
+
|
375
|
+
<span class='id identifier rubyid_nutritional_groups'>nutritional_groups</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
376
|
+
|
377
|
+
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_file_name'>file_name</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>r</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_f'>f</span><span class='op'>|</span>
|
378
|
+
<span class='id identifier rubyid_f'>f</span><span class='period'>.</span><span class='id identifier rubyid_each_line'>each_line</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_line'>line</span><span class='op'>|</span>
|
379
|
+
|
380
|
+
<span class='id identifier rubyid_vector'>vector</span> <span class='op'>=</span> <span class='id identifier rubyid_line'>line</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
381
|
+
|
382
|
+
<span class='id identifier rubyid_num_pos'>num_pos</span> <span class='op'>=</span> <span class='int'>1</span>
|
383
|
+
<span class='id identifier rubyid_food_name'>food_name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='int'>0</span><span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
384
|
+
|
385
|
+
<span class='kw'>while</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_num_pos'>num_pos</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span> <span class='op'>==</span> <span class='float'>0.0</span> <span class='op'>&&</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_num_pos'>num_pos</span><span class='rbracket'>]</span> <span class='op'>!=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_num_pos'>num_pos</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
386
|
+
<span class='id identifier rubyid_food_name'>food_name</span> <span class='op'>+=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_num_pos'>num_pos</span><span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
387
|
+
<span class='id identifier rubyid_num_pos'>num_pos</span> <span class='op'>+=</span> <span class='int'>1</span>
|
388
|
+
<span class='kw'>end</span>
|
389
|
+
|
390
|
+
<span class='id identifier rubyid_food_group'>food_group</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span>
|
391
|
+
<span class='kw'>for</span> <span class='id identifier rubyid_chunk'>chunk</span> <span class='kw'>in</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='lparen'>(</span><span class='id identifier rubyid_num_pos'>num_pos</span> <span class='op'>+</span> <span class='int'>3</span><span class='rparen'>)</span><span class='op'>...</span><span class='id identifier rubyid_vector'>vector</span><span class='period'>.</span><span class='id identifier rubyid_length'>length</span><span class='rbracket'>]</span> <span class='kw'>do</span>
|
392
|
+
<span class='id identifier rubyid_food_group'>food_group</span> <span class='op'>+=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_chunk'>chunk</span><span class='embexpr_end'>}</span><span class='tstring_content'> </span><span class='tstring_end'>"</span></span>
|
393
|
+
<span class='kw'>end</span>
|
394
|
+
|
395
|
+
<span class='id identifier rubyid_vector_of_food'>vector_of_food</span> <span class='op'>=</span> <span class='id identifier rubyid_vector'>vector</span><span class='lbracket'>[</span><span class='id identifier rubyid_num_pos'>num_pos</span><span class='op'>...</span><span class='id identifier rubyid_num_pos'>num_pos</span> <span class='op'>+</span> <span class='int'>3</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_to_f'>to_f</span><span class='rbrace'>}</span>
|
396
|
+
<span class='id identifier rubyid_vector_of_food'>vector_of_food</span><span class='lbracket'>[</span><span class='int'>3</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_food_group'>food_group</span>
|
397
|
+
|
398
|
+
<span class='id identifier rubyid_nutritional_groups'>nutritional_groups</span><span class='lbracket'>[</span><span class='id identifier rubyid_food_name'>food_name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_vector_of_food'>vector_of_food</span>
|
399
|
+
|
400
|
+
<span class='kw'>end</span>
|
401
|
+
<span class='kw'>end</span>
|
402
|
+
|
403
|
+
<span class='id identifier rubyid_nutritional_groups'>nutritional_groups</span>
|
404
|
+
|
405
|
+
<span class='kw'>end</span></pre>
|
406
|
+
</td>
|
407
|
+
</tr>
|
408
|
+
</table>
|
409
|
+
</div>
|
410
|
+
|
411
|
+
</div>
|
412
|
+
|
413
|
+
</div>
|
414
|
+
|
415
|
+
<div id="footer">
|
416
|
+
Generated on Tue Nov 14 20:38:37 2017 by
|
417
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
418
|
+
0.9.9 (ruby-2.3.1).
|
419
|
+
</div>
|
420
|
+
|
421
|
+
</div>
|
422
|
+
</body>
|
423
|
+
</html>
|