nutriente 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6ec26835171b1edbc2be1fa397d5cb06b2cdb707fd3a84e16f66a498b7148acc
4
+ data.tar.gz: 11abbe3f650db929aaaab2b1d87da75a3e9ec7fc289e291816b9ef35a271d60b
5
+ SHA512:
6
+ metadata.gz: ec5daaa72326de6920133999a440ea73b7008ab487f903b242545862fb265bc3f2a51e7a5faa1adec9d99ed8707e396b0d134c616caf5e003ec44304268072c2
7
+ data.tar.gz: 39c57c7371b18a30a5ff1641d16fb679e5c3889bf579cc1ff8482280f64e4dd5908aa7b10b35723551239be5e08a8ef36d833d6cdc017552768ea27ce9cd6739
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/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.7.0
7
+ before_install: gem install bundler -v 2.1.0.pre.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nutriente.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,95 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nutriente (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ coderay (1.1.2)
10
+ coveralls (0.8.23)
11
+ json (>= 1.8, < 3)
12
+ simplecov (~> 0.16.1)
13
+ term-ansicolor (~> 1.3)
14
+ thor (>= 0.19.4, < 2.0)
15
+ tins (~> 1.6)
16
+ diff-lcs (1.3)
17
+ docile (1.3.2)
18
+ ffi (1.11.2)
19
+ formatador (0.2.5)
20
+ guard (2.16.1)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 2.7, < 4.0)
23
+ lumberjack (>= 1.0.12, < 2.0)
24
+ nenv (~> 0.1)
25
+ notiffany (~> 0.0)
26
+ pry (>= 0.9.12)
27
+ shellany (~> 0.0)
28
+ thor (>= 0.18.1)
29
+ guard-bundler (2.2.1)
30
+ bundler (>= 1.3.0, < 3)
31
+ guard (~> 2.2)
32
+ guard-compat (~> 1.1)
33
+ guard-compat (1.2.1)
34
+ guard-rspec (4.7.3)
35
+ guard (~> 2.1)
36
+ guard-compat (~> 1.1)
37
+ rspec (>= 2.99.0, < 4.0)
38
+ json (2.3.0)
39
+ listen (3.2.0)
40
+ rb-fsevent (~> 0.10, >= 0.10.3)
41
+ rb-inotify (~> 0.9, >= 0.9.10)
42
+ lumberjack (1.0.13)
43
+ method_source (0.9.2)
44
+ nenv (0.3.0)
45
+ notiffany (0.1.3)
46
+ nenv (~> 0.1)
47
+ shellany (~> 0.0)
48
+ pry (0.12.2)
49
+ coderay (~> 1.1.0)
50
+ method_source (~> 0.9.0)
51
+ rake (12.3.2)
52
+ rb-fsevent (0.10.3)
53
+ rb-inotify (0.10.0)
54
+ ffi (~> 1.0)
55
+ rspec (3.9.0)
56
+ rspec-core (~> 3.9.0)
57
+ rspec-expectations (~> 3.9.0)
58
+ rspec-mocks (~> 3.9.0)
59
+ rspec-core (3.9.0)
60
+ rspec-support (~> 3.9.0)
61
+ rspec-expectations (3.9.0)
62
+ diff-lcs (>= 1.2.0, < 2.0)
63
+ rspec-support (~> 3.9.0)
64
+ rspec-mocks (3.9.0)
65
+ diff-lcs (>= 1.2.0, < 2.0)
66
+ rspec-support (~> 3.9.0)
67
+ rspec-support (3.9.0)
68
+ shellany (0.0.1)
69
+ simplecov (0.16.1)
70
+ docile (~> 1.1)
71
+ json (>= 1.8, < 3)
72
+ simplecov-html (~> 0.10.0)
73
+ simplecov-html (0.10.2)
74
+ sync (0.5.0)
75
+ term-ansicolor (1.7.1)
76
+ tins (~> 1.0)
77
+ thor (0.20.3)
78
+ tins (1.24.0)
79
+ sync
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ bundler
86
+ coveralls
87
+ guard
88
+ guard-bundler
89
+ guard-rspec
90
+ nutriente!
91
+ rake
92
+ rspec
93
+
94
+ BUNDLED WITH
95
+ 2.1.4
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,35 @@
1
+ # Nutriente
2
+
3
+ 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/nutriente`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'nutriente'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install nutriente
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/nutriente.
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 "nutriente"
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/nutriente.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "nutriente/version"
2
+ require "nutriente/alimento"
3
+ require "nutriente/lista"
4
+ require "nutriente/platoE"
5
+ require "nutriente/platoA"
6
+ require "nutriente/platoDSL"
7
+ require "nutriente/menuDSL"
8
+
9
+ module Nutriente
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
@@ -0,0 +1,55 @@
1
+ # Clase Alimento
2
+ #
3
+ # Autor:: Sergio Moreno Martín
4
+ # @attr_reader nombre: devuelve el nombre del alimeto
5
+ # @attr_reader proteinas: devuelve la cantidad de proteinas
6
+ # @attr_reader carbohidratos: devuelve la cantidad de carbohidratos
7
+ # @attr_reader lipidos: devuelve la cantidad de lipidos
8
+ # @attr_reader gei: devuelve la cantidad de emisiones de gases de efecto invernadero
9
+ # @attr_reader terreno: devuelve la cantidad de terreno utilizado
10
+
11
+
12
+ class Alimento
13
+ attr_reader :nombre, :proteinas, :carbohidratos, :lipidos, :gei, :terreno
14
+ include Comparable
15
+
16
+ # Contruye un objeto alimento según los parámetros
17
+ def initialize(nombre, proteinas, carbohidratos, lipidos, gei, terreno)
18
+ @nombre = nombre
19
+ @proteinas = proteinas
20
+ @carbohidratos = carbohidratos
21
+ @lipidos = lipidos
22
+ @gei = gei
23
+ @terreno = terreno
24
+ end
25
+
26
+ # Obtiene la energía de las proteínas
27
+ def energiaProteinas()
28
+ @proteinas * 4
29
+ end
30
+
31
+ # Obtiene la energía de los lipidos
32
+ def energiaLipidos()
33
+ @lipidos * 9
34
+ end
35
+
36
+ # Obtiene la energía de los glúcidos
37
+ def energiaGlucidos()
38
+ @carbohidratos * 4
39
+ end
40
+
41
+ # Calcula el valor energético total
42
+ def valorEnergetico()
43
+ energiaProteinas() + energiaLipidos() + energiaGlucidos()
44
+ end
45
+
46
+ # Devuelve los valores del alimento formateados como un string
47
+ def to_s()
48
+ "#{@nombre}, #{@proteinas}g, #{@carbohidratos}g, #{@lipidos}g, #{@gei} kgCO2eq, #{@terreno} m2año"
49
+ end
50
+
51
+ # Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable
52
+ def <=>(other)
53
+ return self.valorEnergetico <=> other.valorEnergetico
54
+ end
55
+ end
@@ -0,0 +1,107 @@
1
+ # Nodo, contiene un valor, el nodo siguiente y el nodo previo
2
+ # @attr value: Valor del nodo
3
+ # @attr next: Nodo siguiente
4
+ # @attr prev: Nodo anterior
5
+ Node = Struct.new(:value, :next, :prev)
6
+
7
+ # Clase lista, lista doblemente enlazada
8
+ # @author Sergio Moreno Martín
9
+ # @attr_reader head: Devuelve el nodo cabeza de la lista
10
+ # @attr_reader tail: Devuelve el nodo cola de la lista
11
+
12
+ class Lista
13
+
14
+ attr_reader :head, :tail
15
+ include Enumerable
16
+
17
+ # Constructor, requiere la cabeza y la cola de la lista
18
+ def initialize(val)
19
+ @head = Node.new(val,nil,nil)
20
+ @tail = @head
21
+ end
22
+
23
+ # Comprueba si la lista está vacía
24
+ def is_empty
25
+ if(@head == nil) && (@tail == nil)
26
+ return true
27
+ else
28
+ return false
29
+ end
30
+ end
31
+
32
+ # Inserta un nodo por la cabeza de la lista
33
+ def insert_head(val)
34
+ aux = Node.new(val,@head,nil)
35
+ @head.prev = aux
36
+ @head = aux
37
+ end
38
+
39
+ # Inserta un nodo por la cola de la lista
40
+ def insert_tail(val)
41
+ aux = Node.new(val,nil,@tail)
42
+ @tail.next = aux
43
+ @tail = aux
44
+ end
45
+
46
+ # Extraer el nodo situado en la cabeza de la lista
47
+ def extract_head
48
+ aux = @head.value
49
+ @head = @head.next
50
+ @head.prev = nil
51
+ return aux
52
+ end
53
+
54
+ # Extrae el nodo situado en la cola de la lista
55
+ def extract_tail
56
+ aux = @tail.value
57
+ @tail = @tail.prev
58
+ @tail.next = nil
59
+ return aux
60
+ end
61
+
62
+ # Salida formateado como string de todos los elementos de la lista
63
+ def to_s
64
+ current = @head
65
+ string = "[ "
66
+ while current != nil
67
+ if(current.next == nil)
68
+ string += "#{current.value}"
69
+ else
70
+ string += "#{current.value}, "
71
+ end
72
+ current = current.next
73
+ end
74
+ return string += " ]"
75
+ end
76
+
77
+ # Cálculo de la emisión de gases de efecto invernadero diarios
78
+ def gei_diario
79
+ aux = 0
80
+ current = @head
81
+ while current != nil
82
+ aux += current.value.gei
83
+ current = current.next
84
+ end
85
+ return aux
86
+ end
87
+
88
+ # Cálculo del uso del terreno
89
+ def uso_terreno
90
+ aux = 0
91
+ current = @head
92
+ while current != nil
93
+ aux += current.value.terreno
94
+ current = current.next
95
+ end
96
+ return aux
97
+ end
98
+
99
+ # Metodo each, es un metodo que sirve para iterar por todos los elementos de la lista, es necesario para el funcionamiento de los mixins de Enumerable
100
+ def each
101
+ actual = @head
102
+ while actual != nil do
103
+ yield actual.value
104
+ actual = actual.next
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,31 @@
1
+ class MenuDSL
2
+
3
+ attr_accessor :nombre, :platos, :precio
4
+
5
+ def initialize(nombre, precio, &block)
6
+ @nombre = nombre
7
+ @precio = precio
8
+ @platos = []
9
+
10
+ if block_given?
11
+ if block.arity == 1
12
+ yield self
13
+ else
14
+ instance_eval(&block)
15
+ end
16
+ end
17
+ end
18
+
19
+ def to_s
20
+ output = @nombre
21
+ output << " #{@precio}€"
22
+ output << "\n#{'-' * @nombre.size}\n"
23
+ #output << "#{puts @platos}\n"
24
+ output
25
+ end
26
+
27
+
28
+ def plato(p, opcion = {})
29
+ @platos << p
30
+ end
31
+ end
@@ -0,0 +1,80 @@
1
+ # Clase PlatoA (Plato Ambiental)
2
+ # @author Sergio Moreno Martín
3
+ # @attr_reader nombre: nombre del plato
4
+ # @attr_reader listaAlimentos: lista de alimentos
5
+ # @attr_reader listaGramos: lista de gramos
6
+ # @attr_reader co2: Valor total de co2
7
+ # @attr_reader terreno: terreno total
8
+ class PlatoA < PlatoE
9
+
10
+ attr_reader :nombre, :listaAlimentos, :listaGramos, :co2, :terreno
11
+ include Comparable
12
+
13
+ # Constructo que se le pasa por parametros el nombre del plato, una lista de alimentos y una lista de gramos
14
+ def initialize(nombre, listaAlimentos, listaGramos)
15
+ super(nombre, listaAlimentos, listaGramos)
16
+ @co2 = valorTotalCO2
17
+ @terreno = terrenoTotal
18
+
19
+ end
20
+
21
+ # calcular el valor total de CO2
22
+ def valorTotalCO2
23
+ la = @listaAlimentos.head
24
+ lg = listaGramos.head
25
+ totalCO2 = 0.0
26
+ while la != nil do
27
+ totalCO2 = totalCO2 + la.value.gei * lg.value
28
+ la = la.next
29
+ lg = lg.next
30
+ end
31
+ return totalCO2
32
+ end
33
+
34
+ # calcular el uso del terreno total
35
+ def terrenoTotal
36
+ la = @listaAlimentos.head
37
+ lg = listaGramos.head
38
+ totalCO2 = 0.0
39
+ while la != nil do
40
+ totalTerreno = totalCO2 + la.value.terreno * lg.value
41
+ la = la.next
42
+ lg = lg.next
43
+ end
44
+ return totalTerreno
45
+ end
46
+
47
+ # Formatear la salida de un plato ambiental como un string
48
+ def to_s
49
+ "#{@nombre}, #{@listaAlimentos}, #{@listaGramos}, #{@vct}, #{@co2}, #{@terreno}"
50
+ end
51
+
52
+ # Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable
53
+ def <=>(other)
54
+ self.huella_nutricional <=> other.huella_nutricional
55
+ end
56
+
57
+ # calculo de la huella nutricional, comprando la energía (vct) y el carbono(co2), realizando después la media
58
+ def huella_nutricional
59
+ @energia
60
+ if self.vct< 670
61
+ @energia = 1
62
+ elsif self.vct >= 670 && self.vct < 830
63
+ @energia = 2
64
+ else
65
+ @energia = 3
66
+ end
67
+
68
+ @carbono
69
+ if self.co2 < 800
70
+ @carbono = 1
71
+ elsif self.co2 >= 800 && self.co2 < 1200
72
+ @carbono = 2
73
+ else
74
+ @carbono = 3
75
+ end
76
+
77
+ return (@energia + @carbono)/2
78
+ end
79
+
80
+ end
@@ -0,0 +1,35 @@
1
+ class PlatoDSL
2
+
3
+ attr_accessor :nombre, :ingredientes, :vn, :va
4
+
5
+ def initialize(nombre, vn, va, &block)
6
+
7
+ @nombre = nombre
8
+ @vn = vn
9
+ @va = va
10
+ @ingredientes = []
11
+
12
+ if block_given?
13
+ if block.arity == 1
14
+ yield self
15
+ else
16
+ instance_eval(&block)
17
+ end
18
+ end
19
+ end
20
+
21
+ def to_s
22
+ output = @nombre
23
+ output << " | Valor Nutricional: #{@vn} | Valor Ambiental: #{@va} | Ingredientes: #{@ingredientes.join(', ')}\n"
24
+ output
25
+ end
26
+
27
+
28
+ def ingrediente(nombre, opcion = {})
29
+ ingrediente = nombre
30
+ ingrediente << " (#{opcion[:gramos]})" if opcion[:gramos]
31
+ @vn = " (#{opcion[:vn]})" if opcion[:vn]
32
+ @va = " (#{opcion[:va]})" if opcion[:va]
33
+ @ingredientes << ingrediente
34
+ end
35
+ end
@@ -0,0 +1,86 @@
1
+ # Clase PlatoE (Plato Energía)
2
+ # @author Sergio Moreno Martín
3
+ # @attr_reader nombre: Devuelve el nombre del plato
4
+ # @attr_reader listaAlimentos: Devuelve una lista de alimentos
5
+ # @attr_reader listaGramos: Devuelve una lista de gramos
6
+ # @attr_reader vct: Devuelve el valor calórico total
7
+
8
+ class PlatoE
9
+
10
+ attr_reader :nombre, :listaAlimentos, :listaGramos, :vct
11
+ include Comparable
12
+
13
+ # Constructor que se le pasa por parámetro el nombre del alimento, una lista de alimentos y una lista de gramos
14
+ def initialize(nombre, listaAlimentos, listaGramos)
15
+ @nombre = nombre
16
+ @listaAlimentos = listaAlimentos
17
+ @listaGramos = listaGramos
18
+ @vct = valorCaloricoTotal
19
+ end
20
+
21
+ # cacular el porcentaje de proteinas según la cantidad de gramos
22
+ def porcentajeProteinas
23
+ total_proteinas = 0.0
24
+ la = @listaAlimentos.head
25
+ lg = @listaGramos.head
26
+
27
+ while la != nil do
28
+ total_proteinas += (la.value.proteinas * lg.value) / 100
29
+ la = la.next
30
+ lg = lg.next
31
+ end
32
+ total_gramos = listaGramos.reduce(:+)
33
+ porcentajeProteinas = ((total_proteinas / total_gramos) * 100).round(2)
34
+ end
35
+
36
+ # Calcular el procentaje de lipidos según la cantidad de gramos
37
+ def porcentajeLipidos
38
+ total_lipidos = 0.0
39
+ la = @listaAlimentos.head
40
+ lg = @listaGramos.head
41
+ while la != nil do
42
+ total_lipidos += (la.value.lipidos * lg.value) / 100
43
+ la = la.next
44
+ lg = lg.next
45
+ end
46
+ total_gramos = listaGramos.reduce(:+)
47
+ porcentajeLipidos = ((total_lipidos / total_gramos) * 100).round(2)
48
+ end
49
+
50
+ # Calcular el porcentaje de glucidos segun la cantidad de gramos
51
+ def porcentajeGlucidos
52
+ total_glucidos = 0.0
53
+ la = @listaAlimentos.head
54
+ lg = @listaGramos.head
55
+ while la != nil do
56
+ total_glucidos += (la.value.carbohidratos * lg.value) / 100
57
+ la = la.next
58
+ lg = lg.next
59
+ end
60
+ total_gramos = listaGramos.reduce(:+)
61
+ porcentajeGlucidos = ((total_glucidos / total_gramos)*100).round(2)
62
+ end
63
+
64
+ # calcular el valor clórico total del plato y todos sus alimentos
65
+ def valorCaloricoTotal
66
+ la = @listaAlimentos.head
67
+ lg = @listaGramos.head
68
+ while la != nil do
69
+ resultado = (la.value.valorEnergetico * lg.value) / 100
70
+ la = la.next
71
+ lg = lg.next
72
+ end
73
+ return resultado
74
+ end
75
+
76
+ # Formatear la salidad de un plato tipo energía
77
+ def to_s
78
+ "#{@nombre}, #{@listaAlimentos}, #{@listaGramos}, #{@vct}"
79
+ end
80
+
81
+ # Metodo de comparación, devuelve -1 si es menor que other, +1 si es mayor y 0 si es igual, se utiliza para los mixins de comparable
82
+ def <=>(other)
83
+ self.vct <=> other.vct
84
+ end
85
+
86
+ end
@@ -0,0 +1,3 @@
1
+ module Nutriente
2
+ VERSION = "0.1.0"
3
+ end
data/nutriente.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "nutriente/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nutriente"
7
+ spec.version = Nutriente::VERSION
8
+ spec.authors = ["Sergio Moreno Martin"]
9
+ spec.email = ["alu0100710298@ull.edu.es"]
10
+
11
+ spec.summary = %q{Nutrientes de alimentos}
12
+ spec.description = %q{Gema nutriente}
13
+ spec.homepage = "https://github.com/alu0100710298/practica10.git"
14
+
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ spec.add_development_dependency "guard"
28
+ spec.add_development_dependency "guard-rspec"
29
+ spec.add_development_dependency "guard-bundler"
30
+ spec.add_development_dependency "coveralls"
31
+
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nutriente
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Moreno Martin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-01-10 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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: Gema nutriente
112
+ email:
113
+ - alu0100710298@ull.edu.es
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - Guardfile
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - lib/nutriente.rb
129
+ - lib/nutriente/alimento.rb
130
+ - lib/nutriente/lista.rb
131
+ - lib/nutriente/menuDSL.rb
132
+ - lib/nutriente/platoA.rb
133
+ - lib/nutriente/platoDSL.rb
134
+ - lib/nutriente/platoE.rb
135
+ - lib/nutriente/version.rb
136
+ - nutriente.gemspec
137
+ homepage: https://github.com/alu0100710298/practica10.git
138
+ licenses: []
139
+ metadata: {}
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
+ rubygems_version: 3.1.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Nutrientes de alimentos
159
+ test_files: []