dietary_dsl 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7023482dea93f772dec13950d0e46d6aef4a093
4
- data.tar.gz: 8852fd20bdefbb42bb306c1ea1cee6e127558a0f
3
+ metadata.gz: f57eda75d75d970e6bdbdccff368bc9898837f0d
4
+ data.tar.gz: 3b5f5c21628fdcd6bc936bdfced6a88164432ad6
5
5
  SHA512:
6
- metadata.gz: 984c088bba7bf45aa3e3c0ec5ce1f9210e77e7fc36128d61749ae144e221e28142c9795e3892356423e61fd28215bc195ee4bbbaf417896c6d67099c632eaaec
7
- data.tar.gz: 9ee29715cf8ed7929ad1d76c4898ff7d1c0f95f2c87a384c13934348c7f77596a7bcdbf516fe574ac1f1232fb7f2d2fbd57e5674fa1abeabf2be53f8299a2564
6
+ metadata.gz: 26296bfdff40667c3bfae669c164c53c2efcd663afb6713fdc7fb7ddd4630b4edea22208070cc5f9543ece75ca9ea6ecbd1f75fd69ba256304e9600e0c73b538
7
+ data.tar.gz: 54a05961f6a61e9b33334a7b3019b90ddf8432d05aff902eddcf2975a7a3e358aab4ba461857dc75b30f8cde3ce5838d6e22d477b35e8639980d60668c1f3aa2
@@ -102,6 +102,7 @@ module DietaryDsl
102
102
  end
103
103
 
104
104
  def [](key)
105
+ return @data[key].delete(',') if key === :nombre or key === :name
105
106
  @data[key]
106
107
  end
107
108
 
@@ -67,5 +67,9 @@ module DietaryDsl
67
67
  #{alimentos}
68
68
  OUTPUT
69
69
  end
70
+
71
+ def single?
72
+ @alimentos.length == 1
73
+ end
70
74
  end
71
75
  end
@@ -7,6 +7,8 @@ module DietaryDsl
7
7
  class Masa < Measure
8
8
  def initialize(en_gramos)
9
9
  super(en_gramos)
10
+ @small_postfix = "g"
11
+ @big_postfix = "kg"
10
12
  end
11
13
 
12
14
  # Métodos de clase para instanciarlo
@@ -19,6 +21,16 @@ module DietaryDsl
19
21
  DietaryDsl::Masa.new(number)
20
22
  end
21
23
 
24
+ # Métodos para heredar
25
+
26
+ def big
27
+ kg
28
+ end
29
+
30
+ def small
31
+ g
32
+ end
33
+
22
34
  # Métodos de conversión
23
35
 
24
36
  def g
@@ -12,5 +12,17 @@ module DietaryDsl
12
12
  def to
13
13
  self
14
14
  end
15
+
16
+ def to_s
17
+ if @cantidad < 1000
18
+ "#{small.to_i}#{@small_postfix}"
19
+ else
20
+ if big == big.to_i
21
+ "#{big.to_i}#{@big_postfix}"
22
+ else
23
+ "#{big.round(1)}#{@big_postfix}"
24
+ end
25
+ end
26
+ end
15
27
  end
16
28
  end
@@ -5,53 +5,65 @@ require 'dietary_dsl/measures/measure'
5
5
  module DietaryDsl
6
6
  # Esta clase nos permite representar unidades de volumen, como litros o cucharadas.
7
7
  class Volumen < Measure
8
- def initialize(en_litros)
9
- super(en_litros)
8
+ def initialize(en_ml)
9
+ super(en_ml)
10
10
  @cantidad = cantidad.to_f
11
+ @small_postfix = "ml"
12
+ @big_postfix = "L"
11
13
  end
12
14
 
13
15
  def self.l(number)
14
- Volumen.new(number)
16
+ Volumen.new(number * 1000.0)
15
17
  end
16
18
 
17
19
  def self.ml(number)
18
- Volumen.new(number / 1000.0)
20
+ Volumen.new(number)
19
21
  end
20
22
 
21
23
  def self.cm3(number)
22
- Volumen.new(number / 1000.0)
24
+ Volumen.new(number)
23
25
  end
24
26
 
25
27
  def self.cucharada(number)
26
- Volumen.new((number * 3.0) / 200.0)
28
+ Volumen.new(number * 15.0)
27
29
  end
28
30
 
29
31
  def self.vaso(number)
30
- Volumen.new(number / 5.0)
32
+ Volumen.new(number * 200)
31
33
  end
32
34
 
33
35
  def self.chorrito(number)
34
- Volumen.new(number / 16.0)
36
+ Volumen.new(number * 62.5)
37
+ end
38
+
39
+ # Métodos para heredar
40
+
41
+ def big
42
+ l
43
+ end
44
+
45
+ def small
46
+ ml
35
47
  end
36
48
 
37
49
  def l
38
- @cantidad
50
+ @cantidad / 1000
39
51
  end
40
52
 
41
53
  def litros
42
- @cantidad
54
+ l
43
55
  end
44
56
 
45
57
  def cm3
46
- @cantidad * 1000
58
+ @cantidad
47
59
  end
48
60
 
49
- def cucharada
50
- @cantidad * 50
61
+ def ml
62
+ @cantidad
51
63
  end
52
64
 
53
65
  def cucharadas
54
- cucharada
66
+ @cantidad / 20
55
67
  end
56
68
 
57
69
  def coerce(arg)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DietaryDsl
4
- VERSION = '0.3.1'
4
+ VERSION = '0.4.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dietary_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Ramos