class CutePrint::Printer

Attributes

location_format[RW]

The location format. Defaults to :filename

One of:

  • :filename

  • :path

@return [String]

out[RW]

The object to write to. Defaults to $stderr. @return [#print]

Public Class Methods

new(attrs = {}) click to toggle source

Create an instance. If attributes are supplied, they override the defaults. For example:

CutePrint.new(:out => $stdout)

@api private

# File lib/cute_print/printer.rb, line 44
def initialize(attrs = {})
  set_defaults
  attrs.each { |name, value| send "#{name}=", value }
end

Public Instance Methods

q(*values, &block) click to toggle source

@see CutePrint.q

# File lib/cute_print/printer.rb, line 57
def q(*values, &block)
  formatter = make_formatter(__method__, values, block)
  formatter.inspect
  formatter.write
  nil
end
ql(*values, &block) click to toggle source

@see CutePrint.ql

# File lib/cute_print/printer.rb, line 65
def ql(*values, &block)
  formatter = make_formatter(__method__, values, block)
  formatter.inspect
  formatter.with_location @location_format
  formatter.write
  nil
end
qq(*values, &block) click to toggle source

@see CutePrint.qq

# File lib/cute_print/printer.rb, line 74
def qq(*values, &block)
  formatter = make_formatter(__method__, values, block)
  formatter.pretty_print
  formatter.write
  nil
end
qql(*values, &block) click to toggle source

@see CutePrint.qql

# File lib/cute_print/printer.rb, line 82
def qql(*values, &block)
  formatter = make_formatter(__method__, values, block)
  formatter.pretty_print
  formatter.with_location @location_format
  formatter.write
  nil
end
set_defaults() click to toggle source

Set all attributes to their defaults.

# File lib/cute_print/printer.rb, line 50
def set_defaults
  @out = StderrOut.new
  @location_format = :filename
  self.term_width = :detect
end
term_width() click to toggle source

The terminal width. May be an integer, or :detect to cause the terminal width to be determined automatically. Defaults to :detect

@!attribute [rw] term_width

@return [Integer, Symbol]
# File lib/cute_print/printer.rb, line 30
def term_width
  @term_width.visible
end
term_width=(value) click to toggle source
# File lib/cute_print/printer.rb, line 34
def term_width=(value)
  @term_width = TermWidth.make(value)
end

Private Instance Methods

make_formatter(method, values, block) click to toggle source
# File lib/cute_print/printer.rb, line 92
def make_formatter(method, values, block)
  Formatter.new(
    method: method,
    block: block,
    values: values,
    out: @out,
    width: @term_width.width)
end