eye-of-newt 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9030bbeaacdf2439015bac1867eb22af36900b96
4
- data.tar.gz: 50f0e11a38c624b45d698188f85f78d10fd79d02
3
+ metadata.gz: d3877e1bb1d601343963f3e7d402565f11c725ff
4
+ data.tar.gz: c6b868ec895b6bf17e0673d55d5c2ff23282dd27
5
5
  SHA512:
6
- metadata.gz: 25eab353b59c33bfc79143032111833f2917941f715f4e85c60680e46b44ce71ac06144346d8e8a2c5bbf7415fe684e54560bbcbe2eee279510a8ae340ca8b1f
7
- data.tar.gz: f2c42a2b47411636fc8a91cea55bdfdc6bc0713fc1f57324ab32b342b3ef091224927c36fa6412d922d2c4e351c898cb6a85f542f59599daae726aab60d95d9c
6
+ metadata.gz: 19e84d86352917ac640de46644d5daf49965e14b2b33ddc6de916ac12dd17be18ba0985698f9430e72c7a63eb405a1e6b694041b60f831ffac97cda9bb3662d9
7
+ data.tar.gz: 8931700e8bdc05341d68b189a7fd364d9b644d48266a89c4ce0e23a3515f7333aa4906feb7de38a2221e72b92031ba801dbc3b5354905ceb121c98aa3b49393e
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.3
data/eye_of_newt.gemspec CHANGED
@@ -18,12 +18,12 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activesupport"
21
+ spec.add_dependency "activesupport", "~> 4"
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "racc"
26
- spec.add_development_dependency "pry"
27
- spec.add_development_dependency "pry-byebug"
28
- spec.add_development_dependency "pry-rescue"
24
+ spec.add_development_dependency "rake", "~> 10"
25
+ spec.add_development_dependency "racc", "~> 1"
26
+ spec.add_development_dependency "pry", "~> 0"
27
+ spec.add_development_dependency "pry-byebug", "~> 0"
28
+ spec.add_development_dependency "pry-rescue", "~> 0"
29
29
  end
@@ -1,12 +1,13 @@
1
1
  module EyeOfNewt
2
2
  class Ingredient
3
- attr_accessor :amount, :unit, :name, :style
3
+ attr_accessor :amount, :unit, :name, :style, :note
4
4
 
5
- def initialize(amount: nil, unit: nil, name: nil, style: nil)
5
+ def initialize(amount: nil, unit: nil, name: nil, style: nil, note: nil)
6
6
  self.amount = amount
7
7
  self.unit = unit
8
8
  self.name = name
9
9
  self.style = style
10
+ self.note = note
10
11
  end
11
12
  end
12
13
  end
@@ -37,75 +37,92 @@ module EyeOfNewt
37
37
  ##### State transition tables begin ###
38
38
 
39
39
  racc_action_table = [
40
- -19, 11, 15, 25, 14, 13, 11, -19, 11, 14,
41
- 13, 14, 13, 11, 23, 14, 14, 13, 27, 28,
42
- 20, 29, 20, 16, 14, 27, 33, 34 ]
40
+ -30, 11, 13, 21, 22, 12, 9, 11, -30, -30,
41
+ -30, 12, 16, 11, 20, 21, 22, 12, 16, 25,
42
+ 31, 24, 29, 30, 21, 22, 27, 14, 22, 38,
43
+ 38, 40, 29, 41, 42, 22, 22, 45 ]
43
44
 
44
45
  racc_action_check = [
45
- 9, 0, 0, 6, 0, 0, 2, 9, 20, 2,
46
- 2, 20, 20, 10, 5, 5, 10, 10, 15, 15,
47
- 3, 16, 17, 1, 21, 25, 27, 28 ]
46
+ 9, 0, 0, 15, 15, 0, 0, 2, 9, 9,
47
+ 9, 2, 2, 10, 3, 3, 3, 10, 10, 5,
48
+ 14, 5, 13, 13, 17, 17, 6, 1, 18, 21,
49
+ 22, 23, 27, 29, 30, 32, 34, 39 ]
48
50
 
49
51
  racc_action_pointer = [
50
- -1, 23, 4, 13, nil, 10, 0, nil, nil, 0,
51
- 11, nil, nil, nil, nil, 10, 21, 15, nil, nil,
52
- 6, 19, nil, nil, nil, 17, nil, 23, 24, nil,
53
- nil, nil, nil, nil, nil ]
52
+ -1, 27, 5, 6, nil, 15, 23, nil, nil, 0,
53
+ 11, nil, nil, 10, 20, -6, nil, 15, 18, nil,
54
+ nil, 24, 25, 25, nil, nil, nil, 20, nil, 30,
55
+ 31, nil, 25, nil, 26, nil, nil, nil, nil, 26,
56
+ nil, nil, nil, nil, nil, nil ]
54
57
 
55
58
  racc_action_default = [
56
- -27, -27, -27, -4, -5, -9, -10, -12, -13, -14,
57
- -17, -18, -20, -21, -22, -24, -27, -2, -19, -3,
58
- -27, -7, -8, -23, -11, -27, -16, -27, -27, 35,
59
- -1, -15, -6, -25, -26 ]
59
+ -36, -36, -36, -12, -13, -17, -18, -20, -21, -22,
60
+ -27, -29, -31, -33, -36, -8, -30, -10, -11, -6,
61
+ -23, -36, -36, -15, -16, -32, -19, -36, -26, -36,
62
+ -36, 46, -7, -2, -9, -4, -5, -24, -28, -36,
63
+ -14, -34, -35, -1, -3, -25 ]
60
64
 
61
65
  racc_goto_table = [
62
- 22, 19, 26, 7, 3, 21, 17, 5, 1, 24,
63
- 6, 2, 31, 8, 9, 30, 32 ]
66
+ 19, 7, 28, 3, 18, 15, 17, 26, 37, 39,
67
+ 5, 23, 33, 6, 35, 36, 32, 2, 34, 8,
68
+ 1, nil, nil, nil, nil, nil, nil, nil, nil, 43,
69
+ nil, 44 ]
64
70
 
65
71
  racc_goto_check = [
66
- 8, 4, 5, 10, 3, 7, 3, 6, 1, 10,
67
- 9, 2, 5, 11, 12, 4, 8 ]
72
+ 5, 11, 7, 3, 4, 3, 6, 11, 13, 13,
73
+ 8, 9, 5, 10, 5, 5, 4, 2, 4, 12,
74
+ 1, nil, nil, nil, nil, nil, nil, nil, nil, 5,
75
+ nil, 5 ]
68
76
 
69
77
  racc_goto_pointer = [
70
- nil, 8, 11, 4, -2, -8, 7, 0, -5, 10,
71
- 3, 13, 14, nil ]
78
+ nil, 20, 17, 3, 1, -3, 3, -8, 10, 6,
79
+ 13, 1, 19, -13, nil ]
72
80
 
73
81
  racc_goto_default = [
74
- nil, nil, nil, nil, nil, 4, nil, nil, 12, nil,
75
- nil, nil, 18, 10 ]
82
+ nil, nil, nil, nil, nil, nil, nil, 4, nil, nil,
83
+ nil, nil, nil, nil, 10 ]
76
84
 
77
85
  racc_reduce_table = [
78
86
  0, 0, :racc_error,
79
- 3, 11, :_reduce_none,
80
- 2, 11, :_reduce_none,
81
- 2, 11, :_reduce_none,
82
- 1, 11, :_reduce_none,
83
- 1, 13, :_reduce_5,
84
- 3, 12, :_reduce_none,
85
- 2, 12, :_reduce_none,
86
- 2, 12, :_reduce_none,
87
- 1, 12, :_reduce_none,
88
- 1, 16, :_reduce_10,
89
- 2, 16, :_reduce_11,
90
- 1, 16, :_reduce_12,
91
- 1, 16, :_reduce_13,
92
- 1, 16, :_reduce_14,
93
- 2, 14, :_reduce_15,
94
- 2, 15, :_reduce_16,
87
+ 4, 15, :_reduce_none,
88
+ 3, 15, :_reduce_none,
89
+ 4, 15, :_reduce_none,
90
+ 3, 15, :_reduce_none,
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,
95
98
  1, 15, :_reduce_none,
96
- 1, 23, :_reduce_none,
97
- 1, 23, :_reduce_none,
98
- 1, 23, :_reduce_none,
99
- 1, 22, :_reduce_none,
100
- 1, 18, :_reduce_none,
101
- 1, 17, :_reduce_23,
102
- 1, 19, :_reduce_24,
103
- 3, 20, :_reduce_25,
104
- 3, 21, :_reduce_26 ]
105
-
106
- racc_reduce_n = 27
107
-
108
- racc_shift_n = 35
99
+ 1, 17, :_reduce_13,
100
+ 3, 16, :_reduce_none,
101
+ 2, 16, :_reduce_none,
102
+ 2, 16, :_reduce_none,
103
+ 1, 16, :_reduce_none,
104
+ 1, 22, :_reduce_18,
105
+ 2, 22, :_reduce_19,
106
+ 1, 22, :_reduce_20,
107
+ 1, 22, :_reduce_21,
108
+ 1, 22, :_reduce_22,
109
+ 1, 20, :_reduce_23,
110
+ 2, 18, :_reduce_24,
111
+ 3, 19, :_reduce_25,
112
+ 2, 21, :_reduce_26,
113
+ 1, 21, :_reduce_none,
114
+ 1, 27, :_reduce_none,
115
+ 1, 28, :_reduce_none,
116
+ 1, 28, :_reduce_none,
117
+ 1, 28, :_reduce_none,
118
+ 1, 23, :_reduce_32,
119
+ 1, 24, :_reduce_33,
120
+ 3, 25, :_reduce_34,
121
+ 3, 26, :_reduce_35 ]
122
+
123
+ racc_reduce_n = 36
124
+
125
+ racc_shift_n = 46
109
126
 
110
127
  racc_token_table = {
111
128
  false => 0,
@@ -113,13 +130,17 @@ racc_token_table = {
113
130
  :WORD => 2,
114
131
  :NUMBER => 3,
115
132
  :UNIT => 4,
116
- :OF => 5,
117
- :A => 6,
118
- "," => 7,
119
- "/" => 8,
120
- "." => 9 }
121
-
122
- racc_nt_base = 10
133
+ :TEXT => 5,
134
+ :OF => 6,
135
+ :A => 7,
136
+ :TO_TASTE => 8,
137
+ "," => 9,
138
+ "(" => 10,
139
+ ")" => 11,
140
+ "/" => 12,
141
+ "." => 13 }
142
+
143
+ racc_nt_base = 14
123
144
 
124
145
  racc_use_result_var = true
125
146
 
@@ -145,9 +166,13 @@ Racc_token_to_s_table = [
145
166
  "WORD",
146
167
  "NUMBER",
147
168
  "UNIT",
169
+ "TEXT",
148
170
  "OF",
149
171
  "A",
172
+ "TO_TASTE",
150
173
  "\",\"",
174
+ "\"(\"",
175
+ "\")\"",
151
176
  "\"/\"",
152
177
  "\".\"",
153
178
  "$start",
@@ -155,14 +180,15 @@ Racc_token_to_s_table = [
155
180
  "quantity",
156
181
  "ingredient_name",
157
182
  "style",
183
+ "note",
184
+ "to_taste",
158
185
  "words",
159
186
  "amount",
160
187
  "unit",
161
- "of",
162
188
  "number",
163
189
  "fraction",
164
190
  "decimal",
165
- "a",
191
+ "text",
166
192
  "word" ]
167
193
 
168
194
  Racc_debug_parser = false
@@ -179,10 +205,7 @@ Racc_debug_parser = false
179
205
 
180
206
  # reduce 4 omitted
181
207
 
182
- def _reduce_5(val, _values, result)
183
- @ingredient.name = result
184
- result
185
- end
208
+ # reduce 5 omitted
186
209
 
187
210
  # reduce 6 omitted
188
211
 
@@ -192,69 +215,96 @@ end
192
215
 
193
216
  # reduce 9 omitted
194
217
 
195
- def _reduce_10(val, _values, result)
218
+ # reduce 10 omitted
219
+
220
+ # reduce 11 omitted
221
+
222
+ # reduce 12 omitted
223
+
224
+ def _reduce_13(val, _values, result)
225
+ @ingredient.name = result
226
+ result
227
+ end
228
+
229
+ # reduce 14 omitted
230
+
231
+ # reduce 15 omitted
232
+
233
+ # reduce 16 omitted
234
+
235
+ # reduce 17 omitted
236
+
237
+ def _reduce_18(val, _values, result)
196
238
  @ingredient.amount = result
197
239
  result
198
240
  end
199
241
 
200
- def _reduce_11(val, _values, result)
242
+ def _reduce_19(val, _values, result)
201
243
  @ingredient.amount = val[0] + val[1]
202
244
  result
203
245
  end
204
246
 
205
- def _reduce_12(val, _values, result)
247
+ def _reduce_20(val, _values, result)
206
248
  @ingredient.amount = result
207
249
  result
208
250
  end
209
251
 
210
- def _reduce_13(val, _values, result)
252
+ def _reduce_21(val, _values, result)
211
253
  @ingredient.amount = result
212
254
  result
213
255
  end
214
256
 
215
- def _reduce_14(val, _values, result)
257
+ def _reduce_22(val, _values, result)
216
258
  @ingredient.amount = 1
217
259
  result
218
260
  end
219
261
 
220
- def _reduce_15(val, _values, result)
262
+ def _reduce_23(val, _values, result)
263
+ @ingredient.unit = to_unit(result)
264
+ result
265
+ end
266
+
267
+ def _reduce_24(val, _values, result)
221
268
  @ingredient.style = val[1]
222
269
  result
223
270
  end
224
271
 
225
- def _reduce_16(val, _values, result)
226
- result = val.join(' ')
272
+ def _reduce_25(val, _values, result)
273
+ @ingredient.note = val[1]
227
274
  result
228
275
  end
229
276
 
230
- # reduce 17 omitted
277
+ def _reduce_26(val, _values, result)
278
+ result = val.join(' ')
279
+ result
280
+ end
231
281
 
232
- # reduce 18 omitted
282
+ # reduce 27 omitted
233
283
 
234
- # reduce 19 omitted
284
+ # reduce 28 omitted
235
285
 
236
- # reduce 20 omitted
286
+ # reduce 29 omitted
237
287
 
238
- # reduce 21 omitted
288
+ # reduce 30 omitted
239
289
 
240
- # reduce 22 omitted
290
+ # reduce 31 omitted
241
291
 
242
- def _reduce_23(val, _values, result)
292
+ def _reduce_32(val, _values, result)
243
293
  @ingredient.unit = to_unit(result)
244
294
  result
245
295
  end
246
296
 
247
- def _reduce_24(val, _values, result)
297
+ def _reduce_33(val, _values, result)
248
298
  result = val[0].to_i
249
299
  result
250
300
  end
251
301
 
252
- def _reduce_25(val, _values, result)
302
+ def _reduce_34(val, _values, result)
253
303
  result = val[0].to_f / val[2].to_f
254
304
  result
255
305
  end
256
306
 
257
- def _reduce_26(val, _values, result)
307
+ def _reduce_35(val, _values, result)
258
308
  result = val.join.to_f
259
309
  result
260
310
  end
@@ -1,9 +1,17 @@
1
1
  class EyeOfNewt::Parser
2
- token WORD NUMBER UNIT OF A
2
+ token WORD NUMBER UNIT TEXT OF A TO_TASTE
3
3
  rule
4
4
  ingredient
5
- : quantity ingredient_name style
5
+ : quantity ingredient_name style note
6
+ | quantity ingredient_name note
7
+ | ingredient_name to_taste style note
8
+ | ingredient_name to_taste note
9
+ | ingredient_name style note
10
+ | ingredient_name note
11
+ | quantity ingredient_name style
6
12
  | quantity ingredient_name
13
+ | ingredient_name to_taste style
14
+ | ingredient_name to_taste
7
15
  | ingredient_name style
8
16
  | ingredient_name
9
17
  ;
@@ -11,9 +19,9 @@ rule
11
19
  : words { @ingredient.name = result }
12
20
  ;
13
21
  quantity
14
- : amount unit of
22
+ : amount unit OF
15
23
  | amount unit
16
- | amount of
24
+ | amount OF
17
25
  | amount
18
26
  ;
19
27
  amount
@@ -21,16 +29,17 @@ rule
21
29
  | number fraction { @ingredient.amount = val[0] + val[1] }
22
30
  | fraction { @ingredient.amount = result }
23
31
  | decimal { @ingredient.amount = result }
24
- | a { @ingredient.amount = 1 }
32
+ | A { @ingredient.amount = 1 }
25
33
  ;
26
- style : ',' words { @ingredient.style = val[1] } ;
34
+ to_taste : TO_TASTE { @ingredient.unit = to_unit(result) } ;
35
+ style : ',' text { @ingredient.style = val[1] } ;
36
+ note : '(' text ')' { @ingredient.note = val[1] } ;
27
37
  words
28
38
  : word words { result = val.join(' ') }
29
39
  | word
30
40
  ;
31
- word : WORD | a | of ;
32
- a : A ;
33
- of : OF ;
41
+ text : TEXT
42
+ word : WORD | A | OF ;
34
43
  unit : UNIT { @ingredient.unit = to_unit(result) } ;
35
44
  number : NUMBER { result = val[0].to_i } ;
36
45
  fraction : NUMBER '/' NUMBER { result = val[0].to_f / val[2].to_f } ;
@@ -26,6 +26,7 @@ module EyeOfNewt
26
26
  private
27
27
 
28
28
  def fraction_str
29
+ return nil if units.unquantified?(unit)
29
30
  whole = fraction.to_i
30
31
  fractional = fraction - whole
31
32
  [whole, fractional].reject(&:zero?).join(' ')
@@ -2,13 +2,16 @@ require 'strscan'
2
2
 
3
3
  module EyeOfNewt
4
4
  class Tokenizer
5
- NO_MATCH = /^&%#&^%/
5
+ NO_MATCH = /a^/ # should never match anything
6
6
 
7
7
  WHITESPACE = /\s+/
8
+ ANYTHING = /[^()]+/
8
9
  WORD = /[\w-]+/
9
10
  NUMBER = /\d+/
10
11
  OF = /of/
11
12
  A = /an?/
13
+ TO_TASTE = /to taste/
14
+ COMMA = ','
12
15
 
13
16
  attr_reader :string, :units
14
17
 
@@ -24,18 +27,23 @@ module EyeOfNewt
24
27
  @ss.scan(WHITESPACE)
25
28
 
26
29
  case
30
+ when @scan_text && text = @ss.scan(/#{ANYTHING}\b/)
31
+ [:TEXT, text]
27
32
  when text = @ss.scan(NUMBER)
28
33
  [:NUMBER, text]
29
34
  when text = @ss.scan(/#{OF}\b/)
30
35
  [:OF, text]
31
36
  when text = @ss.scan(/#{A}\b/)
32
37
  [:A, text]
38
+ when text = @ss.scan(/#{TO_TASTE}\b/)
39
+ [:TO_TASTE, text]
33
40
  when text = @ss.scan(/#{unit_matcher}\b/)
34
41
  [:UNIT, text]
35
42
  when text = @ss.scan(/#{WORD}\b/)
36
43
  [:WORD, text]
37
44
  else
38
45
  x = @ss.getch
46
+ @scan_text = true if x == ',' || x == '('
39
47
  [x, x]
40
48
  end
41
49
  end
@@ -8,6 +8,7 @@ module EyeOfNewt
8
8
  @units = {}
9
9
  @conversions = Hash.new { |h, k| h[k] = {} }
10
10
  @default = nil
11
+ @unquantified = []
11
12
  end
12
13
 
13
14
  def all
@@ -18,12 +19,13 @@ module EyeOfNewt
18
19
  units[unit] or raise UnknownUnit.new(unit)
19
20
  end
20
21
 
21
- def add_unit(canonical, *variations, default: false)
22
+ def add_unit(canonical, *variations, default: false, unquantified: false)
22
23
  units[canonical] = canonical
23
24
  variations.each do |v|
24
25
  units[v] = canonical
25
26
  end
26
27
 
28
+ @unquantified << canonical if unquantified
27
29
  @default = canonical if default
28
30
 
29
31
  conversions[canonical][canonical] = 1
@@ -44,6 +46,10 @@ module EyeOfNewt
44
46
  r.to_f
45
47
  end
46
48
 
49
+ def unquantified?(unit)
50
+ @unquantified.include?(self[unit])
51
+ end
52
+
47
53
  def setup(&block)
48
54
  instance_eval &block
49
55
  self
@@ -79,6 +85,9 @@ module EyeOfNewt
79
85
  add_unit "touches", "touch"
80
86
  add_unit "handfuls", "handful"
81
87
 
88
+ # unquantified units
89
+ add_unit "to taste", unquantified: true
90
+
82
91
  add_unit "units", "unit", default: true
83
92
 
84
93
  add_conversion 16, "tbsp", "cup"
@@ -1,3 +1,3 @@
1
1
  module EyeOfNewt
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/test/examples.txt CHANGED
@@ -12,6 +12,13 @@ tomatoes | tomatoes | 1 | units
12
12
  1 cup of flour | flour | 1 | cups
13
13
  1 teaspoon of cream of tartar | cream of tartar | 1 | tsp
14
14
  a pinch of salt | salt | 1 | pinches
15
+ 4 large leeks, trimmed & thinly sliced | large leeks | 4 | units | trimmed & thinly sliced
16
+ 3 pounds potatoes, washed and cut into 2-inch chunks | potatoes | 3 | lb | washed and cut into 2-inch chunks
17
+ salt to taste | salt | 1 | to taste
18
+ an apple, sliced (I like Fuji, but any variety will do) | apple | 1 | units | sliced | I like Fuji, but any variety will do
19
+ #4-5 handfuls of spinach, very roughly chopped
20
+ #3 tablespoons sunflower oil, ghee, or clarified butter
21
+ #1/2 cup crumbled feta, fresh ricotta, or fresh paneer
15
22
 
16
23
  #1 (46 fluid ounce) can tomato juice' => ["1 (46 fluid ounce) can", "tomato juice"],
17
24
  #1 (29 ounce) can tomato sauce' => ["1 (29 ounce) can", "tomato sauce"],
@@ -20,5 +27,3 @@ a pinch of salt | salt | 1 | pinches
20
27
 
21
28
  #1 1/2 cups chopped onion' => ["1 1/2 cups", "onion", "chopped"],
22
29
  #1/4 cup chopped green bell pepper' => ["1/4 cup", "green bell pepper", "chopped"],
23
-
24
- #1/8 teaspoon ground cayenne pepper' => ["1/8 teaspoon", "ground cayenne pepper"],
@@ -24,6 +24,7 @@ class EyeOfNewt::QuantityTest < ActiveSupport::TestCase
24
24
  assert_equal "1 1/2 tbsp", EyeOfNewt::Quantity.new(1.5, "tbs").to_s
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
+ assert_equal "to taste", EyeOfNewt::Quantity.new(1, "to taste").to_s
27
28
  end
28
29
 
29
30
  end
@@ -2,9 +2,42 @@ require 'test_helper'
2
2
 
3
3
  class EyeOfNewt::TokenizerTest < ActiveSupport::TestCase
4
4
  test "tokenizes WORD" do
5
- t = tok("hello world")
5
+ t = tok("hello world to-day")
6
6
  assert_equal [:WORD, "hello"], t.next_token
7
7
  assert_equal [:WORD, "world"], t.next_token
8
+ assert_equal [:WORD, "to-day"], t.next_token
9
+ assert_nil t.next_token
10
+ end
11
+
12
+ test "tokenizes TEXT after a comma" do
13
+ t = tok(", cut into 2-inch chunks")
14
+ assert_equal [',', ","], t.next_token
15
+ assert_equal [:TEXT, "cut into 2-inch chunks"], t.next_token
16
+ assert_nil t.next_token
17
+ end
18
+
19
+ test "tokenizes TEXT between parens" do
20
+ t = tok("(this is a note)")
21
+ assert_equal ['(', "("], t.next_token
22
+ assert_equal [:TEXT, "this is a note"], t.next_token
23
+ assert_equal [')', ')'], t.next_token
24
+ assert_nil t.next_token
25
+ end
26
+
27
+ test "tokenizes TEXT after a comma, with parens" do
28
+ t = tok(", sliced (this is a note)")
29
+ assert_equal [',', ","], t.next_token
30
+ assert_equal [:TEXT, "sliced"], t.next_token
31
+ assert_equal ['(', "("], t.next_token
32
+ assert_equal [:TEXT, "this is a note"], t.next_token
33
+ assert_equal [')', ')'], t.next_token
34
+ assert_nil t.next_token
35
+ end
36
+
37
+ test "tokenizes TO_TASTE" do
38
+ t = tok("salt to taste")
39
+ assert_equal [:WORD, "salt"], t.next_token
40
+ assert_equal [:TO_TASTE, "to taste"], t.next_token
8
41
  assert_nil t.next_token
9
42
  end
10
43
 
@@ -17,6 +17,13 @@ class EyeOfNewt::UnitsTest < ActiveSupport::TestCase
17
17
  assert_equal "foo", units.default
18
18
  end
19
19
 
20
+ test "#unquantified returns true for unquantified units" do
21
+ units = EyeOfNewt::Units.new.setup do
22
+ add_unit "foo", unquantified: true
23
+ end
24
+ assert units.unquantified?("foo")
25
+ end
26
+
20
27
  test "#[] returns the canonical name of the unit" do
21
28
  units = EyeOfNewt::Units.new.setup do
22
29
  add_unit "foo", "f"
@@ -15,7 +15,8 @@ class EyeOfNewtTest < ActiveSupport::TestCase
15
15
  amount = tokens.shift.to_f
16
16
  unit = tokens.shift.presence
17
17
  style = tokens.shift.presence
18
- expected = [name, amount, unit, style]
18
+ note = tokens.shift.presence
19
+ expected = [name, amount, unit, style, note]
19
20
  [line, expected]
20
21
  }.compact
21
22
  end
@@ -24,11 +25,12 @@ class EyeOfNewtTest < ActiveSupport::TestCase
24
25
  examples.each do |line, expected|
25
26
  test "parses #{line} correctly" do
26
27
  ingr = EyeOfNewt.parse(line)
27
- name, amount, unit, style = *expected
28
+ name, amount, unit, style, note = *expected
29
+ assert_equal name, ingr.name, %Q{incorrect name}
28
30
  assert_equal amount, ingr.amount, %Q{incorrect amount}
29
31
  assert_equal unit, ingr.unit, %Q{incorrect unit}
30
- assert_equal name, ingr.name, %Q{incorrect name}
31
32
  assert_equal style, ingr.style, %Q{incorrect style}
33
+ assert_equal note, ingr.note, %Q{incorrect note}
32
34
  end
33
35
  end
34
36
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eye-of-newt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter McCracken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '4'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,70 +42,70 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '10'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '10'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: racc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: pry-byebug
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry-rescue
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Parses natural ingredients (e.g. "1 1/2 pounds of potatoes, peeled")
@@ -117,6 +117,7 @@ extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
+ - ".ruby-version"
120
121
  - Gemfile
121
122
  - LICENSE
122
123
  - LICENSE.txt
@@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
161
  version: '0'
161
162
  requirements: []
162
163
  rubyforge_project:
163
- rubygems_version: 2.2.0
164
+ rubygems_version: 2.2.2
164
165
  signing_key:
165
166
  specification_version: 4
166
167
  summary: Natural language ingredient parser