Class: Betterlog::Log::Severity
- Inherits:
-
Object
- Object
- Betterlog::Log::Severity
- Includes:
- Comparable, Logger::Severity
- Defined in:
- lib/betterlog/log/severity.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #as_json ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
- #hash ⇒ Object
-
#initialize(name) ⇒ Severity
constructor
A new instance of Severity.
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
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
.all ⇒ Object
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_json ⇒ Object
46 47 48 |
# File 'lib/betterlog/log/severity.rb', line 46 def as_json(*) to_sym end |
#eql?(other) ⇒ Boolean Also known as: ==
54 55 56 |
# File 'lib/betterlog/log/severity.rb', line 54 def eql?(other) to_sym == other.to_sym end |
#hash ⇒ Object
60 61 62 |
# File 'lib/betterlog/log/severity.rb', line 60 def hash @name.hash end |
#to_i ⇒ Object
34 35 36 |
# File 'lib/betterlog/log/severity.rb', line 34 def to_i @level end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/betterlog/log/severity.rb', line 38 def to_s @name.to_s.upcase end |
#to_sym ⇒ Object
42 43 44 |
# File 'lib/betterlog/log/severity.rb', line 42 def to_sym @name end |