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.



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

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

Class Method Details

.allObject



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

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

.new(name) ⇒ Object



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

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



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

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

#as_jsonObject



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

def as_json(*)
  to_s
end

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

Returns:

  • (Boolean)


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

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

#hashObject



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

def hash
  @name.hash
end

#to_iObject



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

def to_i
  @level
end

#to_sObject



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

def to_s
  @name.to_s.upcase
end

#to_symObject



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

def to_sym
  @name
end