Class: Cch::Loggers::Level

Inherits:
Object
  • Object
show all
Defined in:
lib/cch/loggers/level.rb

Constant Summary collapse

LEVELS =
[:debug, :info, :warning, :error].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Level

Returns a new instance of Level.


16
17
18
# File 'lib/cch/loggers/level.rb', line 16

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


14
15
16
# File 'lib/cch/loggers/level.rb', line 14

def name
  @name
end

Class Method Details

.allObject


6
7
8
9
10
11
12
# File 'lib/cch/loggers/level.rb', line 6

def self.all
  return @levels if @levels

  @levels = {}
  LEVELS.each { |level| @levels[level] = new(level) }
  @levels
end

Instance Method Details

#allowed?(threshold) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/cch/loggers/level.rb', line 20

def allowed?(threshold)
  LEVELS.index(threshold) <= LEVELS.index(name)
end

#to_sObject


24
25
26
# File 'lib/cch/loggers/level.rb', line 24

def to_s
  name.to_s.upcase.color(color)
end