Class: PrettyPrint::Breakable

Inherits:
Object
  • Object
show all
Defined in:
lib/extensions/mspec/mspec/pp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sep, width, q) ⇒ Breakable

Returns a new instance of Breakable.



305
306
307
308
309
310
311
312
# File 'lib/extensions/mspec/mspec/pp.rb', line 305

def initialize(sep, width, q)
  @obj = sep
  @width = width
  @pp = q
  @indent = q.indent
  @group = q.current_group
  @group.breakables.push self
end

Instance Attribute Details

#indentObject (readonly)

Returns the value of attribute indent.



313
314
315
# File 'lib/extensions/mspec/mspec/pp.rb', line 313

def indent
  @indent
end

#objObject (readonly)

Returns the value of attribute obj.



313
314
315
# File 'lib/extensions/mspec/mspec/pp.rb', line 313

def obj
  @obj
end

#widthObject (readonly)

Returns the value of attribute width.



313
314
315
# File 'lib/extensions/mspec/mspec/pp.rb', line 313

def width
  @width
end

Instance Method Details

#output(out, output_width) ⇒ Object



315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/extensions/mspec/mspec/pp.rb', line 315

def output(out, output_width)
  @group.breakables.shift
  if @group.break?
    out << @pp.newline
    out << @pp.genspace.call(@indent)
    @indent
  else
    @pp.group_queue.delete @group if @group.breakables.empty?
    out << @obj
    output_width + @width
  end
end