Class: Loki::Logger
Constant Summary collapse
- COLORS =
{ :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37, :r => 31, :g => 32, :y => 33, :b => 34, :m => 35, :c => 36, :w => 37 }
Instance Method Summary collapse
- #indented? ⇒ Boolean
-
#initialize ⇒ Logger
constructor
A new instance of Logger.
- #line ⇒ Object
- #paint(text, color = :white) ⇒ Object
- #parse(text) ⇒ Object
- #pull ⇒ Object
- #push ⇒ Object
- #puts(text, mark = ">") ⇒ Object
Constructor Details
#initialize ⇒ Logger
Returns a new instance of Logger.
24 25 26 |
# File 'lib/loki/logger.rb', line 24 def initialize @indent = 0 end |
Instance Method Details
#indented? ⇒ Boolean
29 30 31 |
# File 'lib/loki/logger.rb', line 29 def indented? @indent > 0 end |
#line ⇒ Object
49 50 51 |
# File 'lib/loki/logger.rb', line 49 def line $stdout.puts("-" * 80) if @indent == 0 end |
#paint(text, color = :white) ⇒ Object
56 57 58 |
# File 'lib/loki/logger.rb', line 56 def paint(text, color = :white) "\e[#{COLORS[color]}m#{text}\e[0m" end |
#parse(text) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/loki/logger.rb', line 61 def parse(text) colors = COLORS.keys.collect(&:to_s).join('|') text.gsub(/\<(#{colors})\>(.*)\<\/\1\>/) do paint($2, $1.to_sym) end end |
#pull ⇒ Object
39 40 41 |
# File 'lib/loki/logger.rb', line 39 def pull @indent -= 1 end |
#push ⇒ Object
34 35 36 |
# File 'lib/loki/logger.rb', line 34 def push @indent += 1 end |
#puts(text, mark = ">") ⇒ Object
44 45 46 |
# File 'lib/loki/logger.rb', line 44 def puts(text, mark = ">") $stdout.puts((" " * @indent * 2) + "#{mark} #{parse(text)}") end |