Menudiet_alu0100600216 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +111 -0
- data/Guardfile +83 -0
- data/README.md +31 -0
- data/Rakefile +36 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/Menudiet_alu0100600216.rb +101 -0
- data/lib/Menudiet_alu0100600216/Array.rb +60 -0
- data/lib/Menudiet_alu0100600216/DatosAnt.rb +111 -0
- data/lib/Menudiet_alu0100600216/Lista.rb +203 -0
- data/lib/Menudiet_alu0100600216/MenuDiet.rb +183 -0
- data/lib/Menudiet_alu0100600216/Persona.rb +95 -0
- data/lib/Menudiet_alu0100600216/version.rb +3 -0
- data/menudiet_alu0100600216.gemspec +46 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f119b24f320193914b2326d592a41faf5eda77eb4d2d80d33d175fe784accba5
|
4
|
+
data.tar.gz: 4fa1fc7a7dfd459a506e3368d0a29cdd2fa6c9dd2c4dec794bbda6f493a4c628
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 781e0208db1b8269b2dd4ba2b0d0fca96d421c69795c84d4e0801c667cb4439c5bccf28484728ee768e9fc5ef7cd9c12eefb60433137bb166f06943939a349a1
|
7
|
+
data.tar.gz: 2b7683eac1222fc78fdb44ecef9ebd10bc141318372831b6c5474baa99a573f99348406646bed8c027cf3aad1e011d34de9a99cbb2e302142bf59c7c8fb19d8c
|
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/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
Menudiet_alu0100600216 (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
coveralls (0.7.1)
|
11
|
+
multi_json (~> 1.3)
|
12
|
+
rest-client
|
13
|
+
simplecov (>= 0.7)
|
14
|
+
term-ansicolor
|
15
|
+
thor
|
16
|
+
diff-lcs (1.3)
|
17
|
+
docile (1.3.1)
|
18
|
+
domain_name (0.5.20180417)
|
19
|
+
unf (>= 0.0.5, < 1.0.0)
|
20
|
+
ffi (1.9.25)
|
21
|
+
formatador (0.2.5)
|
22
|
+
guard (2.15.0)
|
23
|
+
formatador (>= 0.2.4)
|
24
|
+
listen (>= 2.7, < 4.0)
|
25
|
+
lumberjack (>= 1.0.12, < 2.0)
|
26
|
+
nenv (~> 0.1)
|
27
|
+
notiffany (~> 0.0)
|
28
|
+
pry (>= 0.9.12)
|
29
|
+
shellany (~> 0.0)
|
30
|
+
thor (>= 0.18.1)
|
31
|
+
guard-bundler (2.1.0)
|
32
|
+
bundler (~> 1.0)
|
33
|
+
guard (~> 2.2)
|
34
|
+
guard-compat (~> 1.1)
|
35
|
+
guard-compat (1.2.1)
|
36
|
+
guard-rspec (4.7.3)
|
37
|
+
guard (~> 2.1)
|
38
|
+
guard-compat (~> 1.1)
|
39
|
+
rspec (>= 2.99.0, < 4.0)
|
40
|
+
http-cookie (1.0.3)
|
41
|
+
domain_name (~> 0.5)
|
42
|
+
json (2.1.0)
|
43
|
+
listen (3.1.5)
|
44
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
45
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
46
|
+
ruby_dep (~> 1.2)
|
47
|
+
lumberjack (1.0.13)
|
48
|
+
method_source (0.9.2)
|
49
|
+
mime-types (3.2.2)
|
50
|
+
mime-types-data (~> 3.2015)
|
51
|
+
mime-types-data (3.2018.0812)
|
52
|
+
multi_json (1.13.1)
|
53
|
+
nenv (0.3.0)
|
54
|
+
netrc (0.11.0)
|
55
|
+
notiffany (0.1.1)
|
56
|
+
nenv (~> 0.1)
|
57
|
+
shellany (~> 0.0)
|
58
|
+
pry (0.12.2)
|
59
|
+
coderay (~> 1.1.0)
|
60
|
+
method_source (~> 0.9.0)
|
61
|
+
rake (10.5.0)
|
62
|
+
rb-fsevent (0.10.3)
|
63
|
+
rb-inotify (0.9.10)
|
64
|
+
ffi (>= 0.5.0, < 2)
|
65
|
+
rest-client (2.0.2)
|
66
|
+
http-cookie (>= 1.0.2, < 2.0)
|
67
|
+
mime-types (>= 1.16, < 4.0)
|
68
|
+
netrc (~> 0.8)
|
69
|
+
rspec (3.8.0)
|
70
|
+
rspec-core (~> 3.8.0)
|
71
|
+
rspec-expectations (~> 3.8.0)
|
72
|
+
rspec-mocks (~> 3.8.0)
|
73
|
+
rspec-core (3.8.0)
|
74
|
+
rspec-support (~> 3.8.0)
|
75
|
+
rspec-expectations (3.8.2)
|
76
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
77
|
+
rspec-support (~> 3.8.0)
|
78
|
+
rspec-mocks (3.8.0)
|
79
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
+
rspec-support (~> 3.8.0)
|
81
|
+
rspec-support (3.8.0)
|
82
|
+
ruby_dep (1.5.0)
|
83
|
+
shellany (0.0.1)
|
84
|
+
simplecov (0.16.1)
|
85
|
+
docile (~> 1.1)
|
86
|
+
json (>= 1.8, < 3)
|
87
|
+
simplecov-html (~> 0.10.0)
|
88
|
+
simplecov-html (0.10.2)
|
89
|
+
term-ansicolor (1.7.0)
|
90
|
+
tins (~> 1.0)
|
91
|
+
thor (0.20.3)
|
92
|
+
tins (1.20.2)
|
93
|
+
unf (0.1.4)
|
94
|
+
unf_ext
|
95
|
+
unf_ext (0.0.7.5)
|
96
|
+
|
97
|
+
PLATFORMS
|
98
|
+
ruby
|
99
|
+
|
100
|
+
DEPENDENCIES
|
101
|
+
Menudiet_alu0100600216!
|
102
|
+
bundler (~> 1.17)
|
103
|
+
coveralls
|
104
|
+
guard
|
105
|
+
guard-bundler
|
106
|
+
guard-rspec
|
107
|
+
rake (~> 10.0)
|
108
|
+
rspec (~> 3.0)
|
109
|
+
|
110
|
+
BUNDLED WITH
|
111
|
+
1.17.1
|
data/Guardfile
ADDED
@@ -0,0 +1,83 @@
|
|
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
|
+
directories %w(lib spec ./) \
|
7
|
+
# .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")}
|
8
|
+
|
9
|
+
## Note: if you are using the `directories` clause above and you are not
|
10
|
+
## watching the project directory ('.'), then you will want to move
|
11
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
12
|
+
#
|
13
|
+
# $ mkdir config
|
14
|
+
# $ mv Guardfile config/
|
15
|
+
# $ ln -s config/Guardfile .
|
16
|
+
#
|
17
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
18
|
+
|
19
|
+
guard :bundler do
|
20
|
+
require 'guard/bundler'
|
21
|
+
require 'guard/bundler/verify'
|
22
|
+
helper = Guard::Bundler::Verify.new
|
23
|
+
|
24
|
+
files = ['Gemfile']
|
25
|
+
files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
|
26
|
+
|
27
|
+
# Assume files are symlinked from somewhere
|
28
|
+
files.each { |file| watch(helper.real_path(file)) }
|
29
|
+
end
|
30
|
+
|
31
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
32
|
+
# rspec may be run, below are examples of the most common uses.
|
33
|
+
# * bundler: 'bundle exec rspec'
|
34
|
+
# * bundler binstubs: 'bin/rspec'
|
35
|
+
# * spring: 'bin/rspec' (This will use spring if running and you have
|
36
|
+
# installed the spring binstubs per the docs)
|
37
|
+
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
38
|
+
# * 'just' rspec: 'rspec'
|
39
|
+
|
40
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
41
|
+
require "guard/rspec/dsl"
|
42
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
43
|
+
|
44
|
+
# Feel free to open issues for suggestions and improvements
|
45
|
+
|
46
|
+
# RSpec files
|
47
|
+
rspec = dsl.rspec
|
48
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
49
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
50
|
+
watch(rspec.spec_files)
|
51
|
+
|
52
|
+
# Ruby files
|
53
|
+
ruby = dsl.ruby
|
54
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
55
|
+
|
56
|
+
# Rails files
|
57
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
58
|
+
dsl.watch_spec_files_for(rails.app_files)
|
59
|
+
dsl.watch_spec_files_for(rails.views)
|
60
|
+
|
61
|
+
watch(rails.controllers) do |m|
|
62
|
+
[
|
63
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
64
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
65
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Rails config changes
|
70
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
71
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
72
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
73
|
+
|
74
|
+
# Capybara features specs
|
75
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
76
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
77
|
+
|
78
|
+
# Turnip features and steps
|
79
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
80
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
81
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
82
|
+
end
|
83
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Menudiet_alu0100600216
|
2
|
+
|
3
|
+
Esta gema forma parte de la evaluación de la asignatura Lenguajes y Paradigmas de Programación y describe un menú dietético.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'Menudiet_alu0100600216'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install Menudiet_alu0100600216
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Development
|
27
|
+
|
28
|
+
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.
|
29
|
+
|
30
|
+
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).
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
3
|
+
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
task :default => :spec
|
7
|
+
|
8
|
+
desc "Realizar pruebas de la clase Persona"
|
9
|
+
task :persona do
|
10
|
+
sh "rspec spec/Persona_spec.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "Realizar pruebas de la clase Lista"
|
14
|
+
task :lista do
|
15
|
+
sh "rspec spec/Lista_spec.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Realizar pruebas de la clase EtiquetaNutricional"
|
19
|
+
task :etiqueta do
|
20
|
+
sh "rspec spec/EtiquetaNutricional_spec.rb"
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Realizar pruebas del menú dietético"
|
24
|
+
task :menudiet do
|
25
|
+
sh "rspec spec/MenuDiet_spec.rb"
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Realizar pruebas de la idoneidad del menú dietético"
|
29
|
+
task :menupac do
|
30
|
+
sh "rspec spec/MenuPaciente_spec.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Realizar pruebas de benchmark"
|
34
|
+
task :benchmark do
|
35
|
+
sh "rspec spec/Benchmark_spec.rb"
|
36
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "EtiquetaNutricional"
|
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,101 @@
|
|
1
|
+
##
|
2
|
+
# Author:: Andrés Concepción Afonso
|
3
|
+
# Mail:: alu0100600216@ull.edu.es
|
4
|
+
#
|
5
|
+
# == Clase Etiqueta
|
6
|
+
# Esta clase almacena los distintos elementos de una etiqueta de información
|
7
|
+
# nutricional: el nombre del producto y la cantidad de nutrientes que contiene por cada 100g de producto
|
8
|
+
#
|
9
|
+
# Además almacena los métodos para calcular el valor energético en kcal, kJ, la
|
10
|
+
# ingesta de referencia y un método to_s para imprimir la entiqueta formateada.
|
11
|
+
#
|
12
|
+
|
13
|
+
class Etiqueta
|
14
|
+
|
15
|
+
include Comparable
|
16
|
+
attr_accessor :nombre, :grasas, :grasas_saturadas, :hidratos_carbono, :azucares, :proteinas, :sal, :grasas_mono, :grasas_poli, :polialcoholes, :almidon, :fibra, :vitaminas, :minerales
|
17
|
+
|
18
|
+
## Método initialize
|
19
|
+
def initialize(nombre, grasas, grasas_saturadas, hidratos_carbono, azucares, proteinas, sal, grasas_mono, grasas_poli, polialcoholes, almidon, fibra, vitaminas, minerales)
|
20
|
+
|
21
|
+
#obligatorias
|
22
|
+
@nombre = nombre
|
23
|
+
@grasas = grasas
|
24
|
+
@grasas_saturadas = grasas_saturadas
|
25
|
+
@hidratos_carbono = hidratos_carbono
|
26
|
+
@azucares = azucares
|
27
|
+
@proteinas = proteinas
|
28
|
+
@sal = sal
|
29
|
+
#opcionales
|
30
|
+
@grasas_mono = grasas_mono
|
31
|
+
@grasas_poli = grasas_poli
|
32
|
+
@polialcoholes = polialcoholes
|
33
|
+
@almidon = almidon
|
34
|
+
@fibra = fibra
|
35
|
+
@vitaminas = vitaminas
|
36
|
+
@minerales = minerales
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
## Método comparador (para poder usar las funciones de Comparable)
|
41
|
+
def <=>(otro)
|
42
|
+
[self.nombre, self.grasas, self.grasas_saturadas, self.hidratos_carbono, self.azucares, self.proteinas, self.sal, self.grasas_mono, self.grasas_poli, self.polialcoholes, self.almidon, self.fibra, self.vitaminas, self.minerales, self.calc_valor_energ_kJ, self.calc_valor_energ_kcal] <=> [otro.nombre, otro.grasas, otro.grasas_saturadas, otro.hidratos_carbono, otro.azucares, otro.proteinas, otro.sal, otro.grasas_mono, otro.grasas_poli, otro.polialcoholes, otro.almidon, otro.fibra, otro.vitaminas, otro.minerales, otro.calc_valor_energ_kJ, otro.calc_valor_energ_kcal]
|
43
|
+
end
|
44
|
+
|
45
|
+
## Cálculo del valor energético en kilojulios (kJ)
|
46
|
+
def calc_valor_energ_kJ()
|
47
|
+
@grasas*37 + @grasas_mono*37 + @grasas_poli*37 + @hidratos_carbono*17 + @polialcoholes*10 + @almidon*17 + @fibra*8 + @proteinas*17 + @sal*25
|
48
|
+
end
|
49
|
+
|
50
|
+
## Cálculo del valor energético en kilocalorías (kcal)
|
51
|
+
def calc_valor_energ_kcal()
|
52
|
+
@grasas*9 + @grasas_mono*9 + @grasas_poli*9 + @hidratos_carbono*4 + @polialcoholes*2.4 + @almidon*4 + @fibra*2 + @proteinas*4 + @sal*6
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# Falta ingesta referencia !!!
|
57
|
+
|
58
|
+
## Método to_s para imprimir la etiqueta bien formateada
|
59
|
+
def to_s
|
60
|
+
|
61
|
+
a = "Por porción (100g) \n"
|
62
|
+
a += "Valor energético \t #{self.calc_valor_energ_kJ} kJ / 8.400 kJ IR\n"
|
63
|
+
a += "\t\t #{self.calc_valor_energ_kcal} kcal / 2.000 kcal IR\n"
|
64
|
+
a += "Grasas \t #{@grasas} g.\n"
|
65
|
+
a += "Grasas saturadas \t #{@grasas_saturadas} g.\n"
|
66
|
+
a += "Hidratos de carbono \t #{@hidratos_carbono} g.\n"
|
67
|
+
a += "Azúcares \t #{@azucares} g.\n"
|
68
|
+
a += "Proteínas \t #{@proteinas} g.\n"
|
69
|
+
a += "Sal \t #{@sal} g.\n"
|
70
|
+
|
71
|
+
# SI HAY NUTRIENTES VOLUNTARIOS DECLARADOS
|
72
|
+
|
73
|
+
if @grasas_mono
|
74
|
+
a += "Grasas monoinsaturadas\t #{@grasas_m} g.\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
if @grasas_poli
|
78
|
+
a += "Grasas poliinsaturadas\t #{@grasas_p} g.\n"
|
79
|
+
end
|
80
|
+
|
81
|
+
if @polialcoholes
|
82
|
+
a += "Polialcoholes\t #{@polialcoholes} g.\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
if @almidon
|
86
|
+
a += "Almidón\t #{@almidon} g.\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
if @fibra
|
90
|
+
a += "Fibra alimentaria\t #{@fibra} g.\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
if @vitaminas
|
94
|
+
a += "Vitaminas\t #{@vitaminas} g.\n"
|
95
|
+
end
|
96
|
+
|
97
|
+
if @minerales
|
98
|
+
a += "Minerales\t #{@minerales} g.\n"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
##
|
2
|
+
# Author:: Andrés Concepción Afonso
|
3
|
+
# Mail:: alu0100600216@ull.edu.es
|
4
|
+
#
|
5
|
+
# == Clase Array
|
6
|
+
# Tenemos que definir manualmente los métodos de ordenación usando
|
7
|
+
# el método each y usando bucles for
|
8
|
+
#
|
9
|
+
|
10
|
+
class Array
|
11
|
+
|
12
|
+
## Método ordenar con bucle for
|
13
|
+
def ordenar_for
|
14
|
+
|
15
|
+
tmp = map{|x| x.reduce(:+)}
|
16
|
+
ordenado = []
|
17
|
+
ordenado.push(tmp[0])
|
18
|
+
|
19
|
+
for i in (1..length - 1)
|
20
|
+
for j in (0..i)
|
21
|
+
if (tmp[i] < ordenado[j])
|
22
|
+
ordenado.insert(j,tmp[i])
|
23
|
+
break
|
24
|
+
elsif (ordenado[(ordenado.length)-1] <= tmp[i])
|
25
|
+
ordenado.push(tmp[i])
|
26
|
+
break
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
return ordenado
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
## Método ordenar con each
|
35
|
+
|
36
|
+
def ordenar_each
|
37
|
+
|
38
|
+
tmp = map{ |x| x.reduce(:+)}
|
39
|
+
orden = []
|
40
|
+
i = 0
|
41
|
+
tmp.each do |x|
|
42
|
+
a = x
|
43
|
+
aux = i
|
44
|
+
j = aux+1
|
45
|
+
|
46
|
+
tmp[j..tmp.length - 1].each do |y|
|
47
|
+
if (a > y)
|
48
|
+
a = y
|
49
|
+
aux = j
|
50
|
+
end
|
51
|
+
j+=1
|
52
|
+
end
|
53
|
+
tmp[aux] = x
|
54
|
+
tmp[i] = a
|
55
|
+
i+=1
|
56
|
+
end
|
57
|
+
tmp
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
##
|
2
|
+
# Author:: Andrés Concepción Afonso
|
3
|
+
# Mail:: alu0100600216@ull.edu.es
|
4
|
+
#
|
5
|
+
# == Clase DatosAnt
|
6
|
+
# Almacena los datos antropométricos de una persona (peso, talla,
|
7
|
+
# edad, sexo y circunferencias de cintura y cadera)
|
8
|
+
#
|
9
|
+
# Además almacena los métodos para calcular el IMC, el % de grasa
|
10
|
+
# corporal y el RCC; además de clasificar el IMC y RCC de acuerdo
|
11
|
+
# a las tablas.
|
12
|
+
#
|
13
|
+
|
14
|
+
class DatosAnt
|
15
|
+
|
16
|
+
attr_accessor :peso, :talla, :edad, :sexo, :cir_cintura, :cir_cadera, :nivel_act
|
17
|
+
|
18
|
+
include Comparable
|
19
|
+
|
20
|
+
## Método initialize
|
21
|
+
def initialize(peso, talla, edad, sexo, cir_cintura, cir_cadera, nivel_act)
|
22
|
+
@peso = Float(peso)
|
23
|
+
@talla = Float(talla)
|
24
|
+
@edad = edad
|
25
|
+
@sexo = sexo
|
26
|
+
@cir_cintura = Float(cir_cintura)
|
27
|
+
@cir_cadera = Float(cir_cadera)
|
28
|
+
@nivel_act = nivel_act
|
29
|
+
end
|
30
|
+
|
31
|
+
## Método comparador (para poder usar las funciones de Comparable)
|
32
|
+
def <=>(otro)
|
33
|
+
[self.peso, self.talla, self.edad, self.sexo, self.cir_cintura, self.cir_cadera, self.indice_masa_corporal, self.porcentaje_grasa, self.rel_cir_cadera] <=> [otro.peso, otro.talla, otro.edad, otro.sexo, otro.cir_cintura, otro.cir_cadera, otro.indice_masa_corporal, otro.porcentaje_grasa, otro.rel_cir_cadera]
|
34
|
+
end
|
35
|
+
|
36
|
+
## Cálculo IMC
|
37
|
+
def indice_masa_corporal
|
38
|
+
(peso / (talla * talla) * 10000).round(1)
|
39
|
+
end
|
40
|
+
|
41
|
+
## IMC de acuerdo a la tabla
|
42
|
+
def imc_segun_tabla
|
43
|
+
imc = self.indice_masa_corporal
|
44
|
+
|
45
|
+
if imc < 18.5
|
46
|
+
return "#{imc} - menor a 18.5 - Bajo peso"
|
47
|
+
elsif imc >= 18.5 && imc < 25.0
|
48
|
+
return "#{imc} - entre 18.5 y 24.9 - Aceptable"
|
49
|
+
elsif imc >= 25.0 && imc < 30.0
|
50
|
+
return "#{imc} - entre 25.0 y 29.9 - Sobrepeso"
|
51
|
+
elsif imc >= 30.0 && imc < 35.0
|
52
|
+
return "#{imc} - entre 30.0 y 34.9 - Obesidad grado 1"
|
53
|
+
elsif imc >= 35.0
|
54
|
+
return "#{imc} - mayor a 40 - Obesidad grado 2"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
## Cálculo porcentaje de grasa corporal
|
60
|
+
def porcentaje_grasa
|
61
|
+
(1.2 * self.indice_masa_corporal + 0.23 * edad - 10.8 * sexo - 5.4).round(1)
|
62
|
+
end
|
63
|
+
|
64
|
+
## Cálculo Relación Circunferencia Cadera
|
65
|
+
def rel_cir_cadera
|
66
|
+
(cir_cintura / cir_cadera).round(2)
|
67
|
+
end
|
68
|
+
|
69
|
+
## RCC de acuerdo a la tabla
|
70
|
+
def rcc_segun_tabla
|
71
|
+
|
72
|
+
rcc = self.rel_cir_cadera
|
73
|
+
|
74
|
+
# Se discrimina según sexos
|
75
|
+
if sexo == 1
|
76
|
+
if rcc >= 0.83 && rcc < 0.88
|
77
|
+
return "#{rcc} - Bajo - entre 0.83 y 0.88"
|
78
|
+
elsif rcc >= 0.88 && rcc < 0.95
|
79
|
+
return "#{rcc} - Moderado - entre 0.88 y 0.95"
|
80
|
+
elsif rcc >= 0.95 && rcc < 1.01
|
81
|
+
return "#{rcc} - Alto - entre 0.95 y 1.01"
|
82
|
+
elsif rcc >= 1.01
|
83
|
+
return "#{rcc} - Muy alto - mayor a 1.01"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
if sexo == 0
|
88
|
+
if rcc >= 0.72 && rcc < 0.75
|
89
|
+
return "#{rcc} - Bajo - entre 0.72 y 0.75"
|
90
|
+
elsif rcc >= 0.75 && rcc < 0.82
|
91
|
+
return "#{rcc} - Moderado - entre 0.75 y 0.82"
|
92
|
+
elsif rcc >= 0.82
|
93
|
+
return "#{rcc} - Alto - mayor a 0.82"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
## Método to_s para imprimir los datos antropométricos
|
99
|
+
def to_s
|
100
|
+
a = "Peso: #{@peso}\n"
|
101
|
+
a += "Altura: #{@talla}\n"
|
102
|
+
a += "Edad: #{@edad}\n"
|
103
|
+
a += "Sexo: #{@sexo}\n"
|
104
|
+
a += "Cincurferencia cintura: #{@cir_cintura}\n"
|
105
|
+
a += "Cincurferencia cadera: #{@cir_cadera}\n"
|
106
|
+
a += "Índice Masa Corporal (IMC): #{self.imc_segun_tabla}\n"
|
107
|
+
a += "% grasa: #{self.porcentaje_grasa}\n"
|
108
|
+
a += "Relación Circunferencia Cadera (RCC): #{self.rcc_segun_tabla}\n"
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
## Definición de nodo, necesario para implementar la lista
|
2
|
+
Nodo = Struct.new(:value, :next, :prev)
|
3
|
+
|
4
|
+
##
|
5
|
+
# Author:: Andrés Concepción Afonso
|
6
|
+
# Mail:: alu0100600216@ull.edu.es
|
7
|
+
#
|
8
|
+
# == Clase Lista
|
9
|
+
# Esta clase simula una lista doblemente enlazada e implementa los
|
10
|
+
# métodos necesarios para utilizarla
|
11
|
+
#
|
12
|
+
# Además dispone de métodos para clasificar los elementos de una
|
13
|
+
# lista de acuerdo al contenido en sal (etiquetas nutricionales)
|
14
|
+
# y al IMC (para pacientes)
|
15
|
+
#
|
16
|
+
|
17
|
+
class Lista
|
18
|
+
|
19
|
+
include Enumerable
|
20
|
+
attr_accessor :head, :tail
|
21
|
+
|
22
|
+
## Metodo initialize
|
23
|
+
def initialize
|
24
|
+
@head = nil
|
25
|
+
@tail = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
## Método each, necesario para enumerar los elementos de una lista (métodos de Enumerable)
|
29
|
+
def each(&block)
|
30
|
+
nodo = Nodo.new(nil, nil, nil)
|
31
|
+
nodo = @head
|
32
|
+
|
33
|
+
while !(nodo.nil?)
|
34
|
+
yield nodo.value
|
35
|
+
nodo = nodo.next
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
## Calcula el tamaño(longitud) de la lista
|
40
|
+
def length
|
41
|
+
|
42
|
+
tam = 0
|
43
|
+
nodo = @head
|
44
|
+
|
45
|
+
while !(nodo.nil?)
|
46
|
+
tam = tam + 1
|
47
|
+
nodo = nodo.next
|
48
|
+
end
|
49
|
+
|
50
|
+
tam
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
## Comprueba si la lista está vacía
|
55
|
+
def empty
|
56
|
+
@head.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
## Insertar nodo
|
60
|
+
def insert(value)
|
61
|
+
|
62
|
+
nodo = Nodo.new(value, nil, @tail)
|
63
|
+
|
64
|
+
@head = nodo if @head.nil?
|
65
|
+
@tail.next = nodo unless @tail.nil?
|
66
|
+
@tail = nodo
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
## Extraer nodo
|
71
|
+
def extract
|
72
|
+
|
73
|
+
return nil if self.empty
|
74
|
+
|
75
|
+
temp = @head
|
76
|
+
@head = @head.next
|
77
|
+
|
78
|
+
@head.prev = nil unless @head.nil?
|
79
|
+
@tail = nil if @head.nil?
|
80
|
+
|
81
|
+
temp.next = nil
|
82
|
+
temp
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
## Método to_s para imprimir la lista de elementos
|
87
|
+
def to_s
|
88
|
+
|
89
|
+
nodo = Nodo.new(nil,nil,nil)
|
90
|
+
nodo = @head
|
91
|
+
|
92
|
+
tmp = "["
|
93
|
+
|
94
|
+
if !(nodo.nil?)
|
95
|
+
tmp += "#{nodo.value.to_s}"
|
96
|
+
nodo = nodo.next
|
97
|
+
end
|
98
|
+
|
99
|
+
while !(nodo.nil?)
|
100
|
+
tmp += ", #{nodo.value.to_s}"
|
101
|
+
nodo = nodo.next
|
102
|
+
end
|
103
|
+
|
104
|
+
tmp += "]"
|
105
|
+
tmp
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
## Método ordenar con bucle for
|
110
|
+
|
111
|
+
def ordenar_for
|
112
|
+
|
113
|
+
tmp = map{|x| x.gasto_energetico_total}
|
114
|
+
ordenado = []
|
115
|
+
ordenado.push(tmp[0])
|
116
|
+
|
117
|
+
for i in (1..length - 1)
|
118
|
+
for j in (0..i)
|
119
|
+
if(ordenado[j] >= tmp[i])
|
120
|
+
ordenado.insert(j,tmp[i])
|
121
|
+
break
|
122
|
+
elsif(ordenado[ordenado.length - 1] <= tmp[i])
|
123
|
+
ordenado.push(tmp[i])
|
124
|
+
break
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
ordenado
|
129
|
+
end
|
130
|
+
|
131
|
+
## Método ordenar con each
|
132
|
+
|
133
|
+
def ordenar_each
|
134
|
+
tmp = map{ |x| x.gasto_energetico_total}
|
135
|
+
i = 0
|
136
|
+
tmp.each do |x|
|
137
|
+
a = x
|
138
|
+
aux = i
|
139
|
+
j = aux + 1
|
140
|
+
|
141
|
+
tmp[j..tmp.length - 1].each do |y|
|
142
|
+
if (a > y)
|
143
|
+
a = y
|
144
|
+
aux = j
|
145
|
+
end
|
146
|
+
j+=1
|
147
|
+
end
|
148
|
+
tmp[aux] = x
|
149
|
+
tmp[i] = a
|
150
|
+
i+=1
|
151
|
+
end
|
152
|
+
tmp
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
## Clasificar una lista de Etiquetas por el contenido en sal
|
159
|
+
def clasificar_por_sal (lista)
|
160
|
+
|
161
|
+
sal_recomendada = Lista.new()
|
162
|
+
sal_excesiva = Lista.new()
|
163
|
+
|
164
|
+
nodo = lista.extract
|
165
|
+
|
166
|
+
while !(nodo.nil?)
|
167
|
+
|
168
|
+
if nodo.value.sal > 6
|
169
|
+
sal_excesiva.insert(nodo.value.sal)
|
170
|
+
else
|
171
|
+
sal_recomendada.insert(nodo.value.sal)
|
172
|
+
end
|
173
|
+
nodo = lista.extract
|
174
|
+
end
|
175
|
+
|
176
|
+
"Los productos con una cantidad de sal menor o igual a la recomendada son #{sal_recomendada.to_s} y los que tienen una sal excesiva son #{sal_excesiva.to_s}"
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
## Clasificar una lista de personas por el IMC
|
181
|
+
def clasificar_por_imc (lista)
|
182
|
+
|
183
|
+
imc_bajo = Lista.new()
|
184
|
+
imc_normal = Lista.new()
|
185
|
+
imc_excesivo = Lista.new()
|
186
|
+
|
187
|
+
nodo = lista.extract
|
188
|
+
|
189
|
+
while !(nodo.nil?)
|
190
|
+
|
191
|
+
if nodo.value.datos_ant.indice_masa_corporal >= 30
|
192
|
+
imc_excesivo.insert(nodo.value.datos_ant.indice_masa_corporal)
|
193
|
+
elsif nodo.value.datos_ant.indice_masa_corporal >=18.5
|
194
|
+
imc_normal.insert(nodo.value.datos_ant.indice_masa_corporal)
|
195
|
+
else
|
196
|
+
imc_bajo.insert(nodo.value.datos_ant.indice_masa_corporal)
|
197
|
+
end
|
198
|
+
nodo = lista.extract
|
199
|
+
end
|
200
|
+
|
201
|
+
"Los IMC por debajo de lo normal son #{imc_bajo.to_s}, los IMC dentro de lo normal son #{imc_normal.to_s} y los que tienen un IMC excesivo son #{imc_excesivo.to_s}"
|
202
|
+
|
203
|
+
end
|
@@ -0,0 +1,183 @@
|
|
1
|
+
require "./lib/Menudiet_alu0100600216.rb"
|
2
|
+
|
3
|
+
##
|
4
|
+
# Author:: Andrés Concepción Afonso
|
5
|
+
# Mail:: alu0100600216@ull.edu.es
|
6
|
+
#
|
7
|
+
# == Clase Menu
|
8
|
+
# Esta clase implementa un menú dietético como DSL
|
9
|
+
#
|
10
|
+
|
11
|
+
class Menu
|
12
|
+
|
13
|
+
## Método initialize
|
14
|
+
def initialize(nombre, &block)
|
15
|
+
@nombre = nombre
|
16
|
+
@desayuno = []
|
17
|
+
@almuerzo = []
|
18
|
+
@cena = []
|
19
|
+
|
20
|
+
if block_given?
|
21
|
+
if block.arity == 1
|
22
|
+
yield self
|
23
|
+
else
|
24
|
+
instance_eval(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Definición del título
|
30
|
+
def titulo(title)
|
31
|
+
@titulo = title
|
32
|
+
end
|
33
|
+
|
34
|
+
# Definición de la ingesta
|
35
|
+
def ingesta(options = {})
|
36
|
+
|
37
|
+
@min = (options[:min]) if options[:min]
|
38
|
+
@max = (options[:max]) if options[:max]
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# Definición del desayuno
|
43
|
+
def desayuno(nombre_alimento, options = {})
|
44
|
+
|
45
|
+
nombre_alimento = nombre_alimento
|
46
|
+
porcion = options[:porcion] ? options[:porcion] : nil
|
47
|
+
grasas = options[:grasas] ? options[:grasas] : 0.0
|
48
|
+
grasas_saturadas = options[:grasas_saturadas] ? options[:grasas_saturadas] : 0.0
|
49
|
+
hidratos_carbono = options[:hidratos_carbono] ? options[:hidratos_carbono] : 0.0
|
50
|
+
azucares = options[:azucares] ? options[:azucares] : 0.0
|
51
|
+
proteinas = options[:proteinas] ? options[:proteinas] : 0.0
|
52
|
+
sal = options[:sal] ? options[:sal] : 0.0
|
53
|
+
grasas_mono = options[:grasas_mono] ? options[:grasas_mono] : 0.0
|
54
|
+
grasas_poli = options[:grasas_poli] ? options[:grasas_poli] : 0.0
|
55
|
+
polialcoholes = options[:polialcoholes] ? options[:polialcoholes] : 0.0
|
56
|
+
almidon = options[:almidon] ? options[:almidon] : 0.0
|
57
|
+
fibra = options[:fibra] ? options[:fibra] : 0.0
|
58
|
+
vitaminas = options[:vitaminas] ? options[:vitaminas] : 0.0
|
59
|
+
minerales = options[:minerales] ? options[:minerales] : 0.0
|
60
|
+
|
61
|
+
etiqueta = Etiqueta.new(nombre_alimento, grasas, grasas_saturadas, hidratos_carbono, azucares, proteinas, sal, grasas_mono, grasas_poli, polialcoholes, almidon, fibra, vitaminas, minerales)
|
62
|
+
etiqueta.calc_valor_energ_kcal()
|
63
|
+
|
64
|
+
@desayuno << etiqueta
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# Definición del almuerzo
|
69
|
+
def almuerzo(nombre_alimento, options = {})
|
70
|
+
|
71
|
+
nombre_alimento = nombre_alimento
|
72
|
+
porcion = options[:porcion] ? options[:porcion] : nil
|
73
|
+
grasas = options[:grasas] ? options[:grasas] : 0.0
|
74
|
+
grasas_saturadas = options[:grasas_saturadas] ? options[:grasas_saturadas] : 0.0
|
75
|
+
hidratos_carbono = options[:hidratos_carbono] ? options[:hidratos_carbono] : 0.0
|
76
|
+
azucares = options[:azucares] ? options[:azucares] : 0.0
|
77
|
+
proteinas = options[:proteinas] ? options[:proteinas] : 0.0
|
78
|
+
sal = options[:sal] ? options[:sal] : 0.0
|
79
|
+
grasas_mono = options[:grasas_mono] ? options[:grasas_mono] : 0.0
|
80
|
+
grasas_poli = options[:grasas_poli] ? options[:grasas_poli] : 0.0
|
81
|
+
polialcoholes = options[:polialcoholes] ? options[:polialcoholes] : 0.0
|
82
|
+
almidon = options[:almidon] ? options[:almidon] : 0.0
|
83
|
+
fibra = options[:fibra] ? options[:fibra] : 0.0
|
84
|
+
vitaminas = options[:vitaminas] ? options[:vitaminas] : 0.0
|
85
|
+
minerales = options[:minerales] ? options[:minerales] : 0.0
|
86
|
+
|
87
|
+
etiqueta = Etiqueta.new(nombre_alimento, grasas, grasas_saturadas, hidratos_carbono, azucares, proteinas, sal, grasas_mono, grasas_poli, polialcoholes, almidon, fibra, vitaminas, minerales)
|
88
|
+
etiqueta.calc_valor_energ_kcal()
|
89
|
+
|
90
|
+
@almuerzo << etiqueta
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# Definición de la cena
|
95
|
+
def cena(nombre_alimento, options = {})
|
96
|
+
|
97
|
+
nombre_alimento = nombre_alimento
|
98
|
+
porcion = options[:porcion] ? options[:porcion] : nil
|
99
|
+
grasas = options[:grasas] ? options[:grasas] : 0.0
|
100
|
+
grasas_saturadas = options[:grasas_saturadas] ? options[:grasas_saturadas] : 0.0
|
101
|
+
hidratos_carbono = options[:hidratos_carbono] ? options[:hidratos_carbono] : 0.0
|
102
|
+
azucares = options[:azucares] ? options[:azucares] : 0.0
|
103
|
+
proteinas = options[:proteinas] ? options[:proteinas] : 0.0
|
104
|
+
sal = options[:sal] ? options[:sal] : 0.0
|
105
|
+
grasas_mono = options[:grasas_mono] ? options[:grasas_mono] : 0.0
|
106
|
+
grasas_poli = options[:grasas_poli] ? options[:grasas_poli] : 0.0
|
107
|
+
polialcoholes = options[:polialcoholes] ? options[:polialcoholes] : 0.0
|
108
|
+
almidon = options[:almidon] ? options[:almidon] : 0.0
|
109
|
+
fibra = options[:fibra] ? options[:fibra] : 0.0
|
110
|
+
vitaminas = options[:vitaminas] ? options[:vitaminas] : 0.0
|
111
|
+
minerales = options[:minerales] ? options[:minerales] : 0.0
|
112
|
+
|
113
|
+
etiqueta = Etiqueta.new(nombre_alimento, grasas, grasas_saturadas, hidratos_carbono, azucares, proteinas, sal, grasas_mono, grasas_poli, polialcoholes, almidon, fibra, vitaminas, minerales)
|
114
|
+
etiqueta.calc_valor_energ_kcal()
|
115
|
+
|
116
|
+
@cena << etiqueta
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# calculamos el valor energético total
|
121
|
+
def valor_energetico_total
|
122
|
+
|
123
|
+
@valor_energetico = @desayuno.map{|x| x.calc_valor_energ_kcal}.reduce(:+)
|
124
|
+
@valor_energetico += @almuerzo.map{|x| x.calc_valor_energ_kcal}.reduce(:+)
|
125
|
+
@valor_energetico += @cena.map{|x| x.calc_valor_energ_kcal}.reduce(:+)
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
# método to_s
|
130
|
+
def to_s
|
131
|
+
|
132
|
+
output = "\n"
|
133
|
+
output << "%-25s" % "#{@nombre}"
|
134
|
+
|
135
|
+
output << "Composición Nutricional\n"
|
136
|
+
output << "================================================================================================\n"
|
137
|
+
output << "\t\t\t Grasas Hidr. Carbono \tProteínas Fibra \tSal \tValor energético\n"
|
138
|
+
|
139
|
+
output << "Desayuno\n"
|
140
|
+
@desayuno.each do |alimento|
|
141
|
+
|
142
|
+
output << "%-25s" % "#{alimento.nombre}"
|
143
|
+
output << "%-6s" % "#{alimento.grasas}"
|
144
|
+
output << "\t #{alimento.hidratos_carbono}"
|
145
|
+
output << "\t\t#{alimento.proteinas}"
|
146
|
+
output << "\t #{alimento.fibra} "
|
147
|
+
output << "\t#{alimento.sal}\t"
|
148
|
+
output << "#{(alimento.calc_valor_energ_kcal*10).floor / 100.0 }\n"
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
output << "\nAlmuerzo\n"
|
153
|
+
@almuerzo.each do |alimento|
|
154
|
+
|
155
|
+
output << "%-25s" % "#{alimento.nombre}"
|
156
|
+
output << "%-6s" % "#{alimento.grasas}"
|
157
|
+
output << "\t #{alimento.hidratos_carbono}"
|
158
|
+
output << "\t\t#{alimento.proteinas}"
|
159
|
+
output << "\t #{alimento.fibra} "
|
160
|
+
output << "\t#{alimento.sal}\t"
|
161
|
+
output << "#{(alimento.calc_valor_energ_kcal*10).floor / 100.0 }\n"
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
output << "\nCena\n"
|
166
|
+
@cena.each do |alimento|
|
167
|
+
|
168
|
+
output << "%-25s" % "#{alimento.nombre}"
|
169
|
+
output << "%-6s" % "#{alimento.grasas}"
|
170
|
+
output << "\t #{alimento.hidratos_carbono}"
|
171
|
+
output << "\t\t#{alimento.proteinas}"
|
172
|
+
output << "\t #{alimento.fibra} "
|
173
|
+
output << "\t#{alimento.sal}\t"
|
174
|
+
output << "#{(alimento.calc_valor_energ_kcal*10).floor / 100.0 }\n"
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
output << "\nValor energético total "
|
179
|
+
output << "#{valor_energetico_total}\n\n"
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
|
2
|
+
require "Menudiet_alu0100600216/DatosAnt"
|
3
|
+
|
4
|
+
##
|
5
|
+
# Author:: Andrés Concepción Afonso
|
6
|
+
# Mail:: alu0100600216@ull.edu.es
|
7
|
+
#
|
8
|
+
# == Clase Persona
|
9
|
+
# Esta clase sólo almacena el nombre de una persona. Es necesaria para
|
10
|
+
# que la clase hija Paciente herede los atributos de Persona
|
11
|
+
#
|
12
|
+
|
13
|
+
class Persona
|
14
|
+
|
15
|
+
attr_accessor :nombre
|
16
|
+
|
17
|
+
## Método initialize
|
18
|
+
def initialize(nombre)
|
19
|
+
@nombre = nombre
|
20
|
+
end
|
21
|
+
|
22
|
+
## Método to_s
|
23
|
+
def to_s
|
24
|
+
"El nombre es #{nombre}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# == Clase Paciente
|
30
|
+
# Paciente es una clase hija de la clase Persona que almacena además
|
31
|
+
# del nombre los datos antropométricos de dicho paciente (que se
|
32
|
+
# encuentran en un objeto DatosAnt)
|
33
|
+
#
|
34
|
+
|
35
|
+
class Paciente < Persona
|
36
|
+
|
37
|
+
include Comparable
|
38
|
+
attr_accessor :datos_ant
|
39
|
+
|
40
|
+
## Método initialize
|
41
|
+
def initialize(nombre, peso, talla, edad, sexo, cir_cintura, cir_cadera, nivel_act)
|
42
|
+
@nombre = nombre
|
43
|
+
@datos_ant = DatosAnt.new(peso, talla, edad, sexo, cir_cintura, cir_cadera, nivel_act)
|
44
|
+
end
|
45
|
+
|
46
|
+
## Método comparador (necesario para poder usar las funciones de Comparable)
|
47
|
+
def <=>(otro)
|
48
|
+
[nombre] <=> [otro.nombre]
|
49
|
+
end
|
50
|
+
|
51
|
+
## Método to_s para imprimir los datos de un paciente
|
52
|
+
def to_s
|
53
|
+
a = "Nombre del paciente: #{@nombre}\n"
|
54
|
+
a += @datos_ant.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
## Peso teórico ideal
|
58
|
+
def peso_teorico_ideal
|
59
|
+
(@datos_ant.talla - 150) * 0.75 + 50
|
60
|
+
end
|
61
|
+
|
62
|
+
## Gasto energético basal
|
63
|
+
def gasto_energetico_basal
|
64
|
+
if @datos_ant.sexo == 0
|
65
|
+
(10 * @datos_ant.peso) + (6.25 * @datos_ant.talla) - (5 * @datos_ant.edad) - 161
|
66
|
+
else
|
67
|
+
(10 * @datos_ant.peso) + (6.25 * @datos_ant.talla) - (5 * @datos_ant.edad) + 5
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
## Efecto termógeno de los alimentos
|
72
|
+
def efecto_termogeno
|
73
|
+
self.gasto_energetico_basal * 0.1
|
74
|
+
end
|
75
|
+
|
76
|
+
## Gasto por actividad física
|
77
|
+
def gasto_actividad_fisica
|
78
|
+
if @datos_ant.nivel_act == 0
|
79
|
+
factor_act = 0.0
|
80
|
+
elsif @datos_ant.nivel_act == 1
|
81
|
+
factor_act = 0.12
|
82
|
+
elsif @datos_ant.nivel_act == 2
|
83
|
+
factor_act = 0.27
|
84
|
+
else
|
85
|
+
factor_act = 0.54
|
86
|
+
end
|
87
|
+
self.gasto_energetico_basal * factor_act
|
88
|
+
end
|
89
|
+
|
90
|
+
## Gasto energético total
|
91
|
+
def gasto_energetico_total
|
92
|
+
self.gasto_energetico_basal + self.efecto_termogeno + self.gasto_actividad_fisica
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "Menudiet_alu0100600216/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "Menudiet_alu0100600216"
|
8
|
+
spec.version = Menudiet_alu0100600216::VERSION
|
9
|
+
spec.authors = ["Andrés Concepción Afonso"]
|
10
|
+
spec.email = ["alu0100600216@ull.edu.es"]
|
11
|
+
|
12
|
+
spec.summary = "Menú dietético"
|
13
|
+
spec.description = "Define un menú dietético y los métodos para calcular sus valores nutricionales"
|
14
|
+
spec.homepage = "https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100600216"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
#if spec.respond_to?(:metadata)
|
19
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
20
|
+
|
21
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
22
|
+
# spec.metadata["source_code_uri"] = "https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100600216"
|
23
|
+
##spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
24
|
+
#else
|
25
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
26
|
+
# "public gem pushes."
|
27
|
+
#end
|
28
|
+
|
29
|
+
# Specify which files should be added to the gem when it is released.
|
30
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
31
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
32
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
## Guard
|
42
|
+
spec.add_development_dependency "guard"
|
43
|
+
spec.add_development_dependency "guard-rspec"
|
44
|
+
spec.add_development_dependency "guard-bundler"
|
45
|
+
spec.add_development_dependency "coveralls"
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Menudiet_alu0100600216
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrés Concepción Afonso
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Define un menú dietético y los métodos para calcular sus valores nutricionales
|
112
|
+
email:
|
113
|
+
- alu0100600216@ull.edu.es
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".DS_Store"
|
119
|
+
- ".coveralls.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- Gemfile.lock
|
125
|
+
- Guardfile
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/Menudiet_alu0100600216.rb
|
131
|
+
- lib/Menudiet_alu0100600216/Array.rb
|
132
|
+
- lib/Menudiet_alu0100600216/DatosAnt.rb
|
133
|
+
- lib/Menudiet_alu0100600216/Lista.rb
|
134
|
+
- lib/Menudiet_alu0100600216/MenuDiet.rb
|
135
|
+
- lib/Menudiet_alu0100600216/Persona.rb
|
136
|
+
- lib/Menudiet_alu0100600216/version.rb
|
137
|
+
- menudiet_alu0100600216.gemspec
|
138
|
+
homepage: https://github.com/ULL-ESIT-LPP-1819/tdd-alu0100600216
|
139
|
+
licenses: []
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 2.7.8
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Menú dietético
|
161
|
+
test_files: []
|