eye-of-newt 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eye_of_newt/ingredient.rb +3 -2
- data/lib/eye_of_newt/parser.rb +120 -89
- data/lib/eye_of_newt/parser.y +10 -3
- data/lib/eye_of_newt/quantity.rb +4 -3
- data/lib/eye_of_newt/tokenizer.rb +15 -4
- data/lib/eye_of_newt/units.rb +16 -1
- data/lib/eye_of_newt/version.rb +1 -1
- data/test/examples.txt +8 -1
- data/test/eye_of_newt/quantity_test.rb +1 -0
- data/test/eye_of_newt_test.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93cc600dbd1c5f6a5e2e62f0f908110ae4e15647
|
4
|
+
data.tar.gz: 257935203d6f991a13faf85cca0c55b9334c7998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24cf9ba3437ce443288d47ddde41519a5c43544e2f84f1306b3b9fd472b740e9e7c64fef24ef7396a5dfd937abaa08683a80a7bb4132623d06426e598c390fea
|
7
|
+
data.tar.gz: 7c925794f3d1703e3028de2b2f5592fb11b8e893a36ae5b76f73f550dcf1faffc771b5378a1472bed2a07251a68a4970a1f621a1d7df6db0eadc1c2568142b8b
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module EyeOfNewt
|
2
2
|
class Ingredient
|
3
|
-
attr_accessor :amount, :unit, :name, :style, :note
|
3
|
+
attr_accessor :amount, :unit, :unit_modifier, :name, :style, :note
|
4
4
|
|
5
|
-
def initialize(amount: nil, unit: nil, name: nil, style: nil, note: nil)
|
5
|
+
def initialize(amount: nil, unit: nil, unit_modifier: nil, name: nil, style: nil, note: nil)
|
6
6
|
self.amount = amount
|
7
7
|
self.unit = unit
|
8
|
+
self.unit_modifier = unit_modifier
|
8
9
|
self.name = name
|
9
10
|
self.style = style
|
10
11
|
self.note = note
|
data/lib/eye_of_newt/parser.rb
CHANGED
@@ -37,94 +37,105 @@ module EyeOfNewt
|
|
37
37
|
##### State transition tables begin ###
|
38
38
|
|
39
39
|
racc_action_table = [
|
40
|
-
-
|
41
|
-
-
|
42
|
-
|
43
|
-
|
40
|
+
-39, 33, 14, 17, 16, 37, 15, 11, -39, 13,
|
41
|
+
-39, -39, 14, 16, 31, 29, 15, 20, 13, 14,
|
42
|
+
16, 16, 47, 15, 20, 24, 26, 25, 26, 25,
|
43
|
+
26, 35, 36, 25, 26, 44, 44, 18, 48, 49,
|
44
|
+
35, 50, 51, 26, 26, 54, 55 ]
|
44
45
|
|
45
46
|
racc_action_check = [
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
11, 8, 0, 0, 0, 18, 0, 0, 11, 0,
|
48
|
+
11, 11, 2, 5, 7, 5, 2, 2, 5, 12,
|
49
|
+
27, 6, 27, 12, 12, 3, 22, 3, 3, 19,
|
50
|
+
19, 17, 17, 21, 21, 25, 26, 1, 28, 30,
|
51
|
+
33, 35, 36, 38, 40, 45, 46 ]
|
50
52
|
|
51
53
|
racc_action_pointer = [
|
52
|
-
|
53
|
-
0,
|
54
|
-
|
55
|
-
|
56
|
-
nil,
|
54
|
+
0, 37, 10, 17, nil, 9, 17, 8, -2, nil,
|
55
|
+
nil, 0, 17, nil, nil, nil, nil, 18, 5, 19,
|
56
|
+
nil, 23, 15, nil, nil, 30, 31, 16, 32, nil,
|
57
|
+
33, nil, nil, 27, nil, 38, 39, nil, 32, nil,
|
58
|
+
33, nil, nil, nil, nil, 33, 40, nil, nil, nil,
|
59
|
+
nil, nil, nil, nil, nil, nil ]
|
57
60
|
|
58
61
|
racc_action_default = [
|
59
|
-
-
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
63
|
-
|
62
|
+
-45, -45, -45, -12, -13, -21, -45, -25, -26, -28,
|
63
|
+
-29, -30, -35, -36, -38, -40, -41, -42, -45, -8,
|
64
|
+
-39, -10, -11, -6, -31, -45, -45, -19, -17, -20,
|
65
|
+
-23, -24, -27, -45, -34, -45, -45, 56, -7, -2,
|
66
|
+
-9, -4, -5, -32, -37, -45, -15, -18, -16, -22,
|
67
|
+
-43, -44, -1, -3, -33, -14 ]
|
64
68
|
|
65
69
|
racc_goto_table = [
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
nil,
|
70
|
+
23, 7, 9, 6, 22, 5, 28, 30, 27, 3,
|
71
|
+
32, 19, 43, 45, 34, 21, 39, 8, 41, 42,
|
72
|
+
38, 2, 40, 10, 1, nil, nil, nil, 46, nil,
|
73
|
+
nil, nil, nil, nil, nil, 52, nil, 53 ]
|
70
74
|
|
71
75
|
racc_goto_check = [
|
72
|
-
5,
|
73
|
-
|
74
|
-
4,
|
75
|
-
nil, 5, nil, 5 ]
|
76
|
+
5, 10, 12, 9, 4, 8, 10, 10, 9, 3,
|
77
|
+
12, 3, 14, 14, 7, 6, 5, 11, 5, 5,
|
78
|
+
4, 2, 4, 13, 1, nil, nil, nil, 10, nil,
|
79
|
+
nil, nil, nil, nil, nil, 5, nil, 5 ]
|
76
80
|
|
77
81
|
racc_goto_pointer = [
|
78
|
-
nil,
|
79
|
-
|
82
|
+
nil, 24, 21, 9, 1, -3, 12, 2, 5, 3,
|
83
|
+
1, 17, 2, 23, -13, nil ]
|
80
84
|
|
81
85
|
racc_goto_default = [
|
82
86
|
nil, nil, nil, nil, nil, nil, nil, 4, nil, nil,
|
83
|
-
nil, nil, nil, nil,
|
87
|
+
nil, nil, nil, nil, nil, 12 ]
|
84
88
|
|
85
89
|
racc_reduce_table = [
|
86
90
|
0, 0, :racc_error,
|
87
|
-
4,
|
88
|
-
3,
|
89
|
-
4,
|
90
|
-
3,
|
91
|
-
3, 15, :_reduce_none,
|
92
|
-
2, 15, :_reduce_none,
|
93
|
-
3, 15, :_reduce_none,
|
94
|
-
2, 15, :_reduce_none,
|
95
|
-
3, 15, :_reduce_none,
|
96
|
-
2, 15, :_reduce_none,
|
97
|
-
2, 15, :_reduce_none,
|
98
|
-
1, 15, :_reduce_none,
|
99
|
-
1, 17, :_reduce_13,
|
91
|
+
4, 16, :_reduce_none,
|
92
|
+
3, 16, :_reduce_none,
|
93
|
+
4, 16, :_reduce_none,
|
94
|
+
3, 16, :_reduce_none,
|
100
95
|
3, 16, :_reduce_none,
|
101
96
|
2, 16, :_reduce_none,
|
97
|
+
3, 16, :_reduce_none,
|
98
|
+
2, 16, :_reduce_none,
|
99
|
+
3, 16, :_reduce_none,
|
102
100
|
2, 16, :_reduce_none,
|
103
|
-
1, 16, :_reduce_none,
|
104
101
|
2, 16, :_reduce_none,
|
105
102
|
1, 16, :_reduce_none,
|
106
|
-
1,
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
2,
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
1,
|
119
|
-
1,
|
120
|
-
|
121
|
-
1,
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
103
|
+
1, 18, :_reduce_13,
|
104
|
+
4, 17, :_reduce_none,
|
105
|
+
3, 17, :_reduce_none,
|
106
|
+
3, 17, :_reduce_none,
|
107
|
+
2, 17, :_reduce_none,
|
108
|
+
3, 17, :_reduce_none,
|
109
|
+
2, 17, :_reduce_none,
|
110
|
+
2, 17, :_reduce_none,
|
111
|
+
1, 17, :_reduce_none,
|
112
|
+
3, 17, :_reduce_none,
|
113
|
+
2, 17, :_reduce_none,
|
114
|
+
2, 17, :_reduce_none,
|
115
|
+
1, 17, :_reduce_none,
|
116
|
+
1, 23, :_reduce_26,
|
117
|
+
2, 23, :_reduce_27,
|
118
|
+
1, 23, :_reduce_28,
|
119
|
+
1, 23, :_reduce_29,
|
120
|
+
1, 23, :_reduce_30,
|
121
|
+
1, 21, :_reduce_31,
|
122
|
+
2, 19, :_reduce_32,
|
123
|
+
3, 20, :_reduce_33,
|
124
|
+
2, 22, :_reduce_34,
|
125
|
+
1, 22, :_reduce_none,
|
126
|
+
1, 24, :_reduce_36,
|
127
|
+
1, 29, :_reduce_none,
|
128
|
+
1, 30, :_reduce_none,
|
129
|
+
1, 30, :_reduce_none,
|
130
|
+
1, 30, :_reduce_none,
|
131
|
+
1, 25, :_reduce_41,
|
132
|
+
1, 26, :_reduce_42,
|
133
|
+
3, 27, :_reduce_43,
|
134
|
+
3, 28, :_reduce_44 ]
|
135
|
+
|
136
|
+
racc_reduce_n = 45
|
137
|
+
|
138
|
+
racc_shift_n = 56
|
128
139
|
|
129
140
|
racc_token_table = {
|
130
141
|
false => 0,
|
@@ -136,13 +147,14 @@ racc_token_table = {
|
|
136
147
|
:OF => 6,
|
137
148
|
:A => 7,
|
138
149
|
:TO_TASTE => 8,
|
139
|
-
|
140
|
-
"
|
141
|
-
"
|
142
|
-
"
|
143
|
-
"
|
150
|
+
:UNIT_MODIFIER => 9,
|
151
|
+
"," => 10,
|
152
|
+
"(" => 11,
|
153
|
+
")" => 12,
|
154
|
+
"/" => 13,
|
155
|
+
"." => 14 }
|
144
156
|
|
145
|
-
racc_nt_base =
|
157
|
+
racc_nt_base = 15
|
146
158
|
|
147
159
|
racc_use_result_var = true
|
148
160
|
|
@@ -172,6 +184,7 @@ Racc_token_to_s_table = [
|
|
172
184
|
"OF",
|
173
185
|
"A",
|
174
186
|
"TO_TASTE",
|
187
|
+
"UNIT_MODIFIER",
|
175
188
|
"\",\"",
|
176
189
|
"\"(\"",
|
177
190
|
"\")\"",
|
@@ -186,6 +199,7 @@ Racc_token_to_s_table = [
|
|
186
199
|
"to_taste",
|
187
200
|
"words",
|
188
201
|
"amount",
|
202
|
+
"unit_modifier",
|
189
203
|
"unit",
|
190
204
|
"number",
|
191
205
|
"fraction",
|
@@ -240,77 +254,94 @@ end
|
|
240
254
|
|
241
255
|
# reduce 19 omitted
|
242
256
|
|
243
|
-
|
257
|
+
# reduce 20 omitted
|
258
|
+
|
259
|
+
# reduce 21 omitted
|
260
|
+
|
261
|
+
# reduce 22 omitted
|
262
|
+
|
263
|
+
# reduce 23 omitted
|
264
|
+
|
265
|
+
# reduce 24 omitted
|
266
|
+
|
267
|
+
# reduce 25 omitted
|
268
|
+
|
269
|
+
def _reduce_26(val, _values, result)
|
244
270
|
@ingredient.amount = result
|
245
271
|
result
|
246
272
|
end
|
247
273
|
|
248
|
-
def
|
274
|
+
def _reduce_27(val, _values, result)
|
249
275
|
@ingredient.amount = val[0] + val[1]
|
250
276
|
result
|
251
277
|
end
|
252
278
|
|
253
|
-
def
|
279
|
+
def _reduce_28(val, _values, result)
|
254
280
|
@ingredient.amount = result
|
255
281
|
result
|
256
282
|
end
|
257
283
|
|
258
|
-
def
|
284
|
+
def _reduce_29(val, _values, result)
|
259
285
|
@ingredient.amount = result
|
260
286
|
result
|
261
287
|
end
|
262
288
|
|
263
|
-
def
|
289
|
+
def _reduce_30(val, _values, result)
|
264
290
|
@ingredient.amount = 1
|
265
291
|
result
|
266
292
|
end
|
267
293
|
|
268
|
-
def
|
294
|
+
def _reduce_31(val, _values, result)
|
269
295
|
@ingredient.unit = to_unit(result)
|
270
296
|
result
|
271
297
|
end
|
272
298
|
|
273
|
-
def
|
299
|
+
def _reduce_32(val, _values, result)
|
274
300
|
@ingredient.style = val[1]
|
275
301
|
result
|
276
302
|
end
|
277
303
|
|
278
|
-
def
|
304
|
+
def _reduce_33(val, _values, result)
|
279
305
|
@ingredient.note = val[1]
|
280
306
|
result
|
281
307
|
end
|
282
308
|
|
283
|
-
def
|
309
|
+
def _reduce_34(val, _values, result)
|
284
310
|
result = val.join(' ')
|
285
311
|
result
|
286
312
|
end
|
287
313
|
|
288
|
-
# reduce
|
314
|
+
# reduce 35 omitted
|
289
315
|
|
290
|
-
|
316
|
+
def _reduce_36(val, _values, result)
|
317
|
+
@ingredient.unit_modifier = val[0]
|
318
|
+
result
|
319
|
+
end
|
291
320
|
|
292
|
-
# reduce
|
321
|
+
# reduce 37 omitted
|
293
322
|
|
294
|
-
# reduce
|
323
|
+
# reduce 38 omitted
|
295
324
|
|
296
|
-
# reduce
|
325
|
+
# reduce 39 omitted
|
297
326
|
|
298
|
-
|
327
|
+
# reduce 40 omitted
|
328
|
+
|
329
|
+
def _reduce_41(val, _values, result)
|
299
330
|
@ingredient.unit = to_unit(result)
|
300
331
|
result
|
301
332
|
end
|
302
333
|
|
303
|
-
def
|
334
|
+
def _reduce_42(val, _values, result)
|
304
335
|
result = val[0].to_i
|
305
336
|
result
|
306
337
|
end
|
307
338
|
|
308
|
-
def
|
339
|
+
def _reduce_43(val, _values, result)
|
309
340
|
result = val[0].to_f / val[2].to_f
|
310
341
|
result
|
311
342
|
end
|
312
343
|
|
313
|
-
def
|
344
|
+
def _reduce_44(val, _values, result)
|
314
345
|
result = val.join.to_f
|
315
346
|
result
|
316
347
|
end
|
data/lib/eye_of_newt/parser.y
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class EyeOfNewt::Parser
|
2
|
-
token WORD NUMBER UNIT TEXT OF A TO_TASTE
|
2
|
+
token WORD NUMBER UNIT TEXT OF A TO_TASTE UNIT_MODIFIER
|
3
3
|
rule
|
4
4
|
ingredient
|
5
5
|
: quantity ingredient_name style note
|
@@ -19,10 +19,16 @@ rule
|
|
19
19
|
: words { @ingredient.name = result }
|
20
20
|
;
|
21
21
|
quantity
|
22
|
-
: amount unit OF
|
22
|
+
: amount unit_modifier unit OF
|
23
|
+
| amount unit_modifier unit
|
24
|
+
| amount unit OF
|
23
25
|
| amount unit
|
26
|
+
| amount unit_modifier OF
|
27
|
+
| amount unit_modifier
|
24
28
|
| amount OF
|
25
29
|
| amount
|
30
|
+
| unit_modifier unit OF
|
31
|
+
| unit_modifier unit
|
26
32
|
| unit OF
|
27
33
|
| unit
|
28
34
|
;
|
@@ -40,7 +46,8 @@ rule
|
|
40
46
|
: word words { result = val.join(' ') }
|
41
47
|
| word
|
42
48
|
;
|
43
|
-
|
49
|
+
unit_modifier : UNIT_MODIFIER { @ingredient.unit_modifier = val[0] } ;
|
50
|
+
text : TEXT ;
|
44
51
|
word : WORD | A | OF ;
|
45
52
|
unit : UNIT { @ingredient.unit = to_unit(result) } ;
|
46
53
|
number : NUMBER { result = val[0].to_i } ;
|
data/lib/eye_of_newt/quantity.rb
CHANGED
@@ -5,12 +5,13 @@ module EyeOfNewt
|
|
5
5
|
DELTA = 0.01
|
6
6
|
SIGNIFICANT_DIGITS = 3
|
7
7
|
|
8
|
-
attr_reader :amount, :unit, :units
|
8
|
+
attr_reader :amount, :unit, :modifier, :units
|
9
9
|
|
10
|
-
def initialize(amount, unit, units: EyeOfNewt.units)
|
10
|
+
def initialize(amount, unit, modifier: nil, units: EyeOfNewt.units)
|
11
11
|
@amount = amount
|
12
12
|
@units = units
|
13
13
|
@unit = units[unit]
|
14
|
+
@modifier = modifier
|
14
15
|
end
|
15
16
|
|
16
17
|
def in(new_unit)
|
@@ -19,7 +20,7 @@ module EyeOfNewt
|
|
19
20
|
end
|
20
21
|
|
21
22
|
def to_s
|
22
|
-
[fraction_str, unit_str].compact.join(' ')
|
23
|
+
[fraction_str, modifier, unit_str].compact.join(' ')
|
23
24
|
end
|
24
25
|
alias :inspect :to_s
|
25
26
|
|
@@ -13,11 +13,12 @@ module EyeOfNewt
|
|
13
13
|
TO_TASTE = /to taste/
|
14
14
|
COMMA = ','
|
15
15
|
|
16
|
-
attr_reader :string, :units
|
16
|
+
attr_reader :string, :units, :unit_modifiers
|
17
17
|
|
18
|
-
def initialize(string, units: EyeOfNewt.units.all)
|
18
|
+
def initialize(string, units: EyeOfNewt.units.all, unit_modifiers: EyeOfNewt.units.unit_modifiers)
|
19
19
|
@string = string
|
20
20
|
@units = units
|
21
|
+
@unit_modifiers = unit_modifiers
|
21
22
|
@ss = StringScanner.new(string)
|
22
23
|
end
|
23
24
|
|
@@ -39,6 +40,8 @@ module EyeOfNewt
|
|
39
40
|
[:TO_TASTE, text]
|
40
41
|
when text = @ss.scan(/#{unit_matcher}\b/)
|
41
42
|
[:UNIT, text]
|
43
|
+
when text = @ss.scan(/#{unit_modifier}\b/)
|
44
|
+
[:UNIT_MODIFIER, text]
|
42
45
|
when text = @ss.scan(/#{WORD}\b/)
|
43
46
|
[:WORD, text]
|
44
47
|
else
|
@@ -50,9 +53,17 @@ module EyeOfNewt
|
|
50
53
|
|
51
54
|
private
|
52
55
|
|
56
|
+
def unit_modifier
|
57
|
+
@unit_modifier_matcher ||= match_any(unit_modifiers)
|
58
|
+
end
|
59
|
+
|
53
60
|
def unit_matcher
|
54
|
-
@unit_matcher ||=
|
55
|
-
|
61
|
+
@unit_matcher ||= match_any(units)
|
62
|
+
end
|
63
|
+
|
64
|
+
def match_any(elements)
|
65
|
+
if elements.any?
|
66
|
+
r = elements
|
56
67
|
.sort
|
57
68
|
.reverse
|
58
69
|
.map{|u|Regexp.escape(u)}
|
data/lib/eye_of_newt/units.rb
CHANGED
@@ -2,11 +2,12 @@ require 'active_support/core_ext/hash/deep_merge'
|
|
2
2
|
|
3
3
|
module EyeOfNewt
|
4
4
|
class Units
|
5
|
-
attr_reader :units, :conversions, :default
|
5
|
+
attr_reader :units, :conversions, :unit_modifiers, :default
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@units = {}
|
9
9
|
@conversions = Hash.new { |h, k| h[k] = {} }
|
10
|
+
@unit_modifiers = []
|
10
11
|
@default = nil
|
11
12
|
@unquantified = []
|
12
13
|
end
|
@@ -39,6 +40,10 @@ module EyeOfNewt
|
|
39
40
|
conversions.deep_merge!(new_conversion)
|
40
41
|
end
|
41
42
|
|
43
|
+
def add_unit_modifier(modifier)
|
44
|
+
unit_modifiers << modifier
|
45
|
+
end
|
46
|
+
|
42
47
|
def conversion_rate(from, to)
|
43
48
|
f = self[from]
|
44
49
|
t = self[to]
|
@@ -84,6 +89,16 @@ module EyeOfNewt
|
|
84
89
|
add_unit "dashes", "dash"
|
85
90
|
add_unit "touches", "touch"
|
86
91
|
add_unit "handfuls", "handful"
|
92
|
+
add_unit "cloves", "clove"
|
93
|
+
add_unit "bunches", "bunch"
|
94
|
+
add_unit "sprigs", "sprig"
|
95
|
+
|
96
|
+
add_unit_modifier "big"
|
97
|
+
add_unit_modifier "large"
|
98
|
+
add_unit_modifier "medium"
|
99
|
+
add_unit_modifier "small"
|
100
|
+
add_unit_modifier "heaping"
|
101
|
+
add_unit_modifier "level"
|
87
102
|
|
88
103
|
# unquantified units
|
89
104
|
add_unit "to taste", unquantified: true
|
data/lib/eye_of_newt/version.rb
CHANGED
data/test/examples.txt
CHANGED
@@ -13,10 +13,17 @@ tomatoes | tomatoes | 1 | units
|
|
13
13
|
1 teaspoon of cream of tartar | cream of tartar | 1 | tsp
|
14
14
|
a pinch of salt | salt | 1 | pinches
|
15
15
|
pinch of salt | salt | 1 | pinches
|
16
|
-
4 large leeks, trimmed & thinly sliced |
|
16
|
+
4 large leeks, trimmed & thinly sliced | leeks | 4 | units | trimmed & thinly sliced | | large
|
17
17
|
3 pounds potatoes, washed and cut into 2-inch chunks | potatoes | 3 | lb | washed and cut into 2-inch chunks
|
18
18
|
salt to taste | salt | 1 | to taste
|
19
19
|
an apple, sliced (I like Fuji, but any variety will do) | apple | 1 | units | sliced | I like Fuji, but any variety will do
|
20
|
+
1 sprig of rosemary | rosemary | 1 | sprigs
|
21
|
+
3 cloves of garlic | garlic | 3 | cloves
|
22
|
+
2 bunches of corriander | corriander | 2 | bunches
|
23
|
+
2 big pinches of red pepper flakes | red pepper flakes | 2 | pinches | | | big
|
24
|
+
big pinch of salt | salt | 1 | pinches | | | big
|
25
|
+
heaping tablespoon of sugar | sugar | 1 | tbsp | | | heaping
|
26
|
+
1 large yellow onion | yellow onion | 1 | units | | | large
|
20
27
|
#4-5 handfuls of spinach, very roughly chopped | spinach | 4-5 | handfuls | very roughly chopped
|
21
28
|
|
22
29
|
|
@@ -25,6 +25,7 @@ class EyeOfNewt::QuantityTest < ActiveSupport::TestCase
|
|
25
25
|
assert_equal "1000 g", EyeOfNewt::Quantity.new(1001, "grams").to_s
|
26
26
|
assert_equal "1/3 g", EyeOfNewt::Quantity.new(0.33, "grams").to_s
|
27
27
|
assert_equal "to taste", EyeOfNewt::Quantity.new(1, "to taste").to_s
|
28
|
+
assert_equal "1 heaping tsp", EyeOfNewt::Quantity.new(1, "teaspoon", modifier: "heaping").to_s
|
28
29
|
end
|
29
30
|
|
30
31
|
end
|
data/test/eye_of_newt_test.rb
CHANGED
@@ -16,7 +16,8 @@ class EyeOfNewtTest < ActiveSupport::TestCase
|
|
16
16
|
unit = tokens.shift.presence
|
17
17
|
style = tokens.shift.presence
|
18
18
|
note = tokens.shift.presence
|
19
|
-
|
19
|
+
unit_modifier = tokens.shift.presence
|
20
|
+
expected = [name, amount, unit, style, note, unit_modifier]
|
20
21
|
[line, expected]
|
21
22
|
}.compact
|
22
23
|
end
|
@@ -25,12 +26,13 @@ class EyeOfNewtTest < ActiveSupport::TestCase
|
|
25
26
|
examples.each do |line, expected|
|
26
27
|
test "parses #{line} correctly" do
|
27
28
|
ingr = EyeOfNewt.parse(line)
|
28
|
-
name, amount, unit, style, note = *expected
|
29
|
+
name, amount, unit, style, note, unit_modifier = *expected
|
29
30
|
assert_equal name, ingr.name, %Q{incorrect name}
|
30
31
|
assert_equal amount, ingr.amount, %Q{incorrect amount}
|
31
32
|
assert_equal unit, ingr.unit, %Q{incorrect unit}
|
32
33
|
assert_equal style, ingr.style, %Q{incorrect style}
|
33
34
|
assert_equal note, ingr.note, %Q{incorrect note}
|
35
|
+
assert_equal unit_modifier, ingr.unit_modifier, %Q{incorrect unit modifier}
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eye-of-newt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter McCracken
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|