Class: CutePrint::Formatter Private

Inherits:
Object show all
Defined in:
lib/cute_print/formatter.rb

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

Constant Summary collapse

DEFAULT_WIDTH =

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

79

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Formatter

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.

Returns a new instance of Formatter.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cute_print/formatter.rb', line 16

def initialize(opts = {})
  @method = opts.fetch(:method)
  @out = opts.fetch(:out)
  @block = opts.fetch(:block, nil)
  @values = opts.fetch(:values, [])
  @width = opts.fetch(:width, DEFAULT_WIDTH)
  if @block && !@values.empty?
    raise ArgumentError, "arguments and block are mutually exclusive"
  end
  @location_label = nil
end

Instance Method Details

#inspectObject

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.



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

def inspect
  @format = Format::Inspect.new
end

#pretty_printObject

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.



48
49
50
# File 'lib/cute_print/formatter.rb', line 48

def pretty_print
  @format = Format::PrettyPrint.new
end

#with_location(format_key) ⇒ Object

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.



39
40
41
42
# File 'lib/cute_print/formatter.rb', line 39

def with_location(format_key)
  location = Location.find
  @location_label = LocationLabel.make(format_key, location)
end

#writeObject

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.



28
29
30
31
32
33
34
35
36
37
# File 'lib/cute_print/formatter.rb', line 28

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