bread_calculator 0.0.2 → 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 +4 -4
- data/bin/bread-calc +14 -7
- data/bread_calculator.gemspec +1 -1
- data/lib/bread_calculator.rb +19 -13
- data/spec/bread_calculator_spec.rb +7 -3
- 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: 666fabbb1e5c7ca277e727d4c3e90cce94fbc0d2
|
4
|
+
data.tar.gz: 70432c965d212256fadb9e6be72d65edfae30301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6438357680a4f803b3e69f0455edc5e73f3ea404cb98629f1c4ec01ad4b8d42f23d96066754f6b6e88df531e2d69b8f3cc5be4f4583ee1f08d021c820a93181
|
7
|
+
data.tar.gz: 2f5885744e28b1e3f46ff0e0e9fad1fc5a3606553fda3565a37be29ceeb00e172cb08054c5f854879f599a8a505e439fdbe7d3e1138a26cfdc97ca162d27a1c9
|
data/bin/bread-calc
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'bread_calculator'
|
4
|
-
|
5
|
-
@get = 'r'
|
6
|
-
@help = nil
|
4
|
+
#require "#{File.dirname(__FILE__)}/../lib/bread_calculator"
|
7
5
|
|
8
6
|
def help status=true
|
9
7
|
puts <<EOF
|
@@ -26,8 +24,14 @@ OPTIONS:
|
|
26
24
|
--scale-by FACTOR
|
27
25
|
regenerate the recipe, scaling up or down by FACTOR
|
28
26
|
FORMATS
|
29
|
-
The recipe format
|
30
|
-
|
27
|
+
The recipe format consists of a metadata prelude, and steps.
|
28
|
+
|
29
|
+
In prelude lines, anything before a colon is considered to be the name of a
|
30
|
+
metadata field; anything after the colon is a value to populate. Lines
|
31
|
+
without colons are continuations of the 'notes' field. It is suggested to
|
32
|
+
have at least a 'name' field.
|
33
|
+
|
34
|
+
A line starting with a hyphen ends the prelude and starts the first step.
|
31
35
|
|
32
36
|
Each step is delimited by one or more blank lines.
|
33
37
|
|
@@ -44,10 +48,13 @@ BUGS
|
|
44
48
|
anything good.
|
45
49
|
EOF
|
46
50
|
|
47
|
-
exit status
|
51
|
+
exit status
|
48
52
|
|
49
53
|
end
|
50
54
|
|
55
|
+
@get = 'r'
|
56
|
+
@help = nil
|
57
|
+
|
51
58
|
loop { case ARGV[0]
|
52
59
|
when /--help/ then @help = 'help' ; ARGV.shift; break
|
53
60
|
when /--summary/ then @get = 'r.summary'; ARGV.shift
|
@@ -61,7 +68,7 @@ end; }
|
|
61
68
|
help if @help
|
62
69
|
|
63
70
|
ARGV.each do |arg|
|
64
|
-
parser = BreadCalculator::Parser.new
|
71
|
+
parser = BreadCalculator::Parser.new
|
65
72
|
r = parser.parse(arg)
|
66
73
|
puts eval("#{@get}")
|
67
74
|
end
|
data/bread_calculator.gemspec
CHANGED
data/lib/bread_calculator.rb
CHANGED
@@ -207,15 +207,14 @@ module BreadCalculator
|
|
207
207
|
##
|
208
208
|
# Create a new parser for Recipe +name+.
|
209
209
|
|
210
|
-
def initialize
|
211
|
-
@name = name
|
212
|
-
|
210
|
+
def initialize
|
213
211
|
@i = 0
|
214
212
|
@args = @steps = []
|
215
213
|
@steps[0] = BreadCalculator::Step.new
|
216
214
|
|
217
215
|
@in_prelude = true
|
218
216
|
@prelude = ''
|
217
|
+
@metadata = Hash.new(nil)
|
219
218
|
end
|
220
219
|
|
221
220
|
##
|
@@ -224,21 +223,16 @@ module BreadCalculator
|
|
224
223
|
def parse input
|
225
224
|
|
226
225
|
IO.foreach(input) do |line|
|
227
|
-
new_step
|
228
|
-
|
226
|
+
new_step && next if line =~ /(^-)|(^\s*$)/
|
227
|
+
preprocess_meta(line) && next if @in_prelude
|
229
228
|
|
230
|
-
@args <<
|
229
|
+
@args << preprocess_step(line.chomp)
|
231
230
|
end
|
232
231
|
|
233
232
|
close_step
|
234
233
|
# because we made a spurious one to begin with
|
235
234
|
@steps.shift
|
236
|
-
metadata
|
237
|
-
:name => @name,
|
238
|
-
:notes => @prelude,
|
239
|
-
}
|
240
|
-
|
241
|
-
Recipe.new metadata, @steps
|
235
|
+
Recipe.new @metadata, @steps
|
242
236
|
end
|
243
237
|
|
244
238
|
private
|
@@ -256,7 +250,19 @@ module BreadCalculator
|
|
256
250
|
@steps[@i].techniques = @args
|
257
251
|
end
|
258
252
|
|
259
|
-
def
|
253
|
+
def preprocess_meta line
|
254
|
+
/^((?<key>[^:]+):)?(?<value>.*)/ =~ line
|
255
|
+
match = Regexp.last_match
|
256
|
+
key = match[:key] ? match[:key].strip.to_sym : :notes
|
257
|
+
if @metadata[key]
|
258
|
+
@metadata[key] << "\n\t"
|
259
|
+
else
|
260
|
+
@metadata[key] = ''
|
261
|
+
end
|
262
|
+
@metadata[key] << match[:value].strip
|
263
|
+
end
|
264
|
+
|
265
|
+
def preprocess_step line
|
260
266
|
ing_regex = /^\s+((?<qty>[0-9.]+\s*)(?<units>g)?\s+)?(?<item>.*)/
|
261
267
|
h = Hash.new
|
262
268
|
if ing_regex =~ line
|
@@ -45,8 +45,7 @@ describe BreadCalculator do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'pretty prints' do
|
48
|
-
|
49
|
-
@recipe.to_s.is_a?(String).should be_true
|
48
|
+
@recipe.to_s.match(/\n-+\n/).should be_true
|
50
49
|
end
|
51
50
|
|
52
51
|
it 'generates a baker\'s percentage summary' do
|
@@ -68,7 +67,7 @@ describe BreadCalculator do
|
|
68
67
|
describe BreadCalculator::Parser do
|
69
68
|
before do
|
70
69
|
@sample = "#{File.dirname(__FILE__)}/../sample/sandwich-bread.recipe"
|
71
|
-
@parser = BreadCalculator::Parser.new
|
70
|
+
@parser = BreadCalculator::Parser.new
|
72
71
|
@r = @parser.parse "#{@sample}"
|
73
72
|
end
|
74
73
|
|
@@ -80,6 +79,11 @@ describe BreadCalculator do
|
|
80
79
|
pending
|
81
80
|
end
|
82
81
|
|
82
|
+
it 'generates metadata' do
|
83
|
+
#@r.metadata[:notes].is_a?(String).should be_true
|
84
|
+
@r.metadata[:notes].length.should == 86
|
85
|
+
end
|
86
|
+
|
83
87
|
end
|
84
88
|
|
85
89
|
end
|