Class: CutePrint::Printer

Inherits:
Object show all
Includes:
FindsForeignCaller
Defined in:
lib/cute_print/printer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FindsForeignCaller

#lib_path, #nearest_foreign_caller

Constructor Details

#initialize(attrs = {}) ⇒ Printer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

CutePrint.new(:out => $stdout)


44
45
46
47
# File 'lib/cute_print/printer.rb', line 44

def initialize(attrs = {})
  set_defaults
  attrs.each { |name, value| send "#{name}=", value }
end

Instance Attribute Details

#location_formatString

The location format. Defaults to :filename

One of:

  • :filename

  • :path

Returns:

  • (String)


21
22
23
# File 'lib/cute_print/printer.rb', line 21

def location_format
  @location_format
end

#out#print

The object to write to. Defaults to $stderr.

Returns:

  • (#print)


12
13
14
# File 'lib/cute_print/printer.rb', line 12

def out
  @out
end

#term_widthObject

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



30
31
32
# File 'lib/cute_print/printer.rb', line 30

def term_width
  @term_width.visible
end

Instance Method Details

#q(*values, &block) ⇒ Object

See Also:



57
58
59
60
61
62
# 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) ⇒ Object

See Also:



65
66
67
68
69
70
71
# 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) ⇒ Object

See Also:



74
75
76
77
78
79
# 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) ⇒ Object

See Also:



82
83
84
85
86
87
88
# 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_defaultsObject

Set all attributes to their defaults.



50
51
52
53
54
# File 'lib/cute_print/printer.rb', line 50

def set_defaults
  @out = StderrOut.new
  @location_format = :filename
  self.term_width = :detect
end