bread_calculator 0.1.0 → 0.2.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 +13 -11
- data/bread_calculator.gemspec +1 -1
- data/lib/bread_calculator.rb +13 -4
- data/spec/bread_calculator_spec.rb +3 -2
- 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: 8d51a14aeb0190404ecd01140c0daa9a489f75f2
|
4
|
+
data.tar.gz: 7416606cdbb1753be4dee8ed4d35c6b3d9b247f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26338dcb8070fff24aa8bf9ea8a3641a556923b4bbc63c3d237ed426de2a60d4537e7625918a6419f8eb7449b903b96ec34d27ad49113ce7c46c856f3f4c5b46
|
7
|
+
data.tar.gz: e265e1d62874d68e8e6096db8105b43062110b08220b19b51e75b4610ce4abbbc5252850c0a814607adedb30b2b69d7754d6045e98ab009662b5adaa1800f020
|
data/bin/bread-calc
CHANGED
@@ -8,12 +8,12 @@ def help status=true
|
|
8
8
|
NAME
|
9
9
|
bread-calc
|
10
10
|
SYNOPSIS
|
11
|
-
bread-calc [OPTIONS] FILE
|
11
|
+
bread-calc [OPTIONS] [FILE]
|
12
12
|
DESCRIPTION
|
13
|
-
bread-calc parses a nearly free-form bread recipe in file FILE
|
14
|
-
the canonical representation of the recipe is printed
|
15
|
-
Optionally, the weight, or bakers percentage formula can be
|
16
|
-
recipe can by scaled up or down.
|
13
|
+
bread-calc parses a nearly free-form bread recipe in file FILE, or from
|
14
|
+
standard in. By default the canonical representation of the recipe is printed
|
15
|
+
to standard out. Optionally, the weight, or bakers percentage formula can be
|
16
|
+
generated, or the recipe can by scaled up or down.
|
17
17
|
OPTIONS:
|
18
18
|
--help
|
19
19
|
print this help
|
@@ -46,6 +46,8 @@ BUGS
|
|
46
46
|
|
47
47
|
It is undefined how 'liquid flour additive' is parsed, but don't expect
|
48
48
|
anything good.
|
49
|
+
|
50
|
+
There is no man page.
|
49
51
|
EOF
|
50
52
|
|
51
53
|
exit status
|
@@ -59,7 +61,8 @@ loop { case ARGV[0]
|
|
59
61
|
when /--help/ then @help = 'help' ; ARGV.shift; break
|
60
62
|
when /--summary/ then @get = 'r.summary'; ARGV.shift
|
61
63
|
when /--weight/ then @get = 'r.weight'; ARGV.shift
|
62
|
-
|
64
|
+
#.to_f protects against 'no .<digit> floating literal anymore' for .33
|
65
|
+
when /--scale-by/ then ARGV.shift; @get = "r.scale_by #{ARGV.shift.to_f}"
|
63
66
|
when /--/ then ARGV.shift; break
|
64
67
|
when /^-/ then help 1
|
65
68
|
else break
|
@@ -67,8 +70,7 @@ end; }
|
|
67
70
|
|
68
71
|
help if @help
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
73
|
+
parser = BreadCalculator::Parser.new
|
74
|
+
r = parser.parse ARGF.file
|
75
|
+
puts eval("#{@get}")
|
76
|
+
|
data/bread_calculator.gemspec
CHANGED
data/lib/bread_calculator.rb
CHANGED
@@ -42,7 +42,15 @@ module BreadCalculator
|
|
42
42
|
|
43
43
|
def to_s
|
44
44
|
#FIXME check for existance
|
45
|
-
|
45
|
+
precision = 0
|
46
|
+
if @quantity < 10
|
47
|
+
precision = 1
|
48
|
+
end
|
49
|
+
if @quantity < 1
|
50
|
+
precision = 2
|
51
|
+
end
|
52
|
+
f_quantity = sprintf "%.#{precision}f", @quantity
|
53
|
+
"\t#{f_quantity} #{@units} #{@name}\n"
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
@@ -205,7 +213,7 @@ module BreadCalculator
|
|
205
213
|
class Parser
|
206
214
|
|
207
215
|
##
|
208
|
-
# Create a new parser for Recipe
|
216
|
+
# Create a new parser for Recipe
|
209
217
|
|
210
218
|
def initialize
|
211
219
|
@i = 0
|
@@ -218,11 +226,12 @@ module BreadCalculator
|
|
218
226
|
end
|
219
227
|
|
220
228
|
##
|
221
|
-
# Parse
|
229
|
+
# Parse text from IO object +input+. It is the caller's responsibility to
|
230
|
+
# open and close the +input+ correctly.
|
222
231
|
|
223
232
|
def parse input
|
224
233
|
|
225
|
-
|
234
|
+
while line = input.gets
|
226
235
|
new_step && next if line =~ /(^-)|(^\s*$)/
|
227
236
|
preprocess_meta(line) && next if @in_prelude
|
228
237
|
|
@@ -66,9 +66,10 @@ describe BreadCalculator do
|
|
66
66
|
|
67
67
|
describe BreadCalculator::Parser do
|
68
68
|
before do
|
69
|
-
@sample = "#{File.dirname(__FILE__)}/../sample/sandwich-bread.recipe"
|
70
69
|
@parser = BreadCalculator::Parser.new
|
71
|
-
@
|
70
|
+
@sample = "#{File.dirname(__FILE__)}/../sample/sandwich-bread.recipe"
|
71
|
+
@io = File.new(@sample,'r')
|
72
|
+
@r = @parser.parse @io
|
72
73
|
end
|
73
74
|
|
74
75
|
it 'gets a recipe from a text file' do
|