alimento-alu0100987829 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +95 -0
- data/Guardfile +83 -0
- data/README.md +6 -0
- data/Rakefile +6 -0
- data/alimento.gemspec +31 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/alimento.rb +12 -0
- data/lib/alimento/alimento.rb +96 -0
- data/lib/alimento/list.rb +84 -0
- data/lib/alimento/menu_dsl.rb +45 -0
- data/lib/alimento/plato.rb +122 -0
- data/lib/alimento/plato_dsl.rb +128 -0
- data/lib/alimento/version.rb +4 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e089ac2cb380662e9172cda17ca4f1a260b773fbda65badceec7fcfaa3e288eb
|
4
|
+
data.tar.gz: 34ec3db7e2f07d2a513c18c7a536770e5f2a32d81b38d2879d45889e863e429f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2984e0a3a0d8d497d363926c3fe7f5cfdc7c1c8414a0d7d49dfa798213e0df47e9c57fc418e3db5d56a01f0d62038196fb8e8a0d34bcd2bb47ed43d1548f47e6
|
7
|
+
data.tar.gz: 681e62e9ef2875ac43e0ffebf23c7790928bc0ed95406db2f741757158f2608af656c6a6682ec551e9723054c378c6f08b531be61d2572ac6fb8006f3b82b0aa
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
alimento-alu0100987829 (0.1.1)
|
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 (10.5.0)
|
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.23.0)
|
79
|
+
sync
|
80
|
+
|
81
|
+
PLATFORMS
|
82
|
+
ruby
|
83
|
+
|
84
|
+
DEPENDENCIES
|
85
|
+
alimento-alu0100987829!
|
86
|
+
bundler (~> 2.0)
|
87
|
+
coveralls
|
88
|
+
guard
|
89
|
+
guard-bundler
|
90
|
+
guard-rspec
|
91
|
+
rake (~> 10.0)
|
92
|
+
rspec (~> 3.0)
|
93
|
+
|
94
|
+
BUNDLED WITH
|
95
|
+
2.0.2
|
data/Guardfile
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec features) \
|
6
|
+
# .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
|
+
watch(%r{^lib/(.+)\.rb$}) { dsl.rspec.spec_dir }
|
45
|
+
|
46
|
+
# RSpec files
|
47
|
+
rspec = dsl.rspec
|
48
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
49
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
50
|
+
watch(rspec.spec_files)
|
51
|
+
|
52
|
+
# Ruby files
|
53
|
+
ruby = dsl.ruby
|
54
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
55
|
+
|
56
|
+
# Rails files
|
57
|
+
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
58
|
+
dsl.watch_spec_files_for(rails.app_files)
|
59
|
+
dsl.watch_spec_files_for(rails.views)
|
60
|
+
|
61
|
+
watch(rails.controllers) do |m|
|
62
|
+
[
|
63
|
+
rspec.spec.call("routing/#{m[1]}_routing"),
|
64
|
+
rspec.spec.call("controllers/#{m[1]}_controller"),
|
65
|
+
rspec.spec.call("acceptance/#{m[1]}")
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
# Rails config changes
|
70
|
+
watch(rails.spec_helper) { rspec.spec_dir }
|
71
|
+
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
72
|
+
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
73
|
+
|
74
|
+
# Capybara features specs
|
75
|
+
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
76
|
+
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
77
|
+
|
78
|
+
# Turnip features and steps
|
79
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
80
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
81
|
+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
82
|
+
end
|
83
|
+
end
|
data/README.md
ADDED
data/Rakefile
ADDED
data/alimento.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "alimento/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "alimento-alu0100987829"
|
7
|
+
spec.version = Alimento::VERSION
|
8
|
+
spec.authors = ["Óscar Carrasco"]
|
9
|
+
spec.email = ["alu0100987829@ull.edu.es"]
|
10
|
+
|
11
|
+
spec.summary = %q{Práctica 6}
|
12
|
+
spec.description = %q{Huella nutricional}
|
13
|
+
spec.homepage = "https://github.com/ULL-ESIT-LPP-1920/tdd-alu0100987829"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
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
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "alimento"
|
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
data/lib/alimento.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
require "alimento/alimento.rb"
|
3
|
+
require "alimento/list.rb"
|
4
|
+
require "alimento/plato.rb"
|
5
|
+
require "alimento/plato_dsl.rb"
|
6
|
+
require "alimento/menu_dsl.rb"
|
7
|
+
|
8
|
+
# Módulo para las prácticas sobre TDD de la asignatura
|
9
|
+
# "Lenguajes y Paradigmas de Programación"
|
10
|
+
module Alimento
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
|
3
|
+
module Alimento
|
4
|
+
class Error < StandardError; end
|
5
|
+
# Representación de un alimento, junto con las propiedades nutricionales y ambientales
|
6
|
+
# que lo definen. Es inicializado con los parámetros "nombre", "proteínas",
|
7
|
+
# "carbohidratos", "lípidos", "GEI" (Gases de Efecto Invernadero) y "terreno":
|
8
|
+
class Alimento
|
9
|
+
include Comparable
|
10
|
+
attr_reader :nombre, :proteinas, :carbohidratos, :lipidos, :GEI, :terreno
|
11
|
+
def initialize(nombre, proteinas, carbohidratos, lipidos, gei, terreno)
|
12
|
+
@nombre = nombre
|
13
|
+
@proteinas = proteinas
|
14
|
+
@carbohidratos = carbohidratos
|
15
|
+
@lipidos = lipidos
|
16
|
+
@GEI = gei
|
17
|
+
@terreno = terreno
|
18
|
+
end
|
19
|
+
|
20
|
+
# Devuelve el nombre del alimento.
|
21
|
+
def getNombre
|
22
|
+
@nombre
|
23
|
+
end
|
24
|
+
|
25
|
+
# Devuelve el factor de gases de efecto invernadero.
|
26
|
+
def getGEI
|
27
|
+
@GEI
|
28
|
+
end
|
29
|
+
|
30
|
+
# Devuelve el terreno utilizado.
|
31
|
+
def getTerreno
|
32
|
+
@terreno
|
33
|
+
end
|
34
|
+
|
35
|
+
# Devuelve las proteínas del alimento.
|
36
|
+
def getProteinas
|
37
|
+
@proteinas
|
38
|
+
end
|
39
|
+
|
40
|
+
# Devuelve los lípidos del alimento.
|
41
|
+
def getLipidos
|
42
|
+
@lipidos
|
43
|
+
end
|
44
|
+
|
45
|
+
# Devuelve los carbohidratos del alimento.
|
46
|
+
def getCarbohidratos
|
47
|
+
@carbohidratos
|
48
|
+
end
|
49
|
+
|
50
|
+
# Devuelve el valor calórico en kcal del alimento.
|
51
|
+
def getValorCalorico
|
52
|
+
resultado = '%0.1f' % ((getProteinas * 4) + (getLipidos * 4) + (getCarbohidratos * 9))
|
53
|
+
return resultado.to_f
|
54
|
+
end
|
55
|
+
|
56
|
+
def to_s
|
57
|
+
"#{@nombre}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def <=>(other)
|
61
|
+
if other != nil
|
62
|
+
getValorCalorico<=>other.getValorCalorico
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# Calcula las calorías de una dieta a partir de los valores calóricos
|
67
|
+
# de esta.
|
68
|
+
def calcularCaloriasDieta(*valores_caloricos)
|
69
|
+
resultado = getValorCalorico
|
70
|
+
for valor in valores_caloricos
|
71
|
+
resultado += valor
|
72
|
+
end
|
73
|
+
return resultado.round(1)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Calcula el factor de gases de efecto invernadero a partir de valores
|
77
|
+
# de gases de efecto invernaderos o GEIs.
|
78
|
+
def calcularGEI(*geis)
|
79
|
+
resultado = getGEI
|
80
|
+
for gei in geis
|
81
|
+
resultado += gei
|
82
|
+
end
|
83
|
+
return resultado.round(2)
|
84
|
+
end
|
85
|
+
|
86
|
+
# Calcula el terreno consumido por la creación del alimento a partir
|
87
|
+
# de valores de terreno de este.
|
88
|
+
def calcularTerreno(*terrenos)
|
89
|
+
resultado = getTerreno
|
90
|
+
for terreno in terrenos
|
91
|
+
resultado += terreno
|
92
|
+
end
|
93
|
+
return resultado.round(2)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
module Alimento
|
5
|
+
# Nodo forma los elementos con valor genérico que forman parte de
|
6
|
+
# la lista.
|
7
|
+
Nodo = Struct.new(:value, :next, :prev)
|
8
|
+
# Lista doblemente enlazada y enumerable. Es posible inicializarla
|
9
|
+
# añadiéndole valores desde un principio.
|
10
|
+
class List
|
11
|
+
include Enumerable
|
12
|
+
attr_reader :head, :tail
|
13
|
+
def initialize(*values)
|
14
|
+
@head = Nodo.new(nil, nil, nil)
|
15
|
+
@tail = @head
|
16
|
+
if values != nil
|
17
|
+
values.each { |value| unshift(value) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
# Devuelve un booleano indicando si la lista se encuentra vacía.
|
21
|
+
def empty
|
22
|
+
@head.value == nil
|
23
|
+
end
|
24
|
+
# Devuelve el número de elementos contenidos en la lista.
|
25
|
+
def size
|
26
|
+
if empty
|
27
|
+
0
|
28
|
+
elsif head == tail && head.value != nil
|
29
|
+
1
|
30
|
+
else
|
31
|
+
i = 1
|
32
|
+
aux = @head
|
33
|
+
while aux != @tail
|
34
|
+
i += 1
|
35
|
+
aux = aux.next
|
36
|
+
end
|
37
|
+
i
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# Inserta un elemento "value" al final de la lista
|
41
|
+
def unshift(value)
|
42
|
+
if empty
|
43
|
+
@head.value = value
|
44
|
+
elsif size == 1
|
45
|
+
@tail = Nodo.new(value, nil, @head)
|
46
|
+
@head.next = @tail
|
47
|
+
else
|
48
|
+
aux = Nodo.new(@tail.value, nil, @tail.prev)
|
49
|
+
pre_tail = @tail.prev
|
50
|
+
@tail = Nodo.new(value, nil, aux)
|
51
|
+
aux.next = @tail
|
52
|
+
pre_tail.next = aux
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def <<(value)
|
56
|
+
unshift(value)
|
57
|
+
end
|
58
|
+
# Devuelve la cabeza de la lista
|
59
|
+
def first
|
60
|
+
@head.value
|
61
|
+
end
|
62
|
+
# Devuelve la cola de la lista
|
63
|
+
def last
|
64
|
+
@tail.value
|
65
|
+
end
|
66
|
+
def to_s
|
67
|
+
ret = "{"
|
68
|
+
aux = @head
|
69
|
+
while (aux != @tail) do
|
70
|
+
ret += "#{aux.value.to_s}, "
|
71
|
+
aux = aux.next
|
72
|
+
end
|
73
|
+
ret += "#{aux.value.to_s}}"
|
74
|
+
return ret
|
75
|
+
end
|
76
|
+
def each
|
77
|
+
aux = @head
|
78
|
+
while (aux != nil)
|
79
|
+
yield aux.value
|
80
|
+
aux = aux.next
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
module Alimento
|
5
|
+
# Menu formado por platos
|
6
|
+
class MenuDSL
|
7
|
+
attr_reader :name
|
8
|
+
def initialize(desc, &block)
|
9
|
+
@desc = desc
|
10
|
+
@listaPlatos = []
|
11
|
+
@listaPrecios = []
|
12
|
+
@precio = 0.0
|
13
|
+
|
14
|
+
if block_given?
|
15
|
+
if block.arity == 1
|
16
|
+
yield self
|
17
|
+
else
|
18
|
+
instance_eval(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def descripcion(desc)
|
23
|
+
@desc = desc
|
24
|
+
end
|
25
|
+
def componente(plato, options = {})
|
26
|
+
unless options[:precio].nil?
|
27
|
+
@listaPlatos << plato
|
28
|
+
@listaPrecios << options[:precio]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
def precio(value)
|
32
|
+
@precio = value
|
33
|
+
end
|
34
|
+
def to_s
|
35
|
+
count = 0
|
36
|
+
ret = "Menu: #{@desc}\nPlatos:\n"
|
37
|
+
ret + @listaPlatos.zip(@listaPrecios).map {
|
38
|
+
|x| "Plato #{count += 1}: " + x.last.to_s + "€\n" +
|
39
|
+
x.first.to_s +
|
40
|
+
"\nValor nutricional: #{x.first.getValorCaloricoTotal}" +
|
41
|
+
"\nValor ambiental: #{x.first.getEmisionGEI}"
|
42
|
+
}.join("\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
module Alimento
|
5
|
+
# Plato formado por cantidades de uno o más alimentos.
|
6
|
+
class Plato
|
7
|
+
include Comparable
|
8
|
+
attr_reader :nombre, :listaAlimentos, :listaGramos
|
9
|
+
def initialize (nombre, listaAlimentos, listaGramos)
|
10
|
+
@nombre = nombre
|
11
|
+
@listaAlimentos = listaAlimentos
|
12
|
+
@listaGramos = listaGramos
|
13
|
+
end
|
14
|
+
# Devuelve el total de proteínas del plato.
|
15
|
+
def getProteinas
|
16
|
+
aux = listaAlimentos.head
|
17
|
+
aux2 = listaGramos.head
|
18
|
+
proteinas = 0
|
19
|
+
gramosTotales = 0
|
20
|
+
while aux != nil && listaGramos != nil
|
21
|
+
proteinas += aux.value.proteinas * (aux2.value/100)
|
22
|
+
gramosTotales = aux2.value
|
23
|
+
aux = aux.next
|
24
|
+
aux2 = aux2.next
|
25
|
+
end
|
26
|
+
return ((proteinas * 100)/gramosTotales).round(2)
|
27
|
+
end
|
28
|
+
# Devuelve el total de lípidos del plato.
|
29
|
+
def getLipidos
|
30
|
+
aux = listaAlimentos.head
|
31
|
+
aux2 = listaGramos.head
|
32
|
+
lipidos = 0
|
33
|
+
gramosTotales = 0
|
34
|
+
while aux != nil && listaGramos != nil
|
35
|
+
lipidos += aux.value.lipidos * (aux2.value/100)
|
36
|
+
gramosTotales = aux2.value
|
37
|
+
aux = aux.next
|
38
|
+
aux2 = aux2.next
|
39
|
+
end
|
40
|
+
return ((lipidos * 100)/gramosTotales).round(2)
|
41
|
+
end
|
42
|
+
# Devuelve el total de carbohidratos del plato.
|
43
|
+
def getCarbohidratos
|
44
|
+
aux = listaAlimentos.head
|
45
|
+
aux2 = listaGramos.head
|
46
|
+
carbohidratos = 0
|
47
|
+
gramosTotales = 0
|
48
|
+
while aux != nil && listaGramos != nil
|
49
|
+
carbohidratos += aux.value.carbohidratos * (aux2.value/100)
|
50
|
+
gramosTotales = aux2.value
|
51
|
+
aux = aux.next
|
52
|
+
aux2 = aux2.next
|
53
|
+
end
|
54
|
+
return ((carbohidratos * 100)/gramosTotales).round(2)
|
55
|
+
end
|
56
|
+
# Devuelve la cantidad total de gramos del plato.
|
57
|
+
def getGramosTotales
|
58
|
+
aux = listaGramos.head
|
59
|
+
gramosTotales = 0
|
60
|
+
while aux != nil
|
61
|
+
gramosTotales = aux.value
|
62
|
+
aux = aux.next
|
63
|
+
end
|
64
|
+
return gramosTotales
|
65
|
+
end
|
66
|
+
# Devuelve el total del valor calórico del plato.
|
67
|
+
def getValorCaloricoTotal
|
68
|
+
proteinas = (getProteinas * getGramosTotales) / 100
|
69
|
+
carbohidratos = (getCarbohidratos * getGramosTotales) / 100
|
70
|
+
lipidos = (getLipidos * getGramosTotales) / 100
|
71
|
+
return (proteinas*4 + carbohidratos*9 + lipidos*4).round(2)
|
72
|
+
end
|
73
|
+
def to_s
|
74
|
+
ret = "Nombre: #{@nombre}\n"
|
75
|
+
ret << listaAlimentos.to_s
|
76
|
+
ret += "\n"
|
77
|
+
ret
|
78
|
+
end
|
79
|
+
def <=>(other)
|
80
|
+
if other != nil
|
81
|
+
getValorCaloricoTotal <=> other.getValorCaloricoTotal
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
# Clase que hereda de Plato y añade funcionalidad relacionada
|
86
|
+
# con el impacto ambiental de un plato de alimentos.
|
87
|
+
class PlatoEnergetico < Plato
|
88
|
+
def initialize (nombre, listaAlimentos, listaGramos)
|
89
|
+
super(nombre, listaAlimentos, listaGramos)
|
90
|
+
end
|
91
|
+
# Devuelve las emisiones de gases de efecto invernadero de un plato.
|
92
|
+
def getEmisionGEI
|
93
|
+
aux = listaAlimentos.head
|
94
|
+
aux2 = listaGramos.head
|
95
|
+
|
96
|
+
geiTotal = 0
|
97
|
+
while aux != nil && aux2 != nil
|
98
|
+
geiTotal += aux.value.GEI * (aux2.value / 100)
|
99
|
+
aux = aux.next
|
100
|
+
aux2 = aux2.next
|
101
|
+
end
|
102
|
+
geiTotal.round(2)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Devuelve el terreno consumido por los alimentos de un plato.
|
106
|
+
def getTerreno
|
107
|
+
aux = listaAlimentos.head
|
108
|
+
aux2 = listaGramos.head
|
109
|
+
|
110
|
+
terrenoTotal = 0
|
111
|
+
while aux != nil && aux2 != nil
|
112
|
+
terrenoTotal = aux.value.terreno * (aux2.value / 100)
|
113
|
+
aux = aux.next
|
114
|
+
end
|
115
|
+
terrenoTotal.round(2)
|
116
|
+
end
|
117
|
+
|
118
|
+
def to_s
|
119
|
+
super + "Eficiencia energética: #{getValorCaloricoTotal}\n"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "alimento/version"
|
2
|
+
|
3
|
+
class Error < StandardError; end
|
4
|
+
module Alimento
|
5
|
+
# Plato formado por cantidades de uno o más alimentos.
|
6
|
+
class PlatoDSL
|
7
|
+
include Comparable
|
8
|
+
attr_reader :name
|
9
|
+
def initialize(name, &block)
|
10
|
+
@name = name
|
11
|
+
@listaAlimentos = List.new()
|
12
|
+
@listaGramos = List.new()
|
13
|
+
|
14
|
+
if block_given?
|
15
|
+
if block.arity == 1
|
16
|
+
yield self
|
17
|
+
else
|
18
|
+
instance_eval(&block)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
def nombre(name)
|
23
|
+
@name = name
|
24
|
+
end
|
25
|
+
def alimento(alimento, options = {})
|
26
|
+
unless options[:gramos].nil?
|
27
|
+
@listaAlimentos << alimento
|
28
|
+
@listaGramos << options[:gramos]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
# Devuelve el total de proteínas del plato.
|
32
|
+
def getProteinas
|
33
|
+
aux = @listaAlimentos.head
|
34
|
+
aux2 = @listaGramos.head
|
35
|
+
proteinas = 0
|
36
|
+
gramosTotales = 0
|
37
|
+
while aux != nil && @listaGramos != nil
|
38
|
+
proteinas += aux.value.proteinas * (aux2.value/100)
|
39
|
+
gramosTotales = aux2.value
|
40
|
+
aux = aux.next
|
41
|
+
aux2 = aux2.next
|
42
|
+
end
|
43
|
+
return ((proteinas * 100)/gramosTotales).round(2)
|
44
|
+
end
|
45
|
+
# Devuelve el total de lípidos del plato.
|
46
|
+
def getLipidos
|
47
|
+
aux = @listaAlimentos.head
|
48
|
+
aux2 = @listaGramos.head
|
49
|
+
lipidos = 0
|
50
|
+
gramosTotales = 0
|
51
|
+
while aux != nil && @listaGramos != nil
|
52
|
+
lipidos += aux.value.lipidos * (aux2.value/100)
|
53
|
+
gramosTotales = aux2.value
|
54
|
+
aux = aux.next
|
55
|
+
aux2 = aux2.next
|
56
|
+
end
|
57
|
+
return ((lipidos * 100)/gramosTotales).round(2)
|
58
|
+
end
|
59
|
+
# Devuelve el total de carbohidratos del plato.
|
60
|
+
def getCarbohidratos
|
61
|
+
aux = @listaAlimentos.head
|
62
|
+
aux2 = @listaGramos.head
|
63
|
+
carbohidratos = 0
|
64
|
+
gramosTotales = 0
|
65
|
+
while aux != nil && @listaGramos != nil
|
66
|
+
carbohidratos += aux.value.carbohidratos * (aux2.value/100)
|
67
|
+
gramosTotales = aux2.value
|
68
|
+
aux = aux.next
|
69
|
+
aux2 = aux2.next
|
70
|
+
end
|
71
|
+
return ((carbohidratos * 100)/gramosTotales).round(2)
|
72
|
+
end
|
73
|
+
# Devuelve la cantidad total de gramos del plato.
|
74
|
+
def getGramosTotales
|
75
|
+
aux = @listaGramos.head
|
76
|
+
gramosTotales = 0
|
77
|
+
while aux != nil
|
78
|
+
gramosTotales = aux.value
|
79
|
+
aux = aux.next
|
80
|
+
end
|
81
|
+
return gramosTotales
|
82
|
+
end
|
83
|
+
# Devuelve el total del valor calórico del plato.
|
84
|
+
def getValorCaloricoTotal
|
85
|
+
proteinas = (getProteinas * getGramosTotales) / 100
|
86
|
+
carbohidratos = (getCarbohidratos * getGramosTotales) / 100
|
87
|
+
lipidos = (getLipidos * getGramosTotales) / 100
|
88
|
+
return (proteinas*4 + carbohidratos*9 + lipidos*4).round(2)
|
89
|
+
end
|
90
|
+
# Devuelve las emisiones de gases de efecto invernadero de un plato.
|
91
|
+
def getEmisionGEI
|
92
|
+
aux = @listaAlimentos.head
|
93
|
+
aux2 = @listaGramos.head
|
94
|
+
|
95
|
+
geiTotal = 0
|
96
|
+
while aux != nil && aux2 != nil
|
97
|
+
geiTotal += aux.value.GEI * (aux2.value / 100)
|
98
|
+
aux = aux.next
|
99
|
+
aux2 = aux2.next
|
100
|
+
end
|
101
|
+
geiTotal.round(2)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Devuelve el terreno consumido por los alimentos de un plato.
|
105
|
+
def getTerreno
|
106
|
+
aux = @listaAlimentos.head
|
107
|
+
aux2 = @listaGramos.head
|
108
|
+
|
109
|
+
terrenoTotal = 0
|
110
|
+
while aux != nil && aux2 != nil
|
111
|
+
terrenoTotal = aux.value.terreno * (aux2.value / 100)
|
112
|
+
aux = aux.next
|
113
|
+
end
|
114
|
+
terrenoTotal.round(2)
|
115
|
+
end
|
116
|
+
def to_s
|
117
|
+
ret = "#{@name}\n"
|
118
|
+
ret + @listaAlimentos.zip(@listaGramos).map {
|
119
|
+
|x| x.first.to_s + " - " + x.last.to_s + " gramos"
|
120
|
+
}.join("\n")
|
121
|
+
end
|
122
|
+
def <=>(other)
|
123
|
+
if other != nil
|
124
|
+
getValorCaloricoTotal <=> other.getValorCaloricoTotal
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alimento-alu0100987829
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Óscar Carrasco
|
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: Huella nutricional
|
112
|
+
email:
|
113
|
+
- alu0100987829@ull.edu.es
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- Guardfile
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- alimento.gemspec
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- lib/alimento.rb
|
131
|
+
- lib/alimento/alimento.rb
|
132
|
+
- lib/alimento/list.rb
|
133
|
+
- lib/alimento/menu_dsl.rb
|
134
|
+
- lib/alimento/plato.rb
|
135
|
+
- lib/alimento/plato_dsl.rb
|
136
|
+
- lib/alimento/version.rb
|
137
|
+
homepage: https://github.com/ULL-ESIT-LPP-1920/tdd-alu0100987829
|
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.0.3
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Práctica 6
|
159
|
+
test_files: []
|