lppP6lu0101027005 1.0.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
+ SHA256:
3
+ metadata.gz: 6ece0e14f47c7a860776f0de364446a0c8ef7f0b4daaf04c8550f13810ea98f8
4
+ data.tar.gz: 851bc423982c0c3af5d63befa7a5928e3356cdd15f6505971976f718c5714870
5
+ SHA512:
6
+ metadata.gz: 6ebe1b9cf5164c87b18e9a64dbf6c43d52f2c324d006a04df29834f02cbfcfe8e6e1af9a3d766a834b51d60375ffb5ca92b7eeb9c31549e255158b98e74518db
7
+ data.tar.gz: c41331b178b3492cf7e5368cb3676a84c225eb9272293b97647a1dafcc4c2d819f9ba640a50e59e41cb3e4002cca7eb4a68278a1202fb4bd237f3fd81865a3da
data/.coverralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
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
12
+
13
+ .vscode
14
+ *.*~
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.6.3
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 alu0101027005@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,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lppP6.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,135 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lppP6lu0101027005 (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.4.0)
10
+ backports (3.15.0)
11
+ coderay (1.1.2)
12
+ coveralls (0.8.23)
13
+ json (>= 1.8, < 3)
14
+ simplecov (~> 0.16.1)
15
+ term-ansicolor (~> 1.3)
16
+ thor (>= 0.19.4, < 2.0)
17
+ tins (~> 1.6)
18
+ diff-lcs (1.3)
19
+ docile (1.3.2)
20
+ ethon (0.12.0)
21
+ ffi (>= 1.3.0)
22
+ faraday (0.17.3)
23
+ multipart-post (>= 1.2, < 3)
24
+ faraday_middleware (0.13.1)
25
+ faraday (>= 0.7.4, < 1.0)
26
+ ffi (1.11.2)
27
+ formatador (0.2.5)
28
+ gh (0.15.1)
29
+ addressable (~> 2.4.0)
30
+ backports
31
+ faraday (~> 0.8)
32
+ multi_json (~> 1.0)
33
+ net-http-persistent (~> 2.9)
34
+ net-http-pipeline
35
+ guard (2.16.1)
36
+ formatador (>= 0.2.4)
37
+ listen (>= 2.7, < 4.0)
38
+ lumberjack (>= 1.0.12, < 2.0)
39
+ nenv (~> 0.1)
40
+ notiffany (~> 0.0)
41
+ pry (>= 0.9.12)
42
+ shellany (~> 0.0)
43
+ thor (>= 0.18.1)
44
+ guard-bundler (2.2.1)
45
+ bundler (>= 1.3.0, < 3)
46
+ guard (~> 2.2)
47
+ guard-compat (~> 1.1)
48
+ guard-compat (1.2.1)
49
+ guard-rspec (4.7.3)
50
+ guard (~> 2.1)
51
+ guard-compat (~> 1.1)
52
+ rspec (>= 2.99.0, < 4.0)
53
+ highline (1.7.10)
54
+ json (2.3.0)
55
+ launchy (2.4.3)
56
+ addressable (~> 2.3)
57
+ listen (3.2.0)
58
+ rb-fsevent (~> 0.10, >= 0.10.3)
59
+ rb-inotify (~> 0.9, >= 0.9.10)
60
+ lumberjack (1.0.13)
61
+ method_source (0.9.2)
62
+ multi_json (1.14.1)
63
+ multipart-post (2.1.1)
64
+ nenv (0.3.0)
65
+ net-http-persistent (2.9.4)
66
+ net-http-pipeline (1.0.1)
67
+ notiffany (0.1.3)
68
+ nenv (~> 0.1)
69
+ shellany (~> 0.0)
70
+ pry (0.12.2)
71
+ coderay (~> 1.1.0)
72
+ method_source (~> 0.9.0)
73
+ pusher-client (0.6.2)
74
+ json
75
+ websocket (~> 1.0)
76
+ rake (10.5.0)
77
+ rb-fsevent (0.10.3)
78
+ rb-inotify (0.10.0)
79
+ ffi (~> 1.0)
80
+ rspec (3.9.0)
81
+ rspec-core (~> 3.9.0)
82
+ rspec-expectations (~> 3.9.0)
83
+ rspec-mocks (~> 3.9.0)
84
+ rspec-core (3.9.0)
85
+ rspec-support (~> 3.9.0)
86
+ rspec-expectations (3.9.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.9.0)
89
+ rspec-mocks (3.9.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.9.0)
92
+ rspec-support (3.9.0)
93
+ shellany (0.0.1)
94
+ simplecov (0.16.1)
95
+ docile (~> 1.1)
96
+ json (>= 1.8, < 3)
97
+ simplecov-html (~> 0.10.0)
98
+ simplecov-html (0.10.2)
99
+ sync (0.5.0)
100
+ term-ansicolor (1.7.1)
101
+ tins (~> 1.0)
102
+ thor (0.20.3)
103
+ tins (1.24.0)
104
+ sync
105
+ travis (1.8.10)
106
+ backports
107
+ faraday (~> 0.9)
108
+ faraday_middleware (~> 0.9, >= 0.9.1)
109
+ gh (~> 0.13)
110
+ highline (~> 1.6)
111
+ launchy (~> 2.1)
112
+ pusher-client (~> 0.4)
113
+ typhoeus (~> 0.6, >= 0.6.8)
114
+ typhoeus (0.8.0)
115
+ ethon (>= 0.8.0)
116
+ websocket (1.2.8)
117
+ yard (0.9.20)
118
+
119
+ PLATFORMS
120
+ ruby
121
+
122
+ DEPENDENCIES
123
+ bundler (~> 2.0)
124
+ coveralls
125
+ guard
126
+ guard-bundler
127
+ guard-rspec
128
+ lppP6lu0101027005!
129
+ rake (~> 10.0)
130
+ rspec (~> 3.0)
131
+ travis
132
+ yard
133
+
134
+ BUNDLED WITH
135
+ 2.0.2
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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Eric Dürr Sierra
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.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # PRÁCTICA NUMERO 6 DE LENGUAJES Y PARADIGMAS DE LA PROGRAMACIÓN | TDD
2
+ ## *(lppP6)*
3
+ ******
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lppP6'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lppP6
20
+
21
+ ## Usage
22
+
23
+ > WIP
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lppP6. 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+
39
+ ## Code of Conduct
40
+
41
+ Everyone interacting in the LppP6 project’s codebases, issue trackers, chat rooms and mailing lists
42
+ is expected to follow the [code of conduct](https://github.com/[USERNAME]/lppP6/blob/master/CODE_OF_CONDUCT.md).
43
+
44
+ ******
45
+
46
+ ## *Creado por: **Eric Dürr Sierra** .*
47
+ ## *Centro de estudio: **Escuela Superior de Ingeniería y Tecnología** .*
48
+ ## *A fecha de: **noviembre de 2019** .*
49
+ > alu0101027005@ull.edu.es
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 "lppP6"
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/DSLMenu.rb ADDED
@@ -0,0 +1,70 @@
1
+
2
+ class DSLMenu
3
+ attr_accessor :nombre, :platos, :menu
4
+
5
+ def initialize(nombre, &block)
6
+ @nombre = nombre
7
+ @platos = []
8
+ @menu = []
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 = "\n\n\n" + @nombre.upcase
21
+ output << "\n#{'='*@nombre.size}\n\n "
22
+ @menu.each do |menu|
23
+ output << "#{menu}"
24
+ end
25
+ output << "\n\n"
26
+ @platos.each_with_index do |plato, i|
27
+ output << "[#{i + 1}] #{plato}\n"
28
+ end
29
+
30
+ output << "\n\n\n"
31
+ output
32
+ end
33
+
34
+ def plato(nombre, opciones = {})
35
+ plato = nombre
36
+ plato << "\n| contiene: #{opciones[:descripcion]} " if opciones[:descripcion]
37
+ plato << " | valor nutricional: #{opciones[:nutricional]}" if opciones[:nutricional]
38
+ plato << " | impacto ambiental: #{opciones[:ambiental]}" if opciones[:ambiental]
39
+ plato << "\n\n #{opciones[:precio]} €\n" if opciones[:precio]
40
+ @platos << plato
41
+ end
42
+
43
+ def menu(descripcion, opciones= {})
44
+ menu = descripcion
45
+ menu << "\n#{'-'*descripcion.size}"
46
+ menu << "\n\n #{opciones[:precio]} €" if opciones[:precio]
47
+ @menu << menu
48
+ end
49
+ end
50
+
51
+ combo1 = DSLMenu.new("Combinado nº 1") do
52
+ menu "hamburguesa con queso, papas, refresco", :precio => 7.59
53
+ plato "hamburguesa especial de la casa",
54
+ :descripcion => "carne de vaca, huevo, bacon, tomate, lechuga",
55
+ :nutricional => "490 kcal",
56
+ :ambiental => "170 gei 240 m²",
57
+ :precio => 4.25
58
+ plato "papas fritas",
59
+ :descripcion => "papas, aceite, sal",
60
+ :nutricional => "570 kcal",
61
+ :ambiental => "90 gei 130 m²",
62
+ :precio => 1.75
63
+ plato "refresco",
64
+ :nutricional => "120 kcal",
65
+ :precio => 1.50
66
+
67
+ end
68
+
69
+
70
+ puts combo1
data/lib/Dish.rb ADDED
@@ -0,0 +1,109 @@
1
+ # @author Eric Dürr
2
+
3
+
4
+ require "lppP6/version"
5
+ require "DobLinkedList.rb"
6
+ require "EnvImpact.rb"
7
+
8
+
9
+
10
+ class Dish
11
+
12
+ attr_reader :name,:grams,:foodList
13
+
14
+ def initialize(name, foods ,grams)
15
+ super()
16
+ @name = name
17
+ @grams = grams
18
+ @foodList = DobLinkedList.new()
19
+ @foodList.insertMany(foods)
20
+
21
+ end
22
+
23
+ def to_s
24
+ s = "( #{name} :"
25
+ food_arr = @foodList.collect { |i| i.value.name }
26
+ food_arr.each_with_index { |name, i| s <<" |#{name}| x #{@grams[i]} g " }
27
+ s << ": )"
28
+ end
29
+
30
+
31
+
32
+ def pprot
33
+ current = @foodList.head
34
+ totalgrams = 0
35
+ totalprot = 0
36
+ count = 0
37
+ #@grams.each { |i| totalgrams += i }
38
+
39
+ while current
40
+ totalprot += (current.value.pr_g * @grams[count])
41
+ totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
42
+ count += 1
43
+
44
+ current = current.next
45
+ end
46
+ pprot = (totalprot*100)/totalgrams
47
+ pprot
48
+ end
49
+
50
+ def plip
51
+ current = @foodList.head
52
+ totalgrams = 0
53
+ totallip = 0
54
+ count = 0
55
+ #@grams.each { |i| totalgrams += i }
56
+
57
+ while current
58
+ totallip += (current.value.lp_g * @grams[count])
59
+ totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
60
+ count += 1
61
+
62
+ current = current.next
63
+ end
64
+ plip= (totallip*100)/totalgrams
65
+ plip
66
+ end
67
+
68
+ def pch
69
+ current = @foodList.head
70
+ totalgrams = 0
71
+ totalch = 0
72
+ count = 0
73
+ #@grams.each { |i| totalgrams += i }
74
+
75
+ while current
76
+ totalch += (current.value.ch_g * @grams[count])
77
+ totalgrams += ((current.value.pr_g + current.value.lp_g + current.value.ch_g) * @grams[count])
78
+ count += 1
79
+ current = current.next
80
+ end
81
+ pch= (totalch*100)/totalgrams
82
+ pch
83
+ end
84
+
85
+ def tcv
86
+ current = @foodList.head
87
+ total = 0
88
+ count = 0
89
+ while current
90
+ total += (current.value.n_value * @grams[count])
91
+ count += 1
92
+ current = current.next
93
+ end
94
+ total
95
+ end
96
+
97
+ def energyMean
98
+
99
+ current = @foodList.head
100
+ total = 0
101
+ count = 0
102
+ while current
103
+ total += (current.value.n_value )
104
+ count += 1
105
+ current = current.next
106
+ end
107
+ total end
108
+
109
+ end
data/lib/DishImpact.rb ADDED
@@ -0,0 +1,85 @@
1
+ # @author Eric Dürr
2
+
3
+
4
+ require "lppP6/version"
5
+ require "Dish.rb"
6
+
7
+
8
+
9
+ class DishImpact < Dish
10
+
11
+ include Comparable
12
+
13
+ attr_reader :name, :grams, :foodList, :e_fp, :n_fp
14
+
15
+ def initialize(name, foods ,grams)
16
+ super(name, foods ,grams)
17
+ nutritional_footprints
18
+ end
19
+ def dailygei
20
+ current = @foodList.head
21
+ total = 0
22
+ count = 0
23
+ while current
24
+ total += (current.value.gei * @grams[count])
25
+ count += 1
26
+ current = current.next
27
+ end
28
+ total
29
+ end
30
+ def terrainTotal
31
+ current = @foodList.head
32
+ total = 0
33
+ count = 0
34
+ while current
35
+ total += (current.value.terrain * @grams[count])
36
+ count += 1
37
+ current = current.next
38
+ end
39
+ total
40
+ end
41
+
42
+ def geiMean
43
+ current = @foodList.head
44
+ total = 0
45
+ count = 0
46
+ while current
47
+ total += (current.value.gei * @grams[count])
48
+ count += 1
49
+ current = current.next
50
+ end
51
+ total/foodList.length
52
+ end
53
+
54
+
55
+ def nutritional_footprints
56
+ @n_fp = 0
57
+ if energyMean < 670 then
58
+ @n_fp = 1
59
+ elsif energyMean > 830 then
60
+ @n_fp = 3
61
+ else
62
+ @n_fp = 2
63
+ end
64
+
65
+ @e_fp = 0
66
+ if dailygei < 800 then
67
+ @e_fp = 1
68
+ elsif dailygei > 1200 then
69
+ @e_fp = 3
70
+ else
71
+ @e_fp = 2
72
+ end
73
+
74
+ end
75
+
76
+ def to_s
77
+ "(: #{@name} : gei [#{dailygei}] | terrain [#{terrainTotal}] :)"
78
+ end
79
+
80
+ def <=>(other)
81
+ return nil unless other.instance_of? DishImpact
82
+
83
+ terrainTotal + dailygei <=> other.terrainTotal + other.dailygei
84
+ end
85
+ end
@@ -0,0 +1,186 @@
1
+ # @author Eric Dürr
2
+
3
+
4
+ require "lppP6/version"
5
+
6
+ Node = Struct.new(:value, :next, :prev) do
7
+ include Comparable
8
+
9
+ def <=>(other)
10
+ return nil unless other.instance_of?Node
11
+
12
+ value <=> other.value
13
+ end
14
+
15
+ def to_s
16
+ "[ |#{value}| ]"
17
+ end
18
+ end
19
+
20
+
21
+ class DobLinkedList
22
+
23
+
24
+ include Comparable, Enumerable
25
+
26
+ attr_reader :head, :tail, :length
27
+
28
+ def initialize
29
+ @head = nil
30
+ @tail = nil
31
+ @length = 0
32
+ end
33
+
34
+ def to_s
35
+ listString = ""
36
+ current = @head
37
+ while current
38
+
39
+ listString = listString + current.to_s
40
+ current = current.next
41
+ end
42
+
43
+ return listString
44
+ end
45
+
46
+
47
+ def insertHead(value)
48
+ node = Node.new(value, nil, nil)
49
+
50
+ if @head
51
+ node.next = @head
52
+ @head.prev = node
53
+ @head = node
54
+ else
55
+ @head = node
56
+ end
57
+ @length += 1
58
+ end
59
+
60
+
61
+ def insertTail(value)
62
+ node = Node.new(value, nil, nil)
63
+
64
+ unless @head
65
+ @head = node
66
+ else
67
+ node.prev = @tail
68
+ @tail.next = node
69
+ end
70
+ @tail = node
71
+ @length += 1
72
+ end
73
+
74
+
75
+ def insertMany(valuesArray)
76
+
77
+ valuesArray.each {| value |
78
+
79
+ node = Node.new(value, nil, nil)
80
+
81
+ unless @head
82
+ @head = node
83
+ else
84
+ node.prev = @tail
85
+ @tail.next = node
86
+ end
87
+ @tail = node
88
+ @length += 1
89
+
90
+ }
91
+ end
92
+
93
+ def remove_head
94
+
95
+ if @head.next.nil?
96
+ @head = @tail = nil
97
+ else
98
+ @head = @head.next
99
+ @head.prev = nil
100
+ end
101
+
102
+ @length -= 1
103
+ end
104
+
105
+ def remove_tail
106
+
107
+ if @tail.prev.nil?
108
+ @tail = @head = nil
109
+
110
+ else
111
+
112
+ @tail = @tail.prev
113
+ @tail.next = nil
114
+ end
115
+
116
+ @length -= 1
117
+ end
118
+
119
+ def remove(node)
120
+ return nil unless node
121
+
122
+ if node == @head
123
+ if @head.next.nil?
124
+ @head = @tail = nil
125
+ else
126
+ @head = @head.next
127
+ end
128
+ else
129
+ pr = node.prev
130
+ ne = node.next
131
+ pr&.next = ne
132
+ ne&.prev = pr
133
+ end
134
+ @length -= 1
135
+ end
136
+
137
+ def <=>(other)
138
+ return nil unless other.instance_of? DobLinkedList
139
+
140
+ value <=> other.value
141
+ end
142
+
143
+ def find_first(&predicate)
144
+ return nil unless block_given?
145
+ current = @head
146
+ while current
147
+ return current if predicate.call(current)
148
+ current = current.next
149
+ end
150
+ end
151
+
152
+
153
+ def each
154
+ return nil unless block_given?
155
+ current = @head
156
+ while current
157
+ yield current
158
+ current = current.next
159
+ end
160
+ end
161
+
162
+ def find_node (index)
163
+ current = @head
164
+ count = 0
165
+ while current
166
+ return current if count==index
167
+ count += 1
168
+ current = current.next
169
+ end
170
+ end
171
+
172
+ def [](index)
173
+ case index
174
+ when 0, -@length
175
+ @head
176
+ when length-1, -1
177
+ @tail
178
+ else
179
+ find_node(index)
180
+ end
181
+ end
182
+
183
+
184
+
185
+
186
+ end
data/lib/EnvImpact.rb ADDED
@@ -0,0 +1,37 @@
1
+ # @author Eric Dürr
2
+
3
+
4
+
5
+ require "lppP6/version"
6
+
7
+ class EnvImpact
8
+ include Comparable
9
+ attr_accessor :name, :pr_g, :ch_g, :lp_g , :gei, :terrain
10
+ def initialize(name, pr_g, ch_g, lp_g , gei, terrain)
11
+ @name = name
12
+ @pr_g, @ch_g, @lp_g = pr_g, ch_g, lp_g
13
+ @gei, @terrain = gei, terrain
14
+ end
15
+
16
+ def to_s
17
+ "#{name} =>| Proteinas/g: #{pr_g} | Carbohidratos/g: #{ch_g} | Lipidos/g: #{lp_g} | GEI: #{gei} | m²/año: #{terrain}"
18
+ end
19
+
20
+ def n_value
21
+ (@pr_g*4 + @ch_g*4 + lp_g*9)
22
+ end
23
+
24
+ def e_value
25
+ (gei + terrain)
26
+ end
27
+
28
+ def <=>(other)
29
+ return nil unless other.instance_of? EnvImpact
30
+
31
+ n_value + e_value <=> other.n_value + other.e_value
32
+ end
33
+
34
+
35
+ end
36
+
37
+
data/lib/Menu.rb ADDED
@@ -0,0 +1,33 @@
1
+ # @author Eric Dürr
2
+
3
+
4
+ require "lppP6/version"
5
+ require "DishImpact.rb"
6
+
7
+
8
+ class Menu
9
+ include Comparable, Enumerable
10
+
11
+ attr_reader :name, :dishes, :prices
12
+
13
+ def initialize (name, dishes, prices)
14
+ @name = name
15
+ @dishes, @prices = dishes, prices
16
+ end
17
+
18
+
19
+ # ---- sobrecargas ---
20
+ def <=>(other)
21
+ return nil unless other.instance_of? Menu
22
+ total_impact = 0
23
+ total_price = 0
24
+ other_impact = 0
25
+ other_price = 0
26
+ dishes.each { | dish | total_impact += (dish.terrainTotal + dish.dailygei) }
27
+ other.dishes.each { | dish | other_impact += (dish.terrainTotal + dish.dailygei) }
28
+ prices.each { | price | total_price += price }
29
+ other.prices.each { | price | other_price += price }
30
+ total_impact + total_price <=> other_impact + other_price
31
+ end
32
+
33
+ end
@@ -0,0 +1,3 @@
1
+ module LppP6
2
+ VERSION = "1.0.0"
3
+ end
data/lppP6.gemspec ADDED
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "lppP6/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "lppP6lu0101027005"
7
+ spec.version = LppP6::VERSION
8
+ spec.authors = ["Eric Dürr Sierra"]
9
+ spec.email = ["alu0101027005@ull.edu.es"]
10
+
11
+ spec.summary = %q{first tdd steps}
12
+ spec.description = %q{longer description...}
13
+ spec.homepage = "https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO"
14
+ spec.license = "MIT"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org/"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO"
20
+ spec.metadata["changelog_uri"] = "https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO"
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 "yard"
38
+ spec.add_development_dependency "travis"
39
+ spec.add_development_dependency "coveralls"
40
+
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,194 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lppP6lu0101027005
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Dürr Sierra
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: '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: yard
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
+ - !ruby/object:Gem::Dependency
112
+ name: travis
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coveralls
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: longer description...
140
+ email:
141
+ - alu0101027005@ull.edu.es
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".coverralls.yml"
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - Gemfile.lock
153
+ - Guardfile
154
+ - LICENSE.txt
155
+ - README.md
156
+ - Rakefile
157
+ - bin/console
158
+ - bin/setup
159
+ - lib/DSLMenu.rb
160
+ - lib/Dish.rb
161
+ - lib/DishImpact.rb
162
+ - lib/DobLinkedList.rb
163
+ - lib/EnvImpact.rb
164
+ - lib/Menu.rb
165
+ - lib/lppP6/version.rb
166
+ - lppP6.gemspec
167
+ homepage: https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO
168
+ licenses:
169
+ - MIT
170
+ metadata:
171
+ allowed_push_host: https://rubygems.org/
172
+ homepage_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO
173
+ source_code_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO
174
+ changelog_uri: https://github.com/ULL-ESIT-LPP-1920/tdd-EricDS-INFO
175
+ post_install_message:
176
+ rdoc_options: []
177
+ require_paths:
178
+ - lib
179
+ required_ruby_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ required_rubygems_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ requirements: []
190
+ rubygems_version: 3.0.6
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: first tdd steps
194
+ test_files: []