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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cbd43078e0f6a01f011391dd6648963c936f016
4
- data.tar.gz: daaaeedbe36c23d8f3b8da79ec6b2336f6c5440a
3
+ metadata.gz: 666fabbb1e5c7ca277e727d4c3e90cce94fbc0d2
4
+ data.tar.gz: 70432c965d212256fadb9e6be72d65edfae30301
5
5
  SHA512:
6
- metadata.gz: c6759ec269ed7e0c74acac7002d43509b112945efe4cc8fc3747c0f6319fa95620bea54ba1d88d7b382a8778eca7038d04d31df933af6ec643e64e985d0d4bf6
7
- data.tar.gz: 02c65e0cc83274355b70edcea3eb47cc501b7e0b0c3a99acc37f213e88e8873a03f477c102f855b77d11a9a0e7bc0fc76eea753450fe0b6063f04ed4bcdab84b
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 starts with a free-form prelude. Any line starting with a
30
- hyphen ends the prelude and starts the first step.
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 arg
71
+ parser = BreadCalculator::Parser.new
65
72
  r = parser.parse(arg)
66
73
  puts eval("#{@get}")
67
74
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bread_calculator'
3
- s.version = '0.0.2'
3
+ s.version = '0.1.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
@@ -207,15 +207,14 @@ module BreadCalculator
207
207
  ##
208
208
  # Create a new parser for Recipe +name+.
209
209
 
210
- def initialize name
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 && next if line =~ /(^-)|(^\s*$)/
228
- @prelude << line && next if @in_prelude
226
+ new_step && next if line =~ /(^-)|(^\s*$)/
227
+ preprocess_meta(line) && next if @in_prelude
229
228
 
230
- @args << preprocess(line.chomp)
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 preprocess line
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
- pending
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 'Sandwich Bread'
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
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.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Birnel