Class: Empezar::EchoingFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/empezar/echoing_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wrapee, stdout) ⇒ EchoingFormatter

Returns a new instance of EchoingFormatter.



5
6
7
8
# File 'lib/empezar/echoing_formatter.rb', line 5

def initialize wrapee, stdout
  @wrapee = wrapee
  @stdout = stdout
end

Instance Attribute Details

#stdoutObject

Returns the value of attribute stdout.



3
4
5
# File 'lib/empezar/echoing_formatter.rb', line 3

def stdout
  @stdout
end

#wrapeeObject

Returns the value of attribute wrapee.



3
4
5
# File 'lib/empezar/echoing_formatter.rb', line 3

def wrapee
  @wrapee
end

Instance Method Details

#call(severity, datetime, progname, message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/empezar/echoing_formatter.rb', line 10

def call severity, datetime, progname, message
  case severity
    when Logger::Severity::FATAL, "FATAL"
      @stdout.puts Term::ANSIColor.bold Term::ANSIColor.red message
    when Logger::Severity::ERROR, "ERROR"
      @stdout.puts Term::ANSIColor.red message
    when Logger::Severity::WARN, "WARN"
      @stdout.puts Term::ANSIColor.yellow message
    when Logger::Severity::INFO, "INFO"
      @stdout.puts Term::ANSIColor.blue message
    when Logger::Severity::DEBUG, "DEBUG"
      @stdout.puts Term::ANSIColor.dark message
    when Logger::Severity::UNKNOWN, "UNKNOWN"
      @stdout.puts message
  end

  wrapee.call severity, datetime, progname, message
end