alimentos-alu0101103181 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 24312aae5e561f0e69d5237d3d00114fb276dcc512ce48784c387446da25207b
4
+ data.tar.gz: 82de1f0301f00a5d46034e8cbba56be2356a7e33f456697e8e78c66df943fca0
5
+ SHA512:
6
+ metadata.gz: 7c6835af8b698e9f3d7dbe9e62ae2cd54d35d3dabe508d7111bc2e65d93053c982c0ecb723fe097ca476f5309985d3e76d8c04720c0717336126a79e45e62e3d
7
+ data.tar.gz: 842d6403396d401a8b0b02d5c7c53c3893636f532a14e58af13d0866263d55709238a511499f783df0064c27f71bd013abd466487771b8507c317ecb8af9b00e
@@ -0,0 +1,2 @@
1
+ service_name: travis-ci
2
+ repo_token: ...
@@ -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
File without changes
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alu0101103181@ull.edu.es. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in alimentos.gemspec
4
+ gem "rspec"
5
+ gem "guard"
6
+ gem "rake"
7
+
8
+ gem "coveralls", require: false
@@ -0,0 +1,75 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ coderay (1.1.2)
5
+ coveralls (0.8.23)
6
+ json (>= 1.8, < 3)
7
+ simplecov (~> 0.16.1)
8
+ term-ansicolor (~> 1.3)
9
+ thor (>= 0.19.4, < 2.0)
10
+ tins (~> 1.6)
11
+ diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ ffi (1.11.2)
14
+ formatador (0.2.5)
15
+ guard (2.16.1)
16
+ formatador (>= 0.2.4)
17
+ listen (>= 2.7, < 4.0)
18
+ lumberjack (>= 1.0.12, < 2.0)
19
+ nenv (~> 0.1)
20
+ notiffany (~> 0.0)
21
+ pry (>= 0.9.12)
22
+ shellany (~> 0.0)
23
+ thor (>= 0.18.1)
24
+ json (2.3.0)
25
+ listen (3.2.0)
26
+ rb-fsevent (~> 0.10, >= 0.10.3)
27
+ rb-inotify (~> 0.9, >= 0.9.10)
28
+ lumberjack (1.0.13)
29
+ method_source (0.9.2)
30
+ nenv (0.3.0)
31
+ notiffany (0.1.3)
32
+ nenv (~> 0.1)
33
+ shellany (~> 0.0)
34
+ pry (0.12.2)
35
+ coderay (~> 1.1.0)
36
+ method_source (~> 0.9.0)
37
+ rake (13.0.1)
38
+ rb-fsevent (0.10.3)
39
+ rb-inotify (0.10.0)
40
+ ffi (~> 1.0)
41
+ rspec (3.9.0)
42
+ rspec-core (~> 3.9.0)
43
+ rspec-expectations (~> 3.9.0)
44
+ rspec-mocks (~> 3.9.0)
45
+ rspec-core (3.9.0)
46
+ rspec-support (~> 3.9.0)
47
+ rspec-expectations (3.9.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.9.0)
50
+ rspec-mocks (3.9.0)
51
+ diff-lcs (>= 1.2.0, < 2.0)
52
+ rspec-support (~> 3.9.0)
53
+ rspec-support (3.9.0)
54
+ shellany (0.0.1)
55
+ simplecov (0.16.1)
56
+ docile (~> 1.1)
57
+ json (>= 1.8, < 3)
58
+ simplecov-html (~> 0.10.0)
59
+ simplecov-html (0.10.2)
60
+ term-ansicolor (1.7.1)
61
+ tins (~> 1.0)
62
+ thor (0.20.3)
63
+ tins (1.22.2)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ coveralls
70
+ guard
71
+ rake
72
+ rspec
73
+
74
+ BUNDLED WITH
75
+ 2.0.2
@@ -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
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
71
+
72
+ guard :bundler do
73
+ require 'guard/bundler'
74
+ require 'guard/bundler/verify'
75
+ helper = Guard::Bundler::Verify.new
76
+
77
+ files = ['Gemfile']
78
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
79
+
80
+ # Assume files are symlinked from somewhere
81
+ files.each { |file| watch(helper.real_path(file)) }
82
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Pablo Molina Martinez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Alimentos
2
+
3
+ Pablo Molina Martinez 2019-2020.
4
+ Practia 6: Desarrollo Dirigido por Pruebas.
5
+ Estructura creada con Bundle y testeada con rspec.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'alimentos'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install alimentos
22
+
23
+ ## Usage
24
+
25
+ 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]/alimentos. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Alimentos project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/alimentos/blob/master/CODE_OF_CONDUCT.md).
@@ -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
@@ -0,0 +1,38 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "alimentos/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "alimentos-alu0101103181"
7
+ spec.version = Alimentos::VERSION
8
+ spec.authors = ["Pablo Molina Martinez"]
9
+ spec.email = ["alu0101103181@ull.edu.es"]
10
+
11
+ spec.summary = %q{Write a short summary, because RubyGems requires one.}
12
+ spec.description = %q{Write a longer description or delete this line.}
13
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+
18
+ spec.metadata["homepage_uri"] = "https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar"
19
+ spec.metadata["source_code_uri"] = "https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar"
20
+ spec.metadata["changelog_uri"] = "https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_development_dependency "bundler", "~> 2.0"
32
+ spec.add_development_dependency "rake", "~> 10.0"
33
+ spec.add_development_dependency "rspec", "~> 3.0"
34
+ spec.add_development_dependency "guard"
35
+ spec.add_development_dependency "guard-rspec"
36
+ spec.add_development_dependency "guard-bundler"
37
+ spec.add_development_dependency "coveralls"
38
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "alimentos"
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__)
@@ -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
@@ -0,0 +1,468 @@
1
+ require "alimentos/version"
2
+
3
+ #
4
+ # Modulo que contiene todo los relacionado con el TDD
5
+ #
6
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
7
+ #
8
+ module Alimentos
9
+ #
10
+ # Encargada de la representacion de un alimento
11
+ #
12
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
13
+ #
14
+ class Alimento
15
+ include Comparable, Enumerable
16
+
17
+ attr_accessor :name, :gei, :terrain, :pro, :car, :lip
18
+
19
+ #
20
+ # Da valores a las variables de instacia de la clase
21
+ #
22
+ # @param [String] name Nombre del alimento
23
+ # @param [Float] gei Efectos de gas invernadero del alimento
24
+ # @param [Float] terrain M^2 de terreno
25
+ # @param [Float] pro Proteinas por cada 100 gr
26
+ # @param [Float] car Carbohidratos por cada 100 gr
27
+ # @param [Float] lip Lipidos por cada 100 gr
28
+ #
29
+ def initialize(name, gei, terrain, pro, car, lip)
30
+ @name = name
31
+ @gei = gei
32
+ @terrain = terrain
33
+ @pro = pro
34
+ @car = car
35
+ @lip = lip
36
+ end
37
+
38
+ #
39
+ # Formato del alimento a string
40
+ #
41
+ # @return [String] String con el formato para la representacion de un alimento
42
+ #
43
+ def to_s
44
+ "#{@name}, #{@gei}, #{terrain}"
45
+ end
46
+
47
+ #
48
+ # Calcula las calorias de un alimento
49
+ #
50
+ # @return [Float] (Proteinas + Carbohidratos) * 4 + Lipidos * 9
51
+ #
52
+ def energi
53
+ (@pro * 4 + @car * 4 + @lip * 9).round(2)
54
+ end
55
+
56
+ #
57
+ # Calcula el impacto ambiental de un alimento
58
+ #
59
+ # @return [Float] Gases de efecto inverdero + Terreno
60
+ #
61
+ def ambient
62
+ (@gei + @terrain).round(2)
63
+ end
64
+
65
+ #
66
+ # Calcula el impacto sobre la dieta diaria nesesaria para un hombre de X gramos del alimento
67
+ #
68
+ # @param [Float] x Cantidad de gramos del alimento a calcular
69
+ #
70
+ # @return [[Float,Float]] Las calorias y las proteinas diarias
71
+ #
72
+ def impactMen(x)
73
+ [((energi / 3000) * x / 100).round(2), ((@pro / 54) * x / 100).round(2)]
74
+ end
75
+
76
+ #
77
+ # Calcula el impacto sobre la dieta diaria nesesaria para una mujer de X gramos del alimento
78
+ #
79
+ # @param [Float] x Cantidad de gramos del alimento a calcular
80
+ #
81
+ # @return [[Float,Float]] Las calorias y las proteinas diarias
82
+ #
83
+ def impactWom(x)
84
+ [((energi / 2300) * x / 100).round(2), ((@pro / 41) * x / 100).round(2)]
85
+ end
86
+ end
87
+
88
+ #
89
+ # Encargada de la representacion de una lista doblemente elazada
90
+ #
91
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
92
+ #
93
+ class Lista
94
+ include Comparable, Enumerable
95
+
96
+ attr_reader :lista, :cabeza, :cola, :tam
97
+
98
+ #
99
+ # Crea un lista vacia, con una cabeza nula y una cola nula, ademas de un tamaño 0
100
+ #
101
+ def initialize
102
+ @lista = []
103
+ @cabeza = nil
104
+ @cola = nil
105
+ @tam = 0
106
+ end
107
+
108
+ #
109
+ # Inserta un nodo por la cola de la lista, cambiando la cola del ultimo nodo y poniendo la del suyo propio a 0
110
+ #
111
+ # @param [Node] nodo Nodo que se va a insertar a la lista
112
+ #
113
+ # @return [Int] Devuelve el tamaño nuevo de la lista
114
+ #
115
+ def insert(nodo)
116
+ node = Struct.new(:value, :next, :prev)
117
+ if @cabeza == nil
118
+ @lista[@tam] = node.new(nodo, nil, nil)
119
+ @cabeza = @lista[0]
120
+ @cola = @lista[0]
121
+ else
122
+ @lista[@tam] = node.new(nodo, nil, @lista[@tam - 1])
123
+ @lista[@tam - 1].next = @lista[@tam]
124
+ @cola = @lista[@tam]
125
+ end
126
+ @tam += 1
127
+ end
128
+
129
+ #
130
+ # Extrae la cabeza de la lista modificado el 2 miembro.
131
+ #
132
+ # @return [Int] Devuelve el tamaño nuevo de la lista
133
+ #
134
+ def extract_head
135
+ @tam -= 1
136
+ aux = @cabeza
137
+ @lista.slice!(0)
138
+ if @tam != 0
139
+ @lista[0].prev = nil
140
+ @cabeza = @lista[0]
141
+ @cola = @lista[@tam - 1]
142
+ end
143
+ aux
144
+ end
145
+
146
+ #
147
+ # Extrae la cola de la lista modificado el antepenultimo miembro.
148
+ #
149
+ # @return [Int] Devuelve el tamaño nuevo de la lista
150
+ #
151
+ def extract_tail
152
+ aux = @cola
153
+ @lista.slice!(@tam - 1)
154
+ @tam -= 1
155
+ if @tam != 0
156
+ @lista[@tam - 1].next = nil
157
+ @cola = @lista[@tam - 1]
158
+ end
159
+ aux
160
+ end
161
+ end
162
+
163
+ #
164
+ # Encargada de la representacion de un plato con diferentes cantidades de alimentos
165
+ #
166
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
167
+ #
168
+ class Plato
169
+ include Comparable
170
+ attr_reader :name, :receip, :grams
171
+
172
+ #
173
+ # Da valor a las variables de instacia de la clase
174
+ #
175
+ # @param [String] name Nombre del plato
176
+ # @param [Array[Alimento]] receip Lista de alimentos del plato
177
+ # @param [Array[Int]] grams Lista de gramos de los alimentos
178
+ #
179
+ def initialize(name, receip, grams)
180
+ @name = name
181
+ @receip = receip
182
+ @grams = grams
183
+ end
184
+
185
+ #
186
+ # Comparable para Plato, centrado en las calorias
187
+ #
188
+ # @param [Plato] param Plato a comparar
189
+ #
190
+ # @return [Bool] Devuelve el booleano de realizar la comprobacion de Comparable
191
+ #
192
+ def <=>(param)
193
+ calories <=> param.calories
194
+ end
195
+
196
+ #
197
+ # Calcula el porcentaje de proteinas de un plato
198
+ #
199
+ # @return [Float] Porcentaje de proteinas
200
+ #
201
+ def proPercent
202
+ aux = 0
203
+ for i in 0..@receip.tam - 1
204
+ aux += @receip.lista[i].value.pro
205
+ end
206
+
207
+ x = []
208
+ for i in 0..@receip.tam - 1
209
+ x[i] = (@receip.lista[i].value.pro / aux).round(2)
210
+ end
211
+ x
212
+ end
213
+
214
+ #
215
+ # Calcula el porcentaje de lipidos de un plato
216
+ #
217
+ # @return [Float] Porcentaje de lipidos
218
+ #
219
+ def lipPercent
220
+ aux = 0
221
+ for i in 0..@receip.tam - 1
222
+ aux += @receip.lista[i].value.lip
223
+ end
224
+
225
+ x = []
226
+ for i in 0..@receip.tam - 1
227
+ x[i] = (@receip.lista[i].value.lip / aux).round(2)
228
+ end
229
+ x
230
+ end
231
+
232
+ #
233
+ # Calcula el porcentaje de carbohidratos de un plato
234
+ #
235
+ # @return [Float] Porcentaje de carbohidratos
236
+ #
237
+ def carPercent
238
+ aux = 0
239
+ for i in 0..@receip.tam - 1
240
+ aux += @receip.lista[i].value.car
241
+ end
242
+
243
+ x = []
244
+ for i in 0..@receip.tam - 1
245
+ x[i] = (@receip.lista[i].value.car / aux).round(2)
246
+ end
247
+ x
248
+ end
249
+
250
+ #
251
+ # Calcula las calorias de un plato en comparacion a los gramos
252
+ #
253
+ # @return [Float] Calorias del plato con respecto a sus gramos
254
+ #
255
+ def calories
256
+ aux = []
257
+ for i in 0..@grams.length() - 1
258
+ aux[i] = @grams[i] / 100
259
+ end
260
+
261
+ cal = 0
262
+ for i in 0..@grams.length() - 1
263
+ cal += @receip.lista[i].value.energi * aux[i]
264
+ end
265
+
266
+ (cal).round(2)
267
+ end
268
+
269
+ #
270
+ # Formato de un plato a string
271
+ #
272
+ # @return [String] String con el formato para la representacion de un plato
273
+ #
274
+ def to_s
275
+ aux = ""
276
+ for i in 0..@receip.tam - 1
277
+ aux += "#{@receip.lista[i].value.name} "
278
+ end
279
+ aux
280
+ end
281
+ end
282
+
283
+ #
284
+ # Encargada de la representacion de un plato centrada en su impacto ambiental
285
+ #
286
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
287
+ #
288
+ class PlatoA < Plato
289
+ include Comparable
290
+
291
+ #
292
+ # Llama al constructor de Plato (su padre)
293
+ #
294
+ # @param [String] name Nombre del plato
295
+ # @param [Array[Alimento]] receip Lista de alimentos del plato
296
+ # @param [Array[Int]] grams Lista de gramos de los alimentos
297
+ #
298
+ def initialize(name, receip, grams)
299
+ super(name, receip, grams)
300
+ end
301
+
302
+ #
303
+ # Comparable para PlatoA, centrado en la huella nutricional
304
+ #
305
+ # @param [Plato] param PlatoA a comparar
306
+ #
307
+ # @return [Bool] Devuelve el booleano de realizar la comprobacion de Comparable
308
+ #
309
+ def <=>(param)
310
+ huella_nut <=> param.huella_nut
311
+ end
312
+
313
+ #
314
+ # Calcula la huella nutricional de un plato y halla su baremo
315
+ #
316
+ # @return [Float] Media entre la huella calorica y ambiental baremadas
317
+ #
318
+ def huella_nut
319
+ cal = calories
320
+ gas = plato_ambiente
321
+
322
+ if cal < 670
323
+ cal = 1
324
+ elsif cal < 830
325
+ cal = 2
326
+ else
327
+ cal = 3
328
+ end
329
+
330
+ if gas < 800
331
+ gas = 1
332
+ elsif gas < 1200
333
+ gas = 2
334
+ else
335
+ gas = 3
336
+ end
337
+
338
+ (cal + gas) / 2.round(2)
339
+ end
340
+
341
+ #
342
+ # Calcula los gases de efecto invernaderos de un plato
343
+ #
344
+ # @return [Float] Gases de efecto invernadero
345
+ #
346
+ def plato_gei
347
+ aux = 0
348
+ for i in 0..@receip.tam - 1
349
+ aux += @receip.lista[i].value.gei
350
+ end
351
+ aux.round(2)
352
+ end
353
+
354
+ #
355
+ # Cacula el uso del terreno en m^2 de un plato
356
+ #
357
+ # @return [Float] Uso del terreno en M^2
358
+ #
359
+ def plato_terreno
360
+ aux = []
361
+ for i in 0..@grams.length() - 1
362
+ aux[i] = @grams[i] / 100
363
+ end
364
+ x = 0
365
+ for i in 0..@receip.tam - 1
366
+ x += @receip.lista[i].value.terrain * aux[i]
367
+ end
368
+ x.round(2)
369
+ end
370
+
371
+ #
372
+ # Calcula el impacto ambiental de un plato
373
+ #
374
+ # @return [Float] Impacto ambiental del plato
375
+ #
376
+ def plato_ambiente
377
+ aux = []
378
+ for i in 0..@grams.length() - 1
379
+ aux[i] = @grams[i] / 100
380
+ end
381
+ x = 0
382
+ for i in 0..@receip.tam - 1
383
+ x += @receip.lista[i].value.gei * aux[i]
384
+ end
385
+ x.round(2)
386
+ end
387
+
388
+ #
389
+ # Formato del plato a string
390
+ #
391
+ # @return [String] String con el formato para la representacion de un PlatoA
392
+ #
393
+ def to_s
394
+ "#{plato_gei}, #{plato_terreno}"
395
+ end
396
+ end
397
+
398
+ class PlatoB
399
+ def initialize(nombre, &bloque)
400
+ @nombre = nombre
401
+ @alimentos = []
402
+
403
+ if block_given?
404
+ if bloque.arity == 1
405
+ yield self
406
+ else
407
+ instance_eval(&bloque)
408
+ end
409
+ end
410
+ end
411
+
412
+ def alimento(alimento)
413
+ @alimentos << [alimento[:descripcion], alimento[:gramos]]
414
+ end
415
+
416
+ def nombre(nombre)
417
+ @descripcion = nombre
418
+ end
419
+
420
+ def to_s
421
+ plato = ""
422
+ plato << @nombre + ", " + @descripcion + " compuesta de: \n"
423
+ @alimentos.each do |alimento|
424
+ plato << alimento[0] + " => " + alimento[1].to_s + ".gr\n"
425
+ end
426
+ plato
427
+ end
428
+ end
429
+
430
+ class MenuA
431
+ def initialize(nombre, &bloque)
432
+ @nombre = nombre
433
+ @platos = []
434
+ @precio = 0
435
+ @descripcion = ""
436
+
437
+ if block_given?
438
+ if bloque.arity == 1
439
+ yield self
440
+ else
441
+ instance_eval(&bloque)
442
+ end
443
+ end
444
+ end
445
+
446
+ def componente (componentes)
447
+ @platos << [componentes[:descripcion], componentes[:precio]]
448
+ end
449
+
450
+ def descripcion(descripcion)
451
+ @descripcion = descripcion
452
+ end
453
+
454
+ def precio(precio)
455
+ @precio = precio
456
+ end
457
+
458
+ def to_s
459
+ menu = ""
460
+ menu << @nombre + ", " + @descripcion + " con valor " + @precio.to_s + "\n"
461
+ @platos.each do |plato|
462
+ menu << plato[0].to_s + "Con valor:" + plato[1].to_s + "\n"
463
+ end
464
+ menu
465
+ end
466
+
467
+ end
468
+ end
@@ -0,0 +1,9 @@
1
+ #
2
+ # Version del proyecto
3
+ #
4
+ # @author Pablo Molina Martinez alu0101103181@ull.edu.es
5
+ #
6
+ module Alimentos
7
+ # @return [String] Version del proyecto
8
+ VERSION = "1.0"
9
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alimentos-alu0101103181
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Pablo Molina Martinez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.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: '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: Write a longer description or delete this line.
112
+ email:
113
+ - alu0101103181@ull.edu.es
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".coveralls.yml"
119
+ - ".gitignore"
120
+ - ".rake_tasks~"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - CODE_OF_CONDUCT.md
124
+ - Gemfile
125
+ - Gemfile.lock
126
+ - Guardfile
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - alimentos.gemspec
131
+ - bin/console
132
+ - bin/setup
133
+ - lib/alimentos.rb
134
+ - lib/alimentos/version.rb
135
+ homepage: https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar
136
+ licenses:
137
+ - MIT
138
+ metadata:
139
+ allowed_push_host: https://rubygems.org/
140
+ homepage_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar
141
+ source_code_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar
142
+ changelog_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-Pmolmar
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.7.6
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Write a short summary, because RubyGems requires one.
163
+ test_files: []