Class: Logue::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/logue/writer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: $stdout, colors: Array.new, colorize_line: false) ⇒ Writer

Returns a new instance of Writer.



10
11
12
13
14
# File 'lib/logue/writer.rb', line 10

def initialize output: $stdout, colors: Array.new, colorize_line: false
  @output        = output
  @colors        = colors
  @colorize_line = colorize_line
end

Instance Attribute Details

#colorize_lineObject

Returns the value of attribute colorize_line.



8
9
10
# File 'lib/logue/writer.rb', line 8

def colorize_line
  @colorize_line
end

#colorsObject

Returns the value of attribute colors.



7
8
9
# File 'lib/logue/writer.rb', line 7

def colors
  @colors
end

#outputObject

Returns the value of attribute output.



6
7
8
# File 'lib/logue/writer.rb', line 6

def output
  @output
end

Instance Method Details

#line(location, msg, lvl) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/logue/writer.rb', line 21

def line location, msg, lvl
  if lvlcol = @colors[lvl]
    if @colorize_line
      line = location + " " + msg
      line.color lvlcol
    else
      location + " " + msg.color(lvlcol)
    end
  else
    location + " " + msg
  end
end


16
17
18
19
# File 'lib/logue/writer.rb', line 16

def print lstr, lvl
  str = lvlcol = @colors[lvl] ? lstr.color(lvlcol) : lstr
  @output.puts str
end