Class: Betterlog::Log::Severity

Inherits:
Object
  • Object
show all
Includes:
Comparable, Logger::Severity
Defined in:
lib/betterlog/log/severity.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Severity

Returns a new instance of Severity.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/betterlog/log/severity.rb', line 18

def initialize(name)
  name = name.to_sym if self.class === name
  name = name.to_s.upcase.to_sym
  @name = name
  begin
    @level = self.class.const_get(@name)
  rescue NameError
    @name  = :UNKNOWN
    @level = UNKNOWN
  end
end

Class Method Details

.allObject



30
31
32
# File 'lib/betterlog/log/severity.rb', line 30

def self.all
  @all_constants ||= constants.map { |c| new(c) }
end

.new(name) ⇒ Object



10
11
12
13
14
15
# File 'lib/betterlog/log/severity.rb', line 10

def new(name)
  name = name.to_sym if self.class === name
  name = name.to_s.upcase.to_sym
  self.shared ||= {}
  shared[name] ||= super(name).freeze
end

Instance Method Details

#<=>(other) ⇒ Object



50
51
52
# File 'lib/betterlog/log/severity.rb', line 50

def <=>(other)
  to_i <=> self.class.new(other).to_i
end

#as_jsonObject



46
47
48
# File 'lib/betterlog/log/severity.rb', line 46

def as_json(*)
  to_sym
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


54
55
56
# File 'lib/betterlog/log/severity.rb', line 54

def eql?(other)
  to_sym == other.to_sym
end

#hashObject



60
61
62
# File 'lib/betterlog/log/severity.rb', line 60

def hash
  @name.hash
end

#to_iObject



34
35
36
# File 'lib/betterlog/log/severity.rb', line 34

def to_i
  @level
end

#to_sObject



38
39
40
# File 'lib/betterlog/log/severity.rb', line 38

def to_s
  @name.to_s.upcase
end

#to_symObject



42
43
44
# File 'lib/betterlog/log/severity.rb', line 42

def to_sym
  @name
end