Module: WrappedPrint::Main

Defined in:
lib/wrapped_print.rb

Constant Summary collapse

COLORS =
[:none, :red, :green, :dark_blue, :dark_green, :yellow, :blue, :pur]
PATTERN =
"-"
COUNT =
80

Instance Method Summary collapse

Instance Method Details

#wp(label = nil, pattern: PATTERN, count: COUNT, prefix: nil, suffix: nil, color: nil) ⇒ Object Also known as: __wp__



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/wrapped_print.rb', line 30

def wp(label = nil, pattern: PATTERN, count: COUNT, prefix: nil, suffix: nil, color: nil)
  line          = pattern * count
  color_method  = detect_color_method(color)
  logger_method = detect_logger_method

  if block_given?
    result = yield
    result.tap do
      logger_method.call color_method.call "#{prefix}#{line}"
      logger_method.call color_method.call "#{label}#{result}"
      logger_method.call color_method.call "#{line}#{suffix}"
    end
  else
    self.tap do
      logger_method.call color_method.call "#{prefix}#{line}"
      logger_method.call color_method.call "#{label}#{self}"
      logger_method.call color_method.call "#{line}#{suffix}"
    end
  end
end