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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 666fabbb1e5c7ca277e727d4c3e90cce94fbc0d2
4
- data.tar.gz: 70432c965d212256fadb9e6be72d65edfae30301
3
+ metadata.gz: 8d51a14aeb0190404ecd01140c0daa9a489f75f2
4
+ data.tar.gz: 7416606cdbb1753be4dee8ed4d35c6b3d9b247f4
5
5
  SHA512:
6
- metadata.gz: a6438357680a4f803b3e69f0455edc5e73f3ea404cb98629f1c4ec01ad4b8d42f23d96066754f6b6e88df531e2d69b8f3cc5be4f4583ee1f08d021c820a93181
7
- data.tar.gz: 2f5885744e28b1e3f46ff0e0e9fad1fc5a3606553fda3565a37be29ceeb00e172cb08054c5f854879f599a8a505e439fdbe7d3e1138a26cfdc97ca162d27a1c9
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. By default
14
- the canonical representation of the recipe is printed to standard out.
15
- Optionally, the weight, or bakers percentage formula can be generated, or the
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
- when /--scale-by/ then ARGV.shift; @get = "r.scale_by #{ARGV.shift}"
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
- ARGV.each do |arg|
71
- parser = BreadCalculator::Parser.new
72
- r = parser.parse(arg)
73
- puts eval("#{@get}")
74
- end
73
+ parser = BreadCalculator::Parser.new
74
+ r = parser.parse ARGF.file
75
+ puts eval("#{@get}")
76
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bread_calculator'
3
- s.version = '0.1.0'
3
+ s.version = '0.2.0'
4
4
  s.date = '2014-03-07'
5
5
  s.summary = "calculate baker's percentages"
6
6
  s.description = "a gem and command-line wrapper to generate baker's
@@ -42,7 +42,15 @@ module BreadCalculator
42
42
 
43
43
  def to_s
44
44
  #FIXME check for existance
45
- "\t#{@quantity} #{@units} #{@name}\n"
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 +name+.
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 our text
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
- IO.foreach(input) do |line|
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
- @r = @parser.parse "#{@sample}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bread_calculator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Birnel