bread_calculator 0.2.1 → 0.3.0

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: c5ee571e444d4434bf4a4e2f64b9adb8e36f77e3
4
- data.tar.gz: 36a0932e37107a14df6f4af01d4aa4ee0feb56de
3
+ metadata.gz: 6959568a142ec9660ea66a80839a34762e0282ee
4
+ data.tar.gz: 4b89277648b629fd0920eab943eadffa56d6e01f
5
5
  SHA512:
6
- metadata.gz: d9e1fb24bb4da2e0bc23b61f1592c02e937604238d10ad31efd9750bc7fb7cc1cc40900246805f97650f9a6a73e04a4808919775520b2b3d983c628a02b76a7d
7
- data.tar.gz: 180f92195733884d5a986ffa2aef459c23efe24cd1b5e58f4494dba21b0079e20ccac1ac2abda8d2a61ddf143347d83ba4dc23b553bb78a2ec3f7534a5ad9a3e
6
+ metadata.gz: c6bb8d52aa6d48efbaf602ac3d56c85ed5ad71f30e0723cf681f77c3204671356b0e5093ca2f2865ea7d48b43acdc9b97a19dcf9463fc036c8427035340566a4
7
+ data.tar.gz: e541c41118bb3086b7b7789a973feb6942b90aa7c3e0cf65768f7df1701c5e124789a55c036b530792bff3a603a89f098dedcfc50506ded7f3bc1a239d357277
data/README.md CHANGED
@@ -9,11 +9,11 @@ Installation
9
9
  or, if you want the latest and the greatest,
10
10
  or if you want the man page installed:
11
11
 
12
- `git clone https://github.com/bread-calculator
13
- cd bread-calculator
14
- rake install`
12
+ git clone https://github.com/bread-calculator
13
+ cd bread-calculator
14
+ rake install
15
15
 
16
- (use sudo as necessary)
16
+ (use `sudo` as necessary)
17
17
 
18
18
  Runtime Requirements
19
19
  ---------
@@ -104,6 +104,9 @@ print this help</p>
104
104
  <p style="margin-left:11%; margin-top: 1em"><b>--summary</b>
105
105
  print a baker&rsquo;s percentage summary</p>
106
106
 
107
+ <p style="margin-left:11%; margin-top: 1em"><b>--html</b>
108
+ print recipe as html.</p>
109
+
107
110
 
108
111
  <p style="margin-left:11%; margin-top: 1em"><b>--weight</b>
109
112
  print the weight</p>
@@ -144,18 +147,41 @@ delimited by one or more blank lines.</p>
144
147
 
145
148
  <p style="margin-left:11%; margin-top: 1em">Any line in a
146
149
  step starting with a space or a blank is an ingredient,
147
- consisting of quantity, units, and the ingredient itself.
148
- <b>bread-calc</b> will attempt to guess at the type of
149
- ingredient, but you can always force it by including one of
150
- the words &rsquo;flour&rsquo;, &rsquo;liquid&rsquo;, or
150
+ consisting of quantity, units, and the ingredient
151
+ itself.</p>
152
+
153
+
154
+ <p style="margin-left:11%; margin-top: 1em"><b>bread-calc</b>
155
+ will attempt to guess at the type of ingredient, but you can
156
+ always force it by including one of the words
157
+ &rsquo;flour&rsquo;, &rsquo;liquid&rsquo;, or
151
158
  &rsquo;additive&rsquo; in the line.</p>
152
159
 
160
+ <p style="margin-left:11%; margin-top: 1em">Here is a brief
161
+ example (note that github displays the indenting
162
+ incorrectly):</p>
163
+
164
+ <p style="margin-left:17%; margin-top: 1em">name: imaginary
165
+ bread <br>
166
+ notes: This is a silly fake bread recipe <br>
167
+ makes: 1 bad loaf <br>
168
+ This line will become part of the notes <br>
169
+ --------------------- <br>
170
+ Mix:</p>
171
+
172
+ <p style="margin-left:23%;">500 g flour <br>
173
+ 300 g water</p>
174
+
175
+ <p style="margin-left:17%; margin-top: 1em">Bake at
176
+ 375&deg;</p>
177
+
153
178
  <h2>SEE ALSO
154
179
  <a name="SEE ALSO"></a>
155
180
  </h2>
156
181
 
157
182
 
158
- <p style="margin-left:11%; margin-top: 1em"><i>ruby(1) <br>
183
+ <p style="margin-left:11%; margin-top: 1em"><b>ruby(1)</b>
184
+ <i><br>
159
185
  http://en.wikipedia.org/wiki/Baker%27s_percentage <br>
160
186
  http://rubygems.org/gems/bread_calculator</i></p>
161
187
 
data/bin/bread-calc CHANGED
@@ -3,12 +3,19 @@
3
3
  require 'bread_calculator'
4
4
  #require "#{File.dirname(__FILE__)}/../lib/bread_calculator"
5
5
 
6
+ def htm_header
7
+ puts '<head>'
8
+ puts ' <meta charset="UTF-8">'
9
+ puts '</head>'
10
+ end
11
+
6
12
  def help status=true
7
13
  puts <<EOF
8
14
  USAGE: bread-calc [OPTIONS] [FILE]
9
15
  where OPTIONS are any of:
10
16
  --help
11
17
  --summary
18
+ --html
12
19
  --weight
13
20
  --scale-by FACTOR
14
21
 
@@ -29,6 +36,7 @@ end
29
36
  loop { case ARGV[0]
30
37
  when /--help/ then @help = 'help' ; ARGV.shift; break
31
38
  when /--summary/ then @get = 'r.summary'; ARGV.shift
39
+ when /--html/ then @get = 'r.to_html'; ARGV.shift
32
40
  when /--weight/ then @get = 'r.weight'; ARGV.shift
33
41
  #.to_f protects against 'no .<digit> floating literal anymore' for .33
34
42
  when /--scale-by/ then ARGV.shift; @get = "r.scale_by #{ARGV.shift.to_f}"
@@ -41,5 +49,6 @@ help if @help
41
49
 
42
50
  parser = BreadCalculator::Parser.new
43
51
  r = parser.parse ARGF.file
52
+ htm_header if @get.include? 'html'
44
53
  puts eval("#{@get}")
45
54
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'bread_calculator'
3
- s.version = '0.2.1'
3
+ s.version = '0.3.0'
4
4
  s.date = '2014-03-11'
5
5
  s.summary = "calculate baker's percentages"
6
6
  s.description = "a gem and command-line wrapper to generate baker's
@@ -3,6 +3,8 @@
3
3
 
4
4
  module BreadCalculator
5
5
 
6
+ require 'cgi'
7
+
6
8
  ##
7
9
  # This class represents an ingredient in a Recipe
8
10
 
@@ -52,6 +54,14 @@ module BreadCalculator
52
54
  f_quantity = sprintf "%.#{precision}f", @quantity
53
55
  "\t#{f_quantity} #{@units} #{@name}\n"
54
56
  end
57
+
58
+ ##
59
+ # Print ingredient as an html unordered list item
60
+
61
+ def to_html
62
+ " <li>#{CGI.escapeHTML(self.to_s.strip.chomp)}</li>\n"
63
+ end
64
+
55
65
  end
56
66
 
57
67
  ##
@@ -94,6 +104,19 @@ module BreadCalculator
94
104
  out << "\n"
95
105
  out
96
106
  end
107
+
108
+ ##
109
+ # Print Step as an html paragraph
110
+
111
+ def to_html
112
+ out = "<p>\n"
113
+ self.techniques.each do |t|
114
+ tmp = t.is_a?(Ingredient) ? t.to_html : "#{CGI.escapeHTML(t.chomp)}"
115
+ out << tmp
116
+ end
117
+ out << "\n</p>\n"
118
+ out
119
+ end
97
120
  end
98
121
 
99
122
  ##
@@ -205,6 +228,18 @@ module BreadCalculator
205
228
  out
206
229
  end
207
230
 
231
+ ##
232
+ # Print recipe as html.
233
+ # It is the caller's responsibility to provide appropriate headers, etc.
234
+
235
+ def to_html
236
+ out = ''
237
+ self.metadata.each{|k,v| out << "<p>\n<b>#{k}</b>: #{v}\n</p>\n"}
238
+ out << "--------------------\n"
239
+ self.steps.each{|s| out << s.to_html }
240
+ out
241
+ end
242
+
208
243
  end
209
244
 
210
245
  ##
@@ -62,6 +62,10 @@ describe BreadCalculator do
62
62
  @recipe.bakers_percent_formula.total_flours.should eq 100.0
63
63
  end
64
64
 
65
+ it 'generates html' do
66
+ @recipe.to_html.include?('<').should be_true
67
+ end
68
+
65
69
  end
66
70
 
67
71
  describe BreadCalculator::Parser 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.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Birnel