class CutePrint::Formatter

@api private

Public Class Methods

new(opts = {}) click to toggle source
# File lib/cute_print/formatter.rb, line 15
def initialize(opts = {})
  @method = opts.fetch(:method)
  @out = opts.fetch(:out)
  @block = opts.fetch(:block, nil)
  @args = opts.fetch(:values, [])
  @values = Values.new(@args, @block)
  @width = opts.fetch(:width)
  @location_label = nil
end

Public Instance Methods

inspect() click to toggle source
# File lib/cute_print/formatter.rb, line 41
def inspect
  @format = Format::Inspect.new
end
pretty_print() click to toggle source
# File lib/cute_print/formatter.rb, line 45
def pretty_print
  @format = Format::PrettyPrint.new
end
with_location(format_key) click to toggle source
# File lib/cute_print/formatter.rb, line 36
def with_location(format_key)
  location = Location.find
  @location_label = LocationLabel.make(format_key, location)
end
write() click to toggle source
# File lib/cute_print/formatter.rb, line 25
def write
  if @values.empty? && !label.empty?
    write_line label.chomp(": ")
  else
    @values.each do |value|
      labeler = Labeler.new(@format, @width, label, value)
      write_lines labeler.labeled
    end
  end
end

Private Instance Methods

label() click to toggle source
# File lib/cute_print/formatter.rb, line 62
def label
  @label ||= make_label
end
make_label() click to toggle source
# File lib/cute_print/formatter.rb, line 66
def make_label
  [
    (@location_label.to_s if @location_label),
    (SourceLabel.new(@block, @method) if @block),
  ].compact.join
end
write_line(line) click to toggle source
# File lib/cute_print/formatter.rb, line 57
def write_line(line)
  line += "\n" unless line =~ /\n\Z/
  @out.print line
end
write_lines(lines) click to toggle source
# File lib/cute_print/formatter.rb, line 51
def write_lines(lines)
  lines.each do |line|
    write_line line
  end
end