p6 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +76 -0
- data/Guardfile +82 -0
- data/README.md +7 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/.p6.rb.swp +0 -0
- data/lib/p6.rb +7 -0
- data/lib/p6/alimento.rb +33 -0
- data/lib/p6/indicadores.rb +106 -0
- data/lib/p6/list.rb +134 -0
- data/lib/p6/menu.rb +37 -0
- data/lib/p6/plato.rb +155 -0
- data/lib/p6/plato_dsl.rb +44 -0
- data/lib/p6/version.rb +3 -0
- data/p6.gemspec +30 -0
- data/pkg/p6-0.1.0.gem +0 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 74ff905449eb525cf2b956345daf7764377421d7404485f9328b98f2fd56d3cd
|
4
|
+
data.tar.gz: 67556073e70e65d73ae99b91d8ec2cd1de5101b79c82853a8fe2d02a689f0742
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 205c7c622d39e778a15783c611e88ae1003e7ddc9f3b54d3062854c1ec5baf5bceb2d0e9ee5a2d4d8a4c59abb8108f653efde5269b3c0491d689ad9832f48b59
|
7
|
+
data.tar.gz: d61078c1dc2911c9b449f0be37aefde055d832cad2083f175a4f475f49cae94231c26538e7807bdf4c7a1dd61bbfc503bd88534475398aa7664740bc2ab69d9d
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
p6 (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
ffi (1.11.2)
|
12
|
+
formatador (0.2.5)
|
13
|
+
guard (2.16.1)
|
14
|
+
formatador (>= 0.2.4)
|
15
|
+
listen (>= 2.7, < 4.0)
|
16
|
+
lumberjack (>= 1.0.12, < 2.0)
|
17
|
+
nenv (~> 0.1)
|
18
|
+
notiffany (~> 0.0)
|
19
|
+
pry (>= 0.9.12)
|
20
|
+
shellany (~> 0.0)
|
21
|
+
thor (>= 0.18.1)
|
22
|
+
guard-bundler (2.2.1)
|
23
|
+
bundler (>= 1.3.0, < 3)
|
24
|
+
guard (~> 2.2)
|
25
|
+
guard-compat (~> 1.1)
|
26
|
+
guard-compat (1.2.1)
|
27
|
+
guard-rspec (4.7.3)
|
28
|
+
guard (~> 2.1)
|
29
|
+
guard-compat (~> 1.1)
|
30
|
+
rspec (>= 2.99.0, < 4.0)
|
31
|
+
listen (3.2.0)
|
32
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
33
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
34
|
+
lumberjack (1.0.13)
|
35
|
+
method_source (0.9.2)
|
36
|
+
nenv (0.3.0)
|
37
|
+
notiffany (0.1.3)
|
38
|
+
nenv (~> 0.1)
|
39
|
+
shellany (~> 0.0)
|
40
|
+
pry (0.12.2)
|
41
|
+
coderay (~> 1.1.0)
|
42
|
+
method_source (~> 0.9.0)
|
43
|
+
rake (10.5.0)
|
44
|
+
rb-fsevent (0.10.3)
|
45
|
+
rb-inotify (0.10.0)
|
46
|
+
ffi (~> 1.0)
|
47
|
+
rspec (3.9.0)
|
48
|
+
rspec-core (~> 3.9.0)
|
49
|
+
rspec-expectations (~> 3.9.0)
|
50
|
+
rspec-mocks (~> 3.9.0)
|
51
|
+
rspec-core (3.9.0)
|
52
|
+
rspec-support (~> 3.9.0)
|
53
|
+
rspec-expectations (3.9.0)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.9.0)
|
56
|
+
rspec-mocks (3.9.0)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.9.0)
|
59
|
+
rspec-support (3.9.0)
|
60
|
+
shellany (0.0.1)
|
61
|
+
thor (0.20.3)
|
62
|
+
|
63
|
+
PLATFORMS
|
64
|
+
ruby
|
65
|
+
|
66
|
+
DEPENDENCIES
|
67
|
+
bundler (~> 2.0)
|
68
|
+
guard
|
69
|
+
guard-bundler
|
70
|
+
guard-rspec
|
71
|
+
p6!
|
72
|
+
rake (~> 10.0)
|
73
|
+
rspec (~> 3.0)
|
74
|
+
|
75
|
+
BUNDLED WITH
|
76
|
+
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/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "p6"
|
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/.p6.rb.swp
ADDED
Binary file
|
data/lib/p6.rb
ADDED
data/lib/p6/alimento.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'p6/version'
|
2
|
+
#Almacena alimentos
|
3
|
+
class Alimento
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
attr_accessor :nombre_, :proteinas_, :carbo_, :lipidos_, :emision_, :terreno_
|
7
|
+
|
8
|
+
#Constructor de la clase alimento
|
9
|
+
def initialize(nombre, proteinas, carbo, lipidos, emision, terreno)
|
10
|
+
@nombre_ = nombre
|
11
|
+
@proteinas_ = proteinas
|
12
|
+
@carbo_ = carbo
|
13
|
+
@lipidos_ = lipidos
|
14
|
+
@emision_ = emision
|
15
|
+
@terreno_ = terreno
|
16
|
+
end
|
17
|
+
|
18
|
+
#Devuelve las calorías del alimento
|
19
|
+
def calorias
|
20
|
+
@carbo_*4 + @lipidos_*9 + @proteinas_*4
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"(#{@nombre_},#{@proteinas_}, #{@carbo_}, #{@lipidos_}, #{@emision_}, #{@terreno_})"
|
25
|
+
end
|
26
|
+
|
27
|
+
#Método comparable
|
28
|
+
def <=>(other)
|
29
|
+
calorias <=> other.calorias
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,106 @@
|
|
1
|
+
def energia(x)
|
2
|
+
if x < 670
|
3
|
+
return 1
|
4
|
+
|
5
|
+
elsif x >= 670 && x<= 830
|
6
|
+
return 2
|
7
|
+
|
8
|
+
else
|
9
|
+
return 3
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def sal(x)
|
15
|
+
if x < 2
|
16
|
+
return 1
|
17
|
+
|
18
|
+
elsif x >= 2 && x <= 3.3
|
19
|
+
return 2
|
20
|
+
|
21
|
+
else
|
22
|
+
return 3
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def fibra(x)
|
28
|
+
if x > 8
|
29
|
+
return 1
|
30
|
+
|
31
|
+
elsif x >= 6 && x <= 8
|
32
|
+
return 2
|
33
|
+
|
34
|
+
else
|
35
|
+
return 3
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def ags(x)
|
42
|
+
if x < 6.7
|
43
|
+
return 1
|
44
|
+
|
45
|
+
elsif x >= 6.7 && x <= 10
|
46
|
+
return 2
|
47
|
+
|
48
|
+
else
|
49
|
+
return 3
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def huella_material(x)
|
56
|
+
if x < 2670
|
57
|
+
return 1
|
58
|
+
|
59
|
+
elsif x >= 2670 && x <= 4000
|
60
|
+
return 2
|
61
|
+
|
62
|
+
else
|
63
|
+
return 3
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def huella_carbono(x)
|
69
|
+
if x < 800
|
70
|
+
return 1
|
71
|
+
|
72
|
+
elsif x >= 800 && x <= 1200
|
73
|
+
return 2
|
74
|
+
|
75
|
+
else
|
76
|
+
return 3
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def huella_hidrica(x)
|
82
|
+
if x < 640
|
83
|
+
return 1
|
84
|
+
|
85
|
+
elsif x >= 640 && x <= 975
|
86
|
+
return 2
|
87
|
+
|
88
|
+
else
|
89
|
+
return 3
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def uso_terreno(x)
|
95
|
+
if x < 1.25
|
96
|
+
return 1
|
97
|
+
|
98
|
+
elsif x >= 1.25 && x <= 1.875
|
99
|
+
return 2
|
100
|
+
|
101
|
+
else
|
102
|
+
return 3
|
103
|
+
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
data/lib/p6/list.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
Node = Struct.new(:value, :next, :prev)
|
2
|
+
|
3
|
+
#Una lista de nodos doblemente enlazada
|
4
|
+
class List
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
attr_accessor :size, :head, :tail
|
8
|
+
|
9
|
+
#Constructor de la clase Lista
|
10
|
+
def initialize()
|
11
|
+
@size = 0
|
12
|
+
@head = nil
|
13
|
+
@tail = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
#Inserta un alimento por la cola
|
17
|
+
def push(item)
|
18
|
+
item = Node.new(item, nil, nil)
|
19
|
+
if(empty)
|
20
|
+
@tail = item
|
21
|
+
item.next = nil
|
22
|
+
else
|
23
|
+
head.prev = item
|
24
|
+
item.next = @head
|
25
|
+
end
|
26
|
+
|
27
|
+
@head = item
|
28
|
+
item.prev = nil
|
29
|
+
@size += 1
|
30
|
+
end
|
31
|
+
|
32
|
+
#Inserta un elemento por la cabeza
|
33
|
+
def insert(item)
|
34
|
+
item = Node.new(item, nil, nil)
|
35
|
+
if(empty)
|
36
|
+
@head = item
|
37
|
+
item.prev = nil
|
38
|
+
else
|
39
|
+
@tail.next = item
|
40
|
+
item.prev = @tail
|
41
|
+
end
|
42
|
+
|
43
|
+
@tail = item
|
44
|
+
item.next = nil
|
45
|
+
@size += 1
|
46
|
+
end
|
47
|
+
|
48
|
+
#Inserta un vector de elementos
|
49
|
+
def insert_many(array)
|
50
|
+
array.each do |item|
|
51
|
+
item = Node.new(item,nil,nil)
|
52
|
+
if(empty)
|
53
|
+
@head = item
|
54
|
+
item.prev = nil
|
55
|
+
else
|
56
|
+
@tail.next = item
|
57
|
+
item.prev = @tail
|
58
|
+
end
|
59
|
+
|
60
|
+
@tail = item
|
61
|
+
item.next = nil
|
62
|
+
@size += 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#Elimina el elemento de la cabeza
|
67
|
+
def pop_head()
|
68
|
+
if(empty)
|
69
|
+
puts "Lista vacía"
|
70
|
+
else
|
71
|
+
aux = @head
|
72
|
+
@head.next.prev = nil
|
73
|
+
@head = @head.next
|
74
|
+
@size -= 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#Elimina el elemento de la cola
|
79
|
+
def pop_tail()
|
80
|
+
if(empty)
|
81
|
+
puts "Lista vacía"
|
82
|
+
else
|
83
|
+
aux = @tail
|
84
|
+
@tail.prev.next = nil
|
85
|
+
@tail = @tail.prev
|
86
|
+
@size -= 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#Devuelve vacío si la lista está vacía
|
91
|
+
def empty()
|
92
|
+
if(@size == 0)
|
93
|
+
return true
|
94
|
+
else
|
95
|
+
return false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
#Método each
|
100
|
+
def each
|
101
|
+
puntero = @head
|
102
|
+
while(puntero != nil)
|
103
|
+
yield puntero.value
|
104
|
+
puntero = puntero.next
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def [](i)
|
109
|
+
if i.is_a?Integer
|
110
|
+
if i == 0
|
111
|
+
return @head.value
|
112
|
+
elsif i == (@size - 1)
|
113
|
+
return @tail.value
|
114
|
+
elsif i < @size - 1 && i > 0
|
115
|
+
puntero = @head
|
116
|
+
i.times{puntero = puntero.next}
|
117
|
+
return puntero.value
|
118
|
+
else
|
119
|
+
return nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_s
|
125
|
+
nodo = @head
|
126
|
+
cadena =""
|
127
|
+
while (nodo != nil)
|
128
|
+
cadena =cadena + nodo.value.to_s
|
129
|
+
nodo = nodo.next
|
130
|
+
end
|
131
|
+
return cadena
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
data/lib/p6/menu.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Clase menu que almacena un vector de platos y un vector de precios
|
2
|
+
class Menu
|
3
|
+
attr_accessor :nombre_, :platos_, :precios_
|
4
|
+
# Constructor de la clase menu
|
5
|
+
def initialize(nombre, &block)
|
6
|
+
@nombre_ = nombre
|
7
|
+
@platos_ = []
|
8
|
+
@precios_ = []
|
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 plato(options={})
|
20
|
+
@platos_ << options[:plato]
|
21
|
+
@precios_ << options[:precio]
|
22
|
+
end
|
23
|
+
|
24
|
+
def precioTotal
|
25
|
+
precios_.collect{|x| x}.reduce(:+)
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
output = "#{@nombre_}"
|
30
|
+
output << " = #{precioTotal}€\n"
|
31
|
+
output << "Contiene: \n"
|
32
|
+
@platos_.zip(@precios_).collect{|x,y|
|
33
|
+
output << "#{x} = #{y}€\n"
|
34
|
+
}
|
35
|
+
return output
|
36
|
+
end
|
37
|
+
end
|
data/lib/p6/plato.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
#La clase plato_i almacena dos listas: alimentos y pesos
|
2
|
+
class Plato_i
|
3
|
+
include Comparable
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
attr_accessor :nombre_, :alimentos_, :peso_
|
7
|
+
|
8
|
+
#Constructor de la clase Plato_i
|
9
|
+
def initialize(string, alimentos, peso)
|
10
|
+
@nombre_ = string
|
11
|
+
@alimentos_ = List.new
|
12
|
+
@peso_ = List.new
|
13
|
+
@alimentos_.insert_many(alimentos)
|
14
|
+
@peso_.insert_many(peso)
|
15
|
+
end
|
16
|
+
|
17
|
+
#Porcentaje de proteinas
|
18
|
+
def porc_proteinas
|
19
|
+
total_prot = 0
|
20
|
+
total_macro = 0
|
21
|
+
|
22
|
+
total_prot = @alimentos_.zip(peso_).collect{|alimento, peso|
|
23
|
+
(peso * alimento.proteinas_) / 100
|
24
|
+
}.reduce(:+)
|
25
|
+
|
26
|
+
total_macro = @alimentos_.zip(peso_).collect{|alimento, peso|
|
27
|
+
(peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100
|
28
|
+
}.reduce(:+)
|
29
|
+
|
30
|
+
return (total_prot / total_macro) * 100
|
31
|
+
end
|
32
|
+
|
33
|
+
#Porcentaje de carbohidratos
|
34
|
+
def porc_carbo
|
35
|
+
total_carb = 0
|
36
|
+
total_macro = 0
|
37
|
+
|
38
|
+
@alimentos_.zip(peso_).collect{|alimento, peso|
|
39
|
+
total_carb += (peso * alimento.carbo_) / 100
|
40
|
+
total_macro += (peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100
|
41
|
+
}
|
42
|
+
|
43
|
+
return (total_carb / total_macro) * 100
|
44
|
+
end
|
45
|
+
|
46
|
+
#Porcentaje de lipidos
|
47
|
+
def porc_lipidos
|
48
|
+
total_lipidos = 0
|
49
|
+
total_macro = 0
|
50
|
+
|
51
|
+
@alimentos_.zip(peso_).collect{|alimento, peso|
|
52
|
+
total_lipidos += (peso * alimento.lipidos_) / 100
|
53
|
+
total_macro += (peso * alimento.carbo_) / 100 + (peso * alimento.proteinas_) / 100 + (peso * alimento.lipidos_) / 100
|
54
|
+
}
|
55
|
+
|
56
|
+
return (total_lipidos / total_macro) * 100
|
57
|
+
end
|
58
|
+
|
59
|
+
#Valor calórico total
|
60
|
+
def vct
|
61
|
+
total = 0
|
62
|
+
total = alimentos_.zip(peso_).collect{| alimento, peso |
|
63
|
+
(alimento.calorias * peso) / 100
|
64
|
+
}.reduce(:+)
|
65
|
+
|
66
|
+
return total
|
67
|
+
end
|
68
|
+
|
69
|
+
#Metodo comparable
|
70
|
+
def <=>(other)
|
71
|
+
vct <=> other.vct
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
#Hereda de la clase Plato_i y añade la emisión de gases de efecto invernadero y el uso de terreno
|
77
|
+
class Plato < Plato_i
|
78
|
+
include Comparable
|
79
|
+
|
80
|
+
attr_accessor :emision_, :terreno_
|
81
|
+
|
82
|
+
#Constructor clase Plato
|
83
|
+
def initalize(string, alimentos, peso)
|
84
|
+
super(string, alimentos, peso)
|
85
|
+
@emision_ = emision_total
|
86
|
+
@terreno_ = terreno_total
|
87
|
+
end
|
88
|
+
|
89
|
+
#Emision de gases de efecto invernadero
|
90
|
+
def emision_total
|
91
|
+
total = 0
|
92
|
+
|
93
|
+
total = @alimentos_.zip(peso_).collect{|alimento, peso|
|
94
|
+
(peso * alimento.emision_) / 100
|
95
|
+
}.reduce(:+)
|
96
|
+
|
97
|
+
return total
|
98
|
+
end
|
99
|
+
|
100
|
+
#Uso de terreno total en m2
|
101
|
+
def terreno_total
|
102
|
+
total = 0
|
103
|
+
|
104
|
+
total = @alimentos_.zip(peso_).collect{|alimento, peso|
|
105
|
+
(peso * alimento.terreno_) / 100
|
106
|
+
}.reduce(:+)
|
107
|
+
|
108
|
+
return total
|
109
|
+
end
|
110
|
+
|
111
|
+
#Devuelve el impacto ambiental
|
112
|
+
def impacto
|
113
|
+
return emision_ + terreno_
|
114
|
+
end
|
115
|
+
|
116
|
+
#Devuelve el índice de energía
|
117
|
+
def energia(x)
|
118
|
+
if x < 670
|
119
|
+
return 1
|
120
|
+
|
121
|
+
elsif x >= 670 && x<= 830
|
122
|
+
return 2
|
123
|
+
|
124
|
+
else
|
125
|
+
return 3
|
126
|
+
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
#Devuelve el índice de huella de carbono
|
131
|
+
def huella_carbono(x)
|
132
|
+
if x < 800
|
133
|
+
return 1
|
134
|
+
|
135
|
+
elsif x >= 800 && x <= 1200
|
136
|
+
return 2
|
137
|
+
|
138
|
+
else
|
139
|
+
return 3
|
140
|
+
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
#Devuelve la huella nutricional
|
145
|
+
def huella_nutricional
|
146
|
+
return (energia(vct) + huella_carbono(emision_total)) / 2
|
147
|
+
end
|
148
|
+
|
149
|
+
#Módulo comparable
|
150
|
+
def <=>(other)
|
151
|
+
huella_nutricional <=> other.huella_nutricional
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
data/lib/p6/plato_dsl.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Clase plato para que funcione con DSL
|
2
|
+
class Plato_dsl < Plato
|
3
|
+
include Comparable
|
4
|
+
|
5
|
+
# Constructor de la clase Plato_dsl
|
6
|
+
def initialize(string, &block)
|
7
|
+
# Nombre del plato
|
8
|
+
@nombre_ = string
|
9
|
+
@alimentos_ = List.new
|
10
|
+
@peso_ = List.new
|
11
|
+
|
12
|
+
if block_given?
|
13
|
+
if block.arity == 1
|
14
|
+
yield self
|
15
|
+
else
|
16
|
+
instance_eval(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def alimento(options={})
|
22
|
+
aux = Alimento.new(options[:descripcion],options[:proteinas],options[:hidratos],options[:lipidos],options[:emision],options[:terreno])
|
23
|
+
@alimentos_.insert(aux)
|
24
|
+
@peso_.insert(options[:peso])
|
25
|
+
end
|
26
|
+
|
27
|
+
def proteinas
|
28
|
+
@alimentos_.collect{|alimento| alimento.proteinas_}.reduce(:+)
|
29
|
+
end
|
30
|
+
|
31
|
+
def hidratos
|
32
|
+
@alimentos_.collect{|alimento| alimento.carbo_}.reduce(:+)
|
33
|
+
end
|
34
|
+
|
35
|
+
def lipidos
|
36
|
+
@alimentos_.collect{|alimento| alimento.lipidos_}.reduce(:+)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
output = "Nombre: #{@nombre_} | C02: #{emision_total} | Terreno: #{terreno_total} | Kcal: #{vct.round(2)}\n"
|
41
|
+
return output
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
data/lib/p6/version.rb
ADDED
data/p6.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "p6/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "p6"
|
7
|
+
spec.version = P6::VERSION
|
8
|
+
spec.authors = ["David Arteaga Sánchez"]
|
9
|
+
spec.email = ["alu0101039664@ull.edu.es"]
|
10
|
+
|
11
|
+
spec.summary = %q{P6 - Lenguajes y Paradigmal de Programación - ULL}
|
12
|
+
spec.description = %q{Información nutricional de alimentos}
|
13
|
+
spec.homepage = "https://github.com/davidas1798/LPP-P10"
|
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
|
+
end
|
data/pkg/p6-0.1.0.gem
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: p6
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Arteaga Sánchez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-09 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
|
+
description: Información nutricional de alimentos
|
98
|
+
email:
|
99
|
+
- alu0101039664@ull.edu.es
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".travis.yml"
|
105
|
+
- Gemfile
|
106
|
+
- Gemfile.lock
|
107
|
+
- Guardfile
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- lib/.p6.rb.swp
|
113
|
+
- lib/p6.rb
|
114
|
+
- lib/p6/alimento.rb
|
115
|
+
- lib/p6/indicadores.rb
|
116
|
+
- lib/p6/list.rb
|
117
|
+
- lib/p6/menu.rb
|
118
|
+
- lib/p6/plato.rb
|
119
|
+
- lib/p6/plato_dsl.rb
|
120
|
+
- lib/p6/version.rb
|
121
|
+
- p6.gemspec
|
122
|
+
- pkg/p6-0.1.0.gem
|
123
|
+
homepage: https://github.com/davidas1798/LPP-P10
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubygems_version: 3.0.6
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: P6 - Lenguajes y Paradigmal de Programación - ULL
|
145
|
+
test_files: []
|