Class: DumbWriter

Inherits:
NullWriter show all
Defined in:
lib/formatter.rb

Instance Method Summary collapse

Methods inherited from NullWriter

#flush, #new_alignment, #new_font, #new_margin, #new_spacing, #new_styles, #send_label_data

Constructor Details

#initialize(file = STDOUT, maxcol = 72) ⇒ DumbWriter

Returns a new instance of DumbWriter.



247
248
249
250
251
252
# File 'lib/formatter.rb', line 247

def initialize(file=STDOUT, maxcol=72)
  @file = file
  @maxcol = maxcol
  super()
  reset
end

Instance Method Details

#resetObject



254
255
256
257
# File 'lib/formatter.rb', line 254

def reset
  @col = 0
  @atbreak = false
end

#send_flowing_data(data) ⇒ Object



291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/formatter.rb', line 291

def send_flowing_data(data)
  return if not data
  atbreak = (@atbreak || (/^\s/ =~ data))
  col = @col
  maxcol = @maxcol
  for word in data.split
    if atbreak
      if col + word.length >= maxcol
        @file.write("\n")
        col = 0
      else
        @file.write(' ')
        col = col + 1
      end
    end
    @file.write(word)
    col = col + word.length
    atbreak = true
  end
  @col = col
  @atbreak = (/\s$/ =~ data)
end

#send_hor_ruleObject

(*args, **kw)



271
272
273
274
275
276
277
# File 'lib/formatter.rb', line 271

def send_hor_rule #(*args, **kw)
  @file.write("\n")
  @file.write('-'*@maxcol)
  @file.write("\n")
  @col = 0
  @atbreak = false
end

#send_line_breakObject



265
266
267
268
269
# File 'lib/formatter.rb', line 265

def send_line_break
  @file.write("\n")
  @col = 0
  @atbreak = false
end

#send_literal_data(data) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
# File 'lib/formatter.rb', line 279

def send_literal_data(data)
  @file.write(data)
  i = data.rindex("\n")
  if i
    @col = 0
    data = data[i+1..-1]
    #data = string.expandtabs(data)
    @col = @col + data.length
    @atbreak = false
  end
end

#send_paragraph(blankline) ⇒ Object



259
260
261
262
263
# File 'lib/formatter.rb', line 259

def send_paragraph(blankline)
  @file.write("\n" + "\n"*blankline)
  @col = 0
  @atbreak = false
end