nutrientesEugenio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f884273252b89f65f204d64dd9ce29fea4ca0b27
4
+ data.tar.gz: 3fbbe7e2a300c26cd0b3317b469c81e3a0948d30
5
+ SHA512:
6
+ metadata.gz: de58a841c6f10e471da717d0b76c1503c688582f74c4c31d0181dd048389e6c93f021239ee16b573bd8c6f8cc5cbf329792458dd298c476a885bf2532a2d5f64
7
+ data.tar.gz: 58f97ba8e785c31e325e0c97b02b162de7d053e51e9ad86f15c60eb5573e562357fd6284039874fe20dab55b71e74135af97a0f343e9f09d48f116efe23c0bf0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in nutrientesEugenio.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nutrientesEugenio (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.7.0)
70
+ rspec-core (~> 3.7.0)
71
+ rspec-expectations (~> 3.7.0)
72
+ rspec-mocks (~> 3.7.0)
73
+ rspec-core (3.7.0)
74
+ rspec-support (~> 3.7.0)
75
+ rspec-expectations (3.7.0)
76
+ diff-lcs (>= 1.2.0, < 2.0)
77
+ rspec-support (~> 3.7.0)
78
+ rspec-mocks (3.7.0)
79
+ diff-lcs (>= 1.2.0, < 2.0)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-support (3.7.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
+ bundler (~> 1.16)
102
+ coveralls
103
+ guard
104
+ guard-bundler
105
+ guard-rspec
106
+ nutrientesEugenio!
107
+ rake (~> 10.0)
108
+ rspec (~> 3.0)
109
+
110
+ BUNDLED WITH
111
+ 1.16.0
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.exist?(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/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # NutrientesEugenio
2
+
3
+ [![Coverage Status](https://coveralls.io/repos/github/ULL-ESIT-LPP-1819/tdd-alu0101000756/badge.svg)](https://coveralls.io/github/ULL-ESIT-LPP-1819/tdd-alu0101000756)
4
+ [![Build Status](https://travis-ci.org/ULL-ESIT-LPP-1819/tdd-alu0101000756.svg?branch=master)](https://travis-ci.org/ULL-ESIT-LPP-1819/tdd-alu0101000756)
5
+
6
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nutrientesEugenio`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+
8
+ TODO: Delete this and the text above, and describe your gem
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'nutrientesEugenio'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install nutrientesEugenio
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nutrientesEugenio.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nutrientesEugenio"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/dietaDia.rb ADDED
@@ -0,0 +1,84 @@
1
+ require "nutrientesEugenio/version"
2
+
3
+
4
+ # Representación de un Menu dietetico
5
+ #
6
+ # @author Eugenio Jose Gonzalez Luis
7
+ # @since 1.0.0
8
+ class DietaDia
9
+ include Comparable
10
+
11
+ attr_reader :nombre, :desayuno, :almuerzo, :cena
12
+
13
+ def initialize(nombre, &bloque)
14
+ @nombre = nombre
15
+ @desayuno = Menu.new()
16
+ @almuerzo = Menu.new()
17
+ @cena = Menu.new()
18
+ if block_given?
19
+ if bloque.arity == 1
20
+ yield self
21
+ else
22
+ instance_eval(&bloque)
23
+ end
24
+ end
25
+ end
26
+ # metodo que calcula el coste calorico de una dieta diaria
27
+ #
28
+ # @return [Number] Coste calorico de la dieta diaria
29
+ def kcal
30
+ @desayuno.kcal + @almuerzo.kcal + @cena.kcal
31
+ end
32
+
33
+ # metodo que calcula si una dieta es suficiente para un individuo dado
34
+ # @param [Individuo] persona persona para la cual se calcula si es suficiente
35
+ # @param [cantidad] cantidad de ejercicio que esa persona realiza
36
+ #
37
+ # @return [Boolean] devuelve si la dieta es o no suficiente para una persona
38
+ def is_enough(persona, cantidad)
39
+ x = kcal
40
+ return (persona.gasto_energetico_total(cantidad) <= x * 1.1) && (persona.gasto_energetico_total(cantidad) >= x * 0.9)
41
+ end
42
+ # Metodo para comparar dos dietas
43
+ # @param [Individuo] otra dieta a comparar
44
+ #
45
+ # @return [-1,0,1] -1 si es menor, 0 si son iguales, 1 si es mayor
46
+ def <=>(other)
47
+ kcal <=> other.kcal
48
+ end
49
+
50
+ # Convierte el objeto en un String
51
+ # @return [String] descripción del plato en una cadena de caracteres
52
+ def to_s
53
+ texto = @nombre
54
+ texto << "\n#{'=' * @nombre.size}\n"
55
+ texto << "Composicion nutricional: \n"
56
+ texto << @desayuno.to_s
57
+ texto << "\n"
58
+ texto << @almuerzo.to_s
59
+ texto << "\n"
60
+ texto << @cena.to_s
61
+ texto << "\n"
62
+ texto << "#{@kcal}"
63
+ texto << "\n"
64
+ return texto
65
+ end
66
+
67
+ #Añade un desayuno
68
+ #@param options información sobre el alimento
69
+ def desayuno(options = {})
70
+ @desayuno.push_head(Alimento.new(options[:descripcion],options[:grasas],0,options[:carbohidratos],0,options[:proteinas],options[:sal]))
71
+ end
72
+
73
+ #Añade un almuerzo
74
+ #@param options información sobre el alimento
75
+ def almuerzo(options = {})
76
+ @almuerzo.push_head(Alimento.new(options[:descripcion],options[:grasas],0,options[:carbohidratos],0,options[:proteinas],options[:sal]))
77
+ end
78
+
79
+ #Añade una cena
80
+ #@param options información sobre el alimento
81
+ def cena(options = {})
82
+ @cena.push_head(Alimento.new(options[:descripcion],options[:grasas],0,options[:carbohidratos],0,options[:proteinas],options[:sal]))
83
+ end
84
+ end
data/lib/imc.rb ADDED
@@ -0,0 +1,50 @@
1
+ require "nutrientesEugenio/version"
2
+ # Clase con datos nutricionales
3
+ #
4
+ # @attr_reader [Number] a peso del paciente
5
+ # @attr_reader [Number] b altura del paciente
6
+ # @attr_reader [Number] c edad del paciente
7
+ # @attr_reader [1,0] d sexo del paciente
8
+ class IMC
9
+ attr_reader :peso, :altura, :edad, :sexo
10
+
11
+ # Constructor de un imc
12
+ #
13
+ # @param [Number] a peso del paciente
14
+ # @param [Number] b altura del paciente
15
+ # @param [Number] c edad del paciente
16
+ # @param [1,0] d sexo del paciente
17
+ #
18
+ # @return [IMC] objeto
19
+ def initialize(a,b,c,d)
20
+ @peso = a
21
+ @altura = b
22
+ @edad = c
23
+ @sexo = d
24
+ end
25
+ # Calcula el imc de un individuo
26
+ #
27
+ # return [Number] imc
28
+ def calcular_imc
29
+ (@peso)/(@altura*@altura)
30
+ end
31
+ # Calcula el %graso
32
+ #
33
+ # return [Number] %graso
34
+ def porcentaje_graso
35
+ (1.2*calcular_imc)+(0.23*@edad)-(10.8*@sexo)-5.4
36
+ end
37
+ # Convierte el objeto a una cadena de caracteres
38
+ #
39
+ # @return [String] devuelve el imc como un string
40
+ def to_s
41
+ rval = ""
42
+ rval += " pesa #{@peso} kilos , mide #{@altura} metros, tiene #{@edad} años y es"
43
+ if(sexo == 1)
44
+ rval+= " un hombre"
45
+ else
46
+ rval+= " una mujer"
47
+ end
48
+ rval
49
+ end
50
+ end
data/lib/individuo.rb ADDED
@@ -0,0 +1,115 @@
1
+ require "nutrientesEugenio/version"
2
+
3
+ # Representación de un individuo
4
+ #
5
+ # @author Eugenio José Gonzalez Luis
6
+ # @since 1.0.0
7
+ # @attr_reader String nombre Nombre del individuo
8
+ # @attr_reader Boolean paciente Determina si el individuo es un paciente o no
9
+ # @attr_reader Boolean t_obesidad Determina si el individuo esta recibiendo tratamiendo de obesidad o no
10
+ class Individuo < IMC
11
+ include Comparable
12
+ attr_reader :nombre, :paciente, :t_obesidad
13
+
14
+ # Constructor de un individuo
15
+ #
16
+ # @param [String] nombre Nombre del individuo
17
+ # @param [Boolean] paciente Determina si el individuo es un paciente o no
18
+ # @param [Boolean] t_obesidad Determina si el individuo esta recibiendo tratamiendo de obesidad o no
19
+ # @param [Number] a peso del paciente
20
+ # @param [Number] b altura del paciente
21
+ # @param [Number] c edad del paciente
22
+ # @param [1,0] d sexo del paciente
23
+ #
24
+ # @return [Individuo] objeto
25
+ def initialize(nombre, paciente, t_obesidad, a, b, c, d)
26
+ @nombre = nombre
27
+ @paciente = paciente
28
+ @t_obesidad = t_obesidad
29
+ if t_obesidad
30
+ super(a,b,c,d)
31
+ end
32
+ end
33
+
34
+ # Metodo que clasifica individuos segun su imc
35
+ #
36
+ # @return [String] devuelve un string con la clasificación
37
+ def cat_peso
38
+ if(!t_obesidad)
39
+ return "Sin datos recogidos"
40
+ elsif(calcular_imc < 18.5)
41
+ return "Bajo peso"
42
+ elsif(calcular_imc < 24.9)
43
+ return "Saludable"
44
+ elsif(calcular_imc < 29.9)
45
+ return "Sobrepeso"
46
+ elsif(calcular_imc < 39.9)
47
+ return "Obesidad"
48
+ else
49
+ return "Obesidad Extrema"
50
+ end
51
+ end
52
+ # Convierte el objeto a una cadena de caracteres
53
+ #
54
+ # @return [String] devuelve el individuo como un string
55
+ def to_s
56
+ rval = "#{@nombre}"
57
+ if(t_obesidad)
58
+ rval += super
59
+ end
60
+ rval
61
+ end
62
+ # Metodo para comparar dos individuos
63
+ # @param [Individuo] otro individuo a comparar
64
+ #
65
+ # @return [-1,0,1] -1 si es menor, 0 si son iguales, 1 si es mayor
66
+ def <=>(other)
67
+ calcular_imc <=> other.calcular_imc
68
+ end
69
+
70
+ # Metodo para calcular peso ideal
71
+ #
72
+ # @return [Number] peso ideal del individuo
73
+ def peso_ideal
74
+ ((@altura * 100) - 150) * 0.75 + 50
75
+ end
76
+
77
+ # Metodo para calcular la tmb
78
+ #
79
+ # @return [Number] tmb del individuo
80
+ def tmb
81
+ 10*@peso + ((@altura * 100) * 6.25) - 5 * @edad + 5 + ((1-@sexo) * 166)
82
+ end
83
+
84
+ # Metodo para calcular el efecto termogeno
85
+ #
86
+ # @return [Number] efecto termogeno del individuo
87
+ def efecto_termogeno
88
+ tmb * 0.1
89
+ end
90
+
91
+ # Metodo para calcular el gasto de la actividad fisica
92
+ # @param [String] tipo de actividad fisica realizado
93
+ #
94
+ # @return [Number] el gasto de la actividad fisica del individuo
95
+ def gasto_actividad_fisica(cantidad)
96
+ if (cantidad == "reposo")
97
+ return 0
98
+ elsif (cantidad == "ligera")
99
+ return tmb * 0.12
100
+ elsif (cantidad == "moderada")
101
+ return tmb * 0.27
102
+ else
103
+ return tmb * 0.54
104
+ end
105
+ end
106
+
107
+ # Metodo para calcular el gasto total del individuo
108
+ # @param [String] tipo de actividad fisica realizado
109
+ #
110
+ # @return [Number] el gasto total del individuo del individuo
111
+ def gasto_energetico_total(cantidad)
112
+ tmb + efecto_termogeno + gasto_actividad_fisica(cantidad)
113
+ end
114
+
115
+ end
data/lib/lista.rb ADDED
@@ -0,0 +1,177 @@
1
+ require "nutrientesEugenio/version"
2
+ # Representación de un nodo en una lista
3
+ #
4
+ # @author Eugenio Jose Gonzalez Luis
5
+ # @since 1.0.0
6
+ # @attr_accessor any value Informacion contenida en el nodo
7
+ # @attr_accessor Node next Nodo siguiente con el que esta conectado
8
+ # @attr_accessor Node prev Nodo previo con el que esta conectado
9
+ class Array
10
+ def swap(a,b)
11
+ self[a], self[b] = self[b], self[a]
12
+ end
13
+ end
14
+
15
+ Node = Struct.new(:value, :next, :prev)
16
+
17
+ # Representación de una lista doblemente enlazada de nodos
18
+ #
19
+ # @author Eugenio Jose Gonzalez Luis
20
+ # @since 1.0.0
21
+ # @attr_reader Node head Nodo en la cabeza de la lista
22
+ # @attr_reader Node tail Nodo en la última posición de la lista
23
+ class Lista
24
+ include Enumerable
25
+ attr_reader :head, :tail
26
+
27
+ # Inserción por la cabeza de la lista
28
+ # @param [any] x valor del nuevo nodo
29
+ #
30
+ # @return [Node] Devuelve el head
31
+ def push_head(x)
32
+ if(@head == nil)
33
+ @head = Node.new(x, nil, nil)
34
+ @tail = @head
35
+ else
36
+ nuevo = Node.new(x, nil, nil)
37
+ nuevo.next= @head
38
+ @head.prev = nuevo
39
+ @head = nuevo
40
+ end
41
+ end
42
+
43
+ # Método para la enumeración de los nodos de la lista
44
+ #
45
+ # @return [Node] devuelve los nodos que conforman la lista
46
+ def each
47
+ x = @head
48
+ while(x != nil)
49
+ yield x.value
50
+ x = x.next
51
+ end
52
+ end
53
+
54
+ # Inserción por la cola de la lista
55
+ # @param [any] x valor del nuevo nodo
56
+ #
57
+ # @return [Node] Devuelve el tail
58
+ def push_tail(x)
59
+ if(@tail == nil)
60
+ @tail = Node.new(x, nil, nil)
61
+ @head = @tail
62
+ else
63
+ nuevo = Node.new(x, nil, nil)
64
+ nuevo.prev = @tail
65
+ @tail.next = nuevo
66
+ @tail = nuevo
67
+ end
68
+ end
69
+
70
+ # Inserción por la cola de la lista de varios nodos
71
+ # @param [Array<any>] x valores de los nuevos nodos
72
+ #
73
+ # @return [Node] Devuelve el tail
74
+ def push(x)
75
+ x.each{
76
+ |i| push_tail(i)
77
+ }
78
+ end
79
+ # Extracción del primer nodo de la lista
80
+ #
81
+ # @return [any, nil] devuelve el valor guardado en el primer nodo o nil si no hay nodos en la lista
82
+ def pop_head()
83
+ if(@head == nil)
84
+ return nil
85
+ end
86
+
87
+ x = @head
88
+ @head = @head.next
89
+ if(@head == nil)
90
+ @tail = nil
91
+ else
92
+ @head.prev = nil
93
+ x.next = nil
94
+ end
95
+ x.value
96
+ end
97
+
98
+ # Extracción del último nodo de la lista
99
+ #
100
+ # @return [any, nil] devuelve el valor guardado en el último nodo o nil si no hay nodos en la lista
101
+ def pop_tail()
102
+ if(@tail == nil)
103
+ return nil
104
+ end
105
+
106
+ x = @tail
107
+ @tail = @tail.prev
108
+ if(@tail == nil)
109
+ @head = nil
110
+ else
111
+ @tail.next = nil
112
+ x.prev = nil
113
+ end
114
+ x.value
115
+ end
116
+
117
+ # Ordena los alimentos en base a sus calorias
118
+ #
119
+ # @return [vector] devuelve un vector ordenado por calorias
120
+ def ordenar
121
+ rvector = []
122
+ j = 0
123
+ each do
124
+ |i| rvector[j] = i
125
+ j +=1
126
+ end
127
+ begin
128
+ intercambio = false
129
+ (rvector.count-1).times do |i|
130
+ if rvector[i].sal > rvector[i+1].sal # Si se cumple la condición, entonces intercambiamos.
131
+ rvector.swap(i,i+1)
132
+ intercambio = true
133
+ end # if
134
+ next
135
+ end # times
136
+ end while intercambio == true
137
+ rlist = Lista.new()
138
+ rlist.push(rvector)
139
+ rlist
140
+ end
141
+
142
+ # Ordena los alimentos en base a un bloque
143
+ #
144
+ # @return [vector] devuelve un vector ordenado por el bloque dado
145
+ def ordenar_por
146
+ rvector = []
147
+ j = 0
148
+ each do
149
+ |i| rvector[j] = i
150
+ j +=1
151
+ end
152
+ begin
153
+ intercambio = false
154
+ (rvector.count-1).times do |i|
155
+ x = yield rvector[i]
156
+ y = yield rvector[i+1]
157
+ if x > y # Si se cumple la condición, entonces intercambiamos.
158
+ rvector.swap(i,i+1)
159
+ intercambio = true
160
+ end # if
161
+ next
162
+ end # times
163
+ end while intercambio == true
164
+ rlist = Lista.new()
165
+ rlist.push(rvector)
166
+ rlist
167
+ end
168
+
169
+ # Convierte el objeto a una cadena de caracteres
170
+ #
171
+ # @return [String] devuelve la lista como un string
172
+ def to_s
173
+ s = ""
174
+ each {|i| s += "#{i.to_s}\n"}
175
+ s
176
+ end
177
+ end
data/lib/menu.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "nutrientesEugenio/version"
2
+
3
+
4
+ # Representación de un Menu dietetico
5
+ #
6
+ # @author Eugenio Jose Gonzalez Luis
7
+ # @since 1.0.0
8
+ class Menu < Lista
9
+ include Comparable
10
+ # metodo que calcula el coste calorico de un menu
11
+ #
12
+ # @return [Number] Coste calorico del menu
13
+ def kcal
14
+ x = collect{|a| a.kcal}
15
+ y = x.inject(0, :+)
16
+ y
17
+ end
18
+
19
+ # metodo que calcula si un menu es suficiente para un individuo dado
20
+ # @param [Individuo] persona persona para la cual se calcula si es suficiente
21
+ # @param [cantidad] cantidad de ejercicio que esa persona realiza
22
+ #
23
+ # @return [Boolean] devuelve si el menú es o no suficiente para una persona
24
+ def is_enough(persona, cantidad)
25
+ x = kcal
26
+ return (persona.gasto_energetico_total(cantidad) <= x * 1.1) && (persona.gasto_energetico_total(cantidad) >= x * 0.9)
27
+ end
28
+ # Metodo para comparar dos menus
29
+ # @param [Individuo] otro menu a comparar
30
+ #
31
+ # @return [-1,0,1] -1 si es menor, 0 si son iguales, 1 si es mayor
32
+ def <=>(other)
33
+ kcal <=> other.kcal
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require "imc"
2
+
3
+ module NutrientesEugenio
4
+ VERSION = "0.1.0"
5
+ end
6
+
7
+ class Lista
8
+ #Version de la clase Lista
9
+ VERSION = "0.1.0"
10
+ end
11
+
12
+ class Individuo < IMC
13
+ #Version de la clase Individuo
14
+ VERSION = "0.1.0"
15
+ end
@@ -0,0 +1,75 @@
1
+ require "nutrientesEugenio/version"
2
+
3
+
4
+ # Representación de un alimento según sus calorías aportadas y la cantidad de glucidos, proteinas y lipidos contenidos
5
+ #
6
+ # @author Eugenio José Gonzalez Luis
7
+ # @since 1.0.0
8
+ # @attr_reader String nombre Nombre del alimento
9
+ # @attr_reader Number grasas grasas contenidas en el alimento
10
+ # @attr_reader Number g_sat grasas saturadas contenidas en el alimento
11
+ # @attr_reader Number h_car hidratos de carbono contenidos en el alimento
12
+ # @attr_reader Number azucar azucat contenidas en el alimento
13
+ # @attr_reader Number proteina proteinas saturadas contenidas en el alimento
14
+ # @attr_reader Number sal sal contenidos en el alimento
15
+ class Alimento include Comparable
16
+ attr_reader :nombre, :grasas, :g_sat, :h_car, :azucar, :proteina, :sal
17
+
18
+ # Constructor de la clase alimento
19
+ # @param [String] nombre nombre del alimento
20
+ # @param [Number] grasas grasas contenidas en el alimento
21
+ # @param [Number] g_sat grasas saturadas contenidas en el alimento
22
+ # @param [Number] h_car hidratos de carbono contenidos en el alimento
23
+ # @param [Number] azucar azucat contenidas en el alimento
24
+ # @param [Number] proteina proteinas saturadas contenidas en el alimento
25
+ # @param [Number] sal sal contenidos en el alimento
26
+ #
27
+ # @return [Alimento] Devuelve el objeto creado de clase Alimento
28
+ def initialize(nombre, grasas, g_sat, h_car, azucar, proteina, sal)
29
+ @nombre = nombre
30
+ @grasas = grasas
31
+ @g_sat = g_sat
32
+ @h_car = h_car
33
+ @azucar = azucar
34
+ @proteina = proteina
35
+ @sal = sal
36
+ end
37
+ # Convierte el objeto a una cadena de caracteres
38
+ #
39
+ # @return [String] devuelve el alimento como un string
40
+ def to_s
41
+ "#{@nombre}:
42
+ #{@grasas} g grasa de los cuales saturados: #{@g_sat}
43
+ #{@h_car} g hidratos de carbono de los cuales azucares: #{@azucar}
44
+ #{@proteina} g proteinas
45
+ #{@sal} g sal"
46
+ end
47
+
48
+ # Calcula las calorias
49
+ #
50
+ # @return [Number] Valor calorico
51
+ def kcal
52
+ @proteina * 4 + @h_car * 4 + @grasas * 9
53
+ end
54
+
55
+ # Metodo para comparar dos alimentos
56
+ # @param [Alimento] otro alimento a comparar
57
+ #
58
+ # @return [-1,0,1] -1 si es menor, 0 si son iguales, 1 si es mayor
59
+ def <=>(other)
60
+ kcal <=> other.kcal
61
+ end
62
+
63
+ # Metodo que clasifica alimentos segun su cantidad de sal
64
+ #
65
+ # @return [String] devuelve un string con la clasificación
66
+ def cantidad_sal
67
+ if(sal < 0.6)
68
+ return "poca"
69
+ else
70
+ return "mucha"
71
+ end
72
+ end
73
+
74
+ end
75
+
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "nutrientesEugenio/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nutrientesEugenio"
8
+ spec.version = NutrientesEugenio::VERSION
9
+ spec.authors = ["Eugenio José"]
10
+ spec.email = ["alu0101000756@ull.edu.es"]
11
+
12
+ spec.summary = %q{"Clase para gestionar los glúcidos, lípidos y proteínas de un alimento específico"}
13
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1819/tdd-alu0101000756.git"
14
+ spec.license = "MIT"
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"] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.16"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+
36
+ spec.add_development_dependency "guard"
37
+ spec.add_development_dependency "guard-rspec"
38
+ spec.add_development_dependency "guard-bundler"
39
+
40
+ spec.add_development_dependency "coveralls"
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nutrientesEugenio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eugenio José
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-08 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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:
112
+ email:
113
+ - alu0101000756@ull.edu.es
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".travis.yml"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - Guardfile
123
+ - README.md
124
+ - Rakefile
125
+ - bin/console
126
+ - bin/setup
127
+ - lib/dietaDia.rb
128
+ - lib/imc.rb
129
+ - lib/individuo.rb
130
+ - lib/lista.rb
131
+ - lib/menu.rb
132
+ - lib/nutrientesEugenio.rb
133
+ - lib/nutrientesEugenio/version.rb
134
+ - nutrientesEugenio.gemspec
135
+ homepage: https://github.com/ULL-ESIT-LPP-1819/tdd-alu0101000756.git
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.5.1
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: '"Clase para gestionar los glúcidos, lípidos y proteínas de un alimento específico"'
160
+ test_files: []