food_alu0100904406 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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Guardfile +82 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Alimento_.html +407 -0
- data/docs/Food.html +110 -0
- data/docs/Gemfile.html +100 -0
- data/docs/Gemfile_lock.html +177 -0
- data/docs/Grupo_alimento.html +235 -0
- data/docs/Guardfile.html +177 -0
- data/docs/Lista.html +365 -0
- data/docs/Object.html +118 -0
- data/docs/README_md.html +151 -0
- data/docs/Rakefile.html +98 -0
- data/docs/bin/setup.html +98 -0
- data/docs/created.rid +16 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +590 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/food_gemspec.html +130 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +110 -0
- data/docs/js/darkfish.js +161 -0
- data/docs/js/jquery.js +4 -0
- data/docs/js/navigation.js +142 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +109 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +150 -0
- data/food.gemspec +39 -0
- data/lib/food/food_.rb +73 -0
- data/lib/food/list.rb +104 -0
- data/lib/food/plato.rb +146 -0
- data/lib/food/version.rb +3 -0
- data/lib/food.rb +8 -0
- metadata +213 -0
data/docs/js/searcher.js
ADDED
@@ -0,0 +1,229 @@
|
|
1
|
+
Searcher = function(data) {
|
2
|
+
this.data = data;
|
3
|
+
this.handlers = [];
|
4
|
+
}
|
5
|
+
|
6
|
+
Searcher.prototype = new function() {
|
7
|
+
// search is performed in chunks of 1000 for non-blocking user input
|
8
|
+
var CHUNK_SIZE = 1000;
|
9
|
+
// do not try to find more than 100 results
|
10
|
+
var MAX_RESULTS = 100;
|
11
|
+
var huid = 1;
|
12
|
+
var suid = 1;
|
13
|
+
var runs = 0;
|
14
|
+
|
15
|
+
this.find = function(query) {
|
16
|
+
var queries = splitQuery(query);
|
17
|
+
var regexps = buildRegexps(queries);
|
18
|
+
var highlighters = buildHilighters(queries);
|
19
|
+
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
|
20
|
+
var _this = this;
|
21
|
+
|
22
|
+
this.currentSuid = state.n;
|
23
|
+
|
24
|
+
if (!query) return;
|
25
|
+
|
26
|
+
var run = function() {
|
27
|
+
// stop current search thread if new search started
|
28
|
+
if (state.n != _this.currentSuid) return;
|
29
|
+
|
30
|
+
var results =
|
31
|
+
performSearch(_this.data, regexps, queries, highlighters, state);
|
32
|
+
var hasMore = (state.limit > 0 && state.pass < 4);
|
33
|
+
|
34
|
+
triggerResults.call(_this, results, !hasMore);
|
35
|
+
if (hasMore) {
|
36
|
+
setTimeout(run, 2);
|
37
|
+
}
|
38
|
+
runs++;
|
39
|
+
};
|
40
|
+
runs = 0;
|
41
|
+
|
42
|
+
// start search thread
|
43
|
+
run();
|
44
|
+
}
|
45
|
+
|
46
|
+
/* ----- Events ------ */
|
47
|
+
this.ready = function(fn) {
|
48
|
+
fn.huid = huid;
|
49
|
+
this.handlers.push(fn);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* ----- Utilities ------ */
|
53
|
+
function splitQuery(query) {
|
54
|
+
return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
|
55
|
+
return string.match(/\S/);
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildRegexps(queries) {
|
60
|
+
return jQuery.map(queries, function(query) {
|
61
|
+
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i');
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
function buildHilighters(queries) {
|
66
|
+
return jQuery.map(queries, function(query) {
|
67
|
+
return jQuery.map(query.split(''), function(l, i) {
|
68
|
+
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
|
69
|
+
}).join('');
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
// function longMatchRegexp(index, longIndex, regexps) {
|
74
|
+
// for (var i = regexps.length - 1; i >= 0; i--){
|
75
|
+
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
|
76
|
+
// };
|
77
|
+
// return true;
|
78
|
+
// }
|
79
|
+
|
80
|
+
|
81
|
+
/* ----- Mathchers ------ */
|
82
|
+
|
83
|
+
/*
|
84
|
+
* This record matches if the index starts with queries[0] and the record
|
85
|
+
* matches all of the regexps
|
86
|
+
*/
|
87
|
+
function matchPassBeginning(index, longIndex, queries, regexps) {
|
88
|
+
if (index.indexOf(queries[0]) != 0) return false;
|
89
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
90
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* This record matches if the longIndex starts with queries[0] and the
|
98
|
+
* longIndex matches all of the regexps
|
99
|
+
*/
|
100
|
+
function matchPassLongIndex(index, longIndex, queries, regexps) {
|
101
|
+
if (longIndex.indexOf(queries[0]) != 0) return false;
|
102
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
103
|
+
if (!longIndex.match(regexps[i]))
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* This record matches if the index contains queries[0] and the record
|
111
|
+
* matches all of the regexps
|
112
|
+
*/
|
113
|
+
function matchPassContains(index, longIndex, queries, regexps) {
|
114
|
+
if (index.indexOf(queries[0]) == -1) return false;
|
115
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
116
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
117
|
+
return false;
|
118
|
+
};
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* This record matches if regexps[0] matches the index and the record
|
124
|
+
* matches all of the regexps
|
125
|
+
*/
|
126
|
+
function matchPassRegexp(index, longIndex, queries, regexps) {
|
127
|
+
if (!index.match(regexps[0])) return false;
|
128
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
129
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
130
|
+
return false;
|
131
|
+
};
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/* ----- Highlighters ------ */
|
137
|
+
function highlightRegexp(info, queries, regexps, highlighters) {
|
138
|
+
var result = createResult(info);
|
139
|
+
for (var i=0, l = regexps.length; i < l; i++) {
|
140
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
141
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
142
|
+
};
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
function hltSubstring(string, pos, length) {
|
147
|
+
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
|
148
|
+
}
|
149
|
+
|
150
|
+
function highlightQuery(info, queries, regexps, highlighters) {
|
151
|
+
var result = createResult(info);
|
152
|
+
var pos = 0;
|
153
|
+
var lcTitle = result.title.toLowerCase();
|
154
|
+
|
155
|
+
pos = lcTitle.indexOf(queries[0]);
|
156
|
+
if (pos != -1) {
|
157
|
+
result.title = hltSubstring(result.title, pos, queries[0].length);
|
158
|
+
}
|
159
|
+
|
160
|
+
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
|
161
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
162
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
163
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
164
|
+
};
|
165
|
+
return result;
|
166
|
+
}
|
167
|
+
|
168
|
+
function createResult(info) {
|
169
|
+
var result = {};
|
170
|
+
result.title = info[0];
|
171
|
+
result.namespace = info[1];
|
172
|
+
result.path = info[2];
|
173
|
+
result.params = info[3];
|
174
|
+
result.snippet = info[4];
|
175
|
+
result.badge = info[6];
|
176
|
+
return result;
|
177
|
+
}
|
178
|
+
|
179
|
+
/* ----- Searching ------ */
|
180
|
+
function performSearch(data, regexps, queries, highlighters, state) {
|
181
|
+
var searchIndex = data.searchIndex;
|
182
|
+
var longSearchIndex = data.longSearchIndex;
|
183
|
+
var info = data.info;
|
184
|
+
var result = [];
|
185
|
+
var i = state.from;
|
186
|
+
var l = searchIndex.length;
|
187
|
+
var togo = CHUNK_SIZE;
|
188
|
+
var matchFunc, hltFunc;
|
189
|
+
|
190
|
+
while (state.pass < 4 && state.limit > 0 && togo > 0) {
|
191
|
+
if (state.pass == 0) {
|
192
|
+
matchFunc = matchPassBeginning;
|
193
|
+
hltFunc = highlightQuery;
|
194
|
+
} else if (state.pass == 1) {
|
195
|
+
matchFunc = matchPassLongIndex;
|
196
|
+
hltFunc = highlightQuery;
|
197
|
+
} else if (state.pass == 2) {
|
198
|
+
matchFunc = matchPassContains;
|
199
|
+
hltFunc = highlightQuery;
|
200
|
+
} else if (state.pass == 3) {
|
201
|
+
matchFunc = matchPassRegexp;
|
202
|
+
hltFunc = highlightRegexp;
|
203
|
+
}
|
204
|
+
|
205
|
+
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
|
206
|
+
if (info[i].n == state.n) continue;
|
207
|
+
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
|
208
|
+
info[i].n = state.n;
|
209
|
+
result.push(hltFunc(info[i], queries, regexps, highlighters));
|
210
|
+
state.limit--;
|
211
|
+
}
|
212
|
+
};
|
213
|
+
if (searchIndex.length <= i) {
|
214
|
+
state.pass++;
|
215
|
+
i = state.from = 0;
|
216
|
+
} else {
|
217
|
+
state.from = i;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
return result;
|
221
|
+
}
|
222
|
+
|
223
|
+
function triggerResults(results, isLast) {
|
224
|
+
jQuery.each(this.handlers, function(i, fn) {
|
225
|
+
fn.call(this, results, isLast)
|
226
|
+
})
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
Binary file
|
@@ -0,0 +1,150 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>Table of Contents - 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
|
+
<body id="top" class="table-of-contents">
|
23
|
+
<main role="main">
|
24
|
+
<h1 class="class">Table of Contents - RDoc Documentation</h1>
|
25
|
+
|
26
|
+
<h2 id="pages">Pages</h2>
|
27
|
+
<ul>
|
28
|
+
<li class="file">
|
29
|
+
<a href="Gemfile.html">Gemfile</a>
|
30
|
+
</li>
|
31
|
+
<li class="file">
|
32
|
+
<a href="Gemfile_lock.html">Gemfile.lock</a>
|
33
|
+
</li>
|
34
|
+
<li class="file">
|
35
|
+
<a href="Guardfile.html">Guardfile</a>
|
36
|
+
</li>
|
37
|
+
<li class="file">
|
38
|
+
<a href="README_md.html">README</a>
|
39
|
+
|
40
|
+
<ul>
|
41
|
+
<li><a href="README_md.html#label-Food">Food</a>
|
42
|
+
<li><a href="README_md.html#label-Installation">Installation</a>
|
43
|
+
<li><a href="README_md.html#label-Usage">Usage</a>
|
44
|
+
<li><a href="README_md.html#label-Development">Development</a>
|
45
|
+
<li><a href="README_md.html#label-Contributing">Contributing</a>
|
46
|
+
</ul>
|
47
|
+
</li>
|
48
|
+
<li class="file">
|
49
|
+
<a href="Rakefile.html">Rakefile</a>
|
50
|
+
</li>
|
51
|
+
<li class="file">
|
52
|
+
<a href="bin/setup.html">setup</a>
|
53
|
+
</li>
|
54
|
+
<li class="file">
|
55
|
+
<a href="food_gemspec.html">food.gemspec</a>
|
56
|
+
</li>
|
57
|
+
|
58
|
+
</ul>
|
59
|
+
|
60
|
+
<h2 id="classes">Classes and Modules</h2>
|
61
|
+
<ul>
|
62
|
+
<li class="class">
|
63
|
+
<a href="Alimento_.html">Alimento_</a>
|
64
|
+
</li>
|
65
|
+
<li class="module">
|
66
|
+
<a href="Food.html">Food</a>
|
67
|
+
</li>
|
68
|
+
<li class="class">
|
69
|
+
<a href="Grupo_alimento.html">Grupo_alimento</a>
|
70
|
+
</li>
|
71
|
+
<li class="class">
|
72
|
+
<a href="Lista.html">Lista</a>
|
73
|
+
</li>
|
74
|
+
<li class="class">
|
75
|
+
<a href="Object.html">Object</a>
|
76
|
+
</li>
|
77
|
+
</ul>
|
78
|
+
|
79
|
+
<h2 id="methods">Methods</h2>
|
80
|
+
<ul>
|
81
|
+
|
82
|
+
<li class="method">
|
83
|
+
<a href="Alimento_.html#method-c-new">::new</a>
|
84
|
+
—
|
85
|
+
<span class="container">Alimento_</span>
|
86
|
+
|
87
|
+
<li class="method">
|
88
|
+
<a href="Grupo_alimento.html#method-c-new">::new</a>
|
89
|
+
—
|
90
|
+
<span class="container">Grupo_alimento</span>
|
91
|
+
|
92
|
+
<li class="method">
|
93
|
+
<a href="Lista.html#method-c-new">::new</a>
|
94
|
+
—
|
95
|
+
<span class="container">Lista</span>
|
96
|
+
|
97
|
+
<li class="method">
|
98
|
+
<a href="Alimento_.html#method-i-3C-3D-3E">#<=></a>
|
99
|
+
—
|
100
|
+
<span class="container">Alimento_</span>
|
101
|
+
|
102
|
+
<li class="method">
|
103
|
+
<a href="Alimento_.html#method-i-aibc">#aibc</a>
|
104
|
+
—
|
105
|
+
<span class="container">Alimento_</span>
|
106
|
+
|
107
|
+
<li class="method">
|
108
|
+
<a href="Lista.html#method-i-each">#each</a>
|
109
|
+
—
|
110
|
+
<span class="container">Lista</span>
|
111
|
+
|
112
|
+
<li class="method">
|
113
|
+
<a href="Lista.html#method-i-insertEnd">#insertEnd</a>
|
114
|
+
—
|
115
|
+
<span class="container">Lista</span>
|
116
|
+
|
117
|
+
<li class="method">
|
118
|
+
<a href="Lista.html#method-i-pop_first">#pop_first</a>
|
119
|
+
—
|
120
|
+
<span class="container">Lista</span>
|
121
|
+
|
122
|
+
<li class="method">
|
123
|
+
<a href="Lista.html#method-i-pop_last">#pop_last</a>
|
124
|
+
—
|
125
|
+
<span class="container">Lista</span>
|
126
|
+
|
127
|
+
<li class="method">
|
128
|
+
<a href="Alimento_.html#method-i-to_s">#to_s</a>
|
129
|
+
—
|
130
|
+
<span class="container">Alimento_</span>
|
131
|
+
|
132
|
+
<li class="method">
|
133
|
+
<a href="Grupo_alimento.html#method-i-to_s">#to_s</a>
|
134
|
+
—
|
135
|
+
<span class="container">Grupo_alimento</span>
|
136
|
+
|
137
|
+
<li class="method">
|
138
|
+
<a href="Alimento_.html#method-i-valor_energetico">#valor_energetico</a>
|
139
|
+
—
|
140
|
+
<span class="container">Alimento_</span>
|
141
|
+
</ul>
|
142
|
+
</main>
|
143
|
+
|
144
|
+
|
145
|
+
<footer id="validator-badges" role="contentinfo">
|
146
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
147
|
+
<p>Generated by <a href="https://rdoc.github.io/rdoc">RDoc</a> 5.1.0.
|
148
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
149
|
+
</footer>
|
150
|
+
|
data/food.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "food/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "food_alu0100904406"
|
8
|
+
spec.version = Food::VERSION
|
9
|
+
spec.authors = ["Cristian"]
|
10
|
+
spec.email = ["cristianjonay@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gema que describe un alimento}
|
13
|
+
spec.homepage = "https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100904406"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
#if spec.respond_to?(:metadata)
|
18
|
+
# spec.metadata["allowed_push_host"] = "https://github.com/ULL-ESIT-LPP-1718/tdd-alu0100904406"
|
19
|
+
#else
|
20
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
21
|
+
# "public gem pushes."
|
22
|
+
#end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "guard"
|
35
|
+
spec.add_development_dependency "guard-rspec"
|
36
|
+
spec.add_development_dependency "guard-bundler"
|
37
|
+
|
38
|
+
spec.add_development_dependency "coveralls"
|
39
|
+
end
|
data/lib/food/food_.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Author:: Cristian Jonay Ramos González
|
4
|
+
# Alu:: alu0100904406
|
5
|
+
# Copyright:: Cretive Commons
|
6
|
+
# License:: Distributes under the same terms as Ruby
|
7
|
+
|
8
|
+
require "food/version"
|
9
|
+
|
10
|
+
# Esta clase permite representar un alimento.
|
11
|
+
|
12
|
+
class Alimento_
|
13
|
+
include Comparable
|
14
|
+
attr_reader :nombre, :proteinas, :lipidos, :glucidos
|
15
|
+
attr_accessor :datos
|
16
|
+
|
17
|
+
#Constructor al que se le pasa el nombre del alimmento, cantidad de proteinas, cantidad de lipidos y cantidad de glucidos
|
18
|
+
def initialize(nombre, proteinas, lipidos, glucidos)
|
19
|
+
@nombre=nombre
|
20
|
+
@proteinas=proteinas
|
21
|
+
@lipidos=lipidos
|
22
|
+
@glucidos=glucidos
|
23
|
+
end
|
24
|
+
|
25
|
+
#Metodo para mostrar formateado:
|
26
|
+
# =>formato= Nombre del alimento nºproteinas nºglucido nºlipidos
|
27
|
+
def to_s
|
28
|
+
"#{@nombre}\t#{@proteinas}\t#{@glucidos}\t#{@lipidos}"
|
29
|
+
end
|
30
|
+
|
31
|
+
#Metodo para calcular el valor energético de un alimento:
|
32
|
+
# =>Valor energetico=proteinas*4+glucidos*4+lipidos*9.
|
33
|
+
def valor_energetico
|
34
|
+
(@proteinas*4) + (@glucidos*4) + (@lipidos*9)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Sobrecarga del metodo <=> para que un Alimento_ se compare con otro a través de su valor ennergético.
|
38
|
+
def <=> another
|
39
|
+
return nil unless another.is_a? Alimento_
|
40
|
+
self.valor_energetico <=> another.valor_energetico
|
41
|
+
end
|
42
|
+
|
43
|
+
# Funcion para calcular el AIBC de forma funcional.
|
44
|
+
def aibc(indice)
|
45
|
+
vector = []
|
46
|
+
datos[indice][1..datos[indice].length-1].zip(datos[indice][0..datos[indice].length-2]) do | gi, gi_1 |
|
47
|
+
if gi < datos[indice][0]
|
48
|
+
vector << 0.0
|
49
|
+
else
|
50
|
+
vector << (((gi-datos[indice][0])+(gi_1-datos[indice][0]))/2)*5
|
51
|
+
end
|
52
|
+
end
|
53
|
+
vector.reduce(:+)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# Esta clase permite representar un alimento especificando además su grupo.
|
58
|
+
|
59
|
+
class Grupo_alimento < Alimento_
|
60
|
+
attr_reader :grupo
|
61
|
+
#Constructor al que se le pasa el nombre del alimmento, cantidad de proteinas, cantidad de lipidos y cantidad de glucidos
|
62
|
+
#y el grupo al que pertenece
|
63
|
+
def initialize(nombre, proteinas, glucidos, grasas, grupo)
|
64
|
+
super(nombre, proteinas, glucidos, grasas)
|
65
|
+
@grupo = grupo
|
66
|
+
end
|
67
|
+
|
68
|
+
#Metodo to_s:
|
69
|
+
# =>formato= Nombre del alimento nºproteinas nºglucido nºlipidos grupo al que pertence
|
70
|
+
def to_s
|
71
|
+
super.to_s + "\t" + @grupo
|
72
|
+
end
|
73
|
+
end
|
data/lib/food/list.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
# Author:: Cristian Jonay Ramos González
|
5
|
+
# Alu:: alu0100904406
|
6
|
+
# Copyright:: Cretive Commons
|
7
|
+
# License:: Distributes under the same terms as Ruby
|
8
|
+
|
9
|
+
require "food/version"
|
10
|
+
|
11
|
+
# Esta clase permite representar nodo con un nodo siguiente y un nodo anterior.
|
12
|
+
# Se ha incluido el moduulo enumerable
|
13
|
+
|
14
|
+
Node = Struct.new(:value, :next, :prev)
|
15
|
+
|
16
|
+
# Esta clase permite representar una lista doblemente enlazada.
|
17
|
+
class Lista
|
18
|
+
include Enumerable
|
19
|
+
attr_reader :first, :last
|
20
|
+
|
21
|
+
# Constructor al que se le pasa el primer y ultimo nodo de una lista.
|
22
|
+
def initialize(first, last)
|
23
|
+
@first = first
|
24
|
+
@last = last
|
25
|
+
end
|
26
|
+
|
27
|
+
# Método para insertar uno o varios elementos al final de la lista.
|
28
|
+
def insertEnd *args
|
29
|
+
args.each do |arg_item|
|
30
|
+
node = Node.new(arg_item, nil, nil)
|
31
|
+
if @last == nil
|
32
|
+
@last = @first = node
|
33
|
+
else
|
34
|
+
@last.next = node
|
35
|
+
node.prev = @last
|
36
|
+
@last = node
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Método para extraer el primer nodo de la lista.
|
42
|
+
def pop_first
|
43
|
+
@first = @first.next
|
44
|
+
@first.prev = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
# Método para extraer el último nodo de la lista.
|
48
|
+
def pop_last
|
49
|
+
@last = @last.prev
|
50
|
+
@last.next = nil
|
51
|
+
end
|
52
|
+
|
53
|
+
# Método each que hace un yield de cada elemento de la lista.
|
54
|
+
def each
|
55
|
+
node = self.first
|
56
|
+
while node != nil do
|
57
|
+
yield node.value
|
58
|
+
node = node.next
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def seleccion
|
63
|
+
vector = self.map { |x| x }
|
64
|
+
for i in 0..self.count-1
|
65
|
+
aux = vector[i]
|
66
|
+
c = i
|
67
|
+
|
68
|
+
for j in i + 1..self.count-1
|
69
|
+
if aux > vector[j]
|
70
|
+
aux = vector[j]
|
71
|
+
c = j
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
vector[c] = vector[i]
|
76
|
+
vector[i] = aux
|
77
|
+
end
|
78
|
+
vector
|
79
|
+
end
|
80
|
+
|
81
|
+
def seleccion_each
|
82
|
+
vector = self.map { |x| x }
|
83
|
+
indice=0
|
84
|
+
vector.each do |x|
|
85
|
+
aux = x
|
86
|
+
c=indice
|
87
|
+
indice2=indice+1
|
88
|
+
|
89
|
+
vector[indice2..vector.length-1].each do |y|
|
90
|
+
if aux > y
|
91
|
+
aux = y
|
92
|
+
c = indice2
|
93
|
+
end
|
94
|
+
indice2+=1
|
95
|
+
end
|
96
|
+
|
97
|
+
vector[c] = x
|
98
|
+
vector[indice] = aux
|
99
|
+
|
100
|
+
indice+=1
|
101
|
+
end
|
102
|
+
vector
|
103
|
+
end
|
104
|
+
end
|