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.
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
.all ⇒ Object
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_json ⇒ Object
47 48 49 |
# File 'lib/betterlog/log/severity.rb', line 47 def as_json(*) to_s end |
#eql?(other) ⇒ Boolean Also known as: ==
55 56 57 |
# File 'lib/betterlog/log/severity.rb', line 55 def eql?(other) to_sym == other.to_sym end |
#hash ⇒ Object
61 62 63 |
# File 'lib/betterlog/log/severity.rb', line 61 def hash @name.hash end |
#to_i ⇒ Object
35 36 37 |
# File 'lib/betterlog/log/severity.rb', line 35 def to_i @level end |
#to_s ⇒ Object
39 40 41 |
# File 'lib/betterlog/log/severity.rb', line 39 def to_s @name.to_s.upcase end |
#to_sym ⇒ Object
43 44 45 |
# File 'lib/betterlog/log/severity.rb', line 43 def to_sym @name end |