dietary_dsl 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dietary_dsl/dsl/menu.rb +11 -19
- data/lib/dietary_dsl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7daff4360e86c5256697da8874d2355f82a182e
|
4
|
+
data.tar.gz: f0a650c9f0d59d03c8d4177d45ec42757b3c44d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16a91d13e5e85393f99ab918e6024404958f12c743ee424a51f7f12aa75d86b62d3f8387953376464ace06f87c3ce76cae3e224a20c907ccd6bf9be8366c3e09
|
7
|
+
data.tar.gz: 755260a6eee2bf49a3669eaeffcde869dff90cad0b721b7e8941a53b5e88dfe7426b1a3a16b3f0460315dcd0042f7eeda24fcfbf8b25989b05a4dd0d16be8fed
|
data/lib/dietary_dsl/dsl/menu.rb
CHANGED
@@ -5,14 +5,13 @@ require 'dietary_dsl/dsl/alimento'
|
|
5
5
|
module DietaryDsl
|
6
6
|
# Clase que representa un menú. Un menú se compone de distintos platos (entrantes, primeros platos, postres...)
|
7
7
|
class Menu
|
8
|
-
attr_reader :title
|
8
|
+
attr_reader :title
|
9
9
|
|
10
10
|
include Enumerable
|
11
11
|
|
12
12
|
def initialize(title, &block)
|
13
13
|
@title = title
|
14
14
|
@platos = []
|
15
|
-
@racion = nil
|
16
15
|
instance_eval(&block)
|
17
16
|
end
|
18
17
|
|
@@ -26,30 +25,23 @@ module DietaryDsl
|
|
26
25
|
|
27
26
|
def plato(datos, options = {})
|
28
27
|
return plato_single(datos) if datos.is_a?(Hash)
|
29
|
-
@platos = @platos.push datos
|
30
|
-
@racion = options[:racion]
|
28
|
+
@platos = @platos.push(plato: datos, racion: options[:racion])
|
31
29
|
end
|
32
30
|
|
33
31
|
def plato_single(datos)
|
34
|
-
@platos = @platos.push(DietaryDsl::Plato.new(datos[:food]) { alimento(datos) })
|
32
|
+
@platos = @platos.push(plato: DietaryDsl::Plato.new(datos[:food]) { alimento(datos) })
|
35
33
|
end
|
36
34
|
|
37
35
|
def kcal
|
38
|
-
|
39
|
-
|
36
|
+
@platos.inject(0) do |sum, plato_y_cantidad|
|
37
|
+
plato = plato_y_cantidad[:plato]
|
38
|
+
racion = plato_y_cantidad[:racion]
|
39
|
+
if racion.nil?
|
40
|
+
sum + plato.kcal
|
41
|
+
else
|
42
|
+
sum + ((racion.to.g * plato.kcal) / plato.masa.to.g)
|
43
|
+
end
|
40
44
|
end
|
41
|
-
return racionar(kilocalorias) unless @racion.nil?
|
42
|
-
kilocalorias
|
43
|
-
end
|
44
|
-
|
45
|
-
def masa
|
46
|
-
@platos.inject(0) do |sum, plato|
|
47
|
-
sum + plato.masa.to.g
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def racionar(kilocalorias)
|
52
|
-
(@racion.to.g * kilocalorias) / masa
|
53
45
|
end
|
54
46
|
end
|
55
47
|
end
|
data/lib/dietary_dsl/version.rb
CHANGED