Sha256: 64120dc9e6303b48fc290568fdbbcaf59f4b320e06a6e7e3a143173727016f6f

Contents?: true

Size: 830 Bytes

Versions: 7

Compression:

Stored size: 830 Bytes

Contents

module Betterlog
  class Log
    class Severity
      include Comparable

      def initialize(name)
        @name = name.to_s.downcase.to_sym
        begin
          @level = Logger::Severity.const_get(@name.upcase)
        rescue NameError
          @name  = :UNKNOWN
          @level = Logger::Severity::UNKNOWN
        end
      end

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

      def to_i
        @level
      end

      def to_s
        @name.to_s.upcase
      end

      def to_sym
        @name
      end

      def as_json(*)
        to_sym
      end

      def <=>(other)
        to_i <=> other.to_i
      end

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

      alias == eql?

      def hash
        @name.hash
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
betterlog-0.6.1 lib/betterlog/log/severity.rb
betterlog-0.5.0 lib/betterlog/log/severity.rb
betterlog-0.4.0 lib/betterlog/log/severity.rb
betterlog-0.3.0 lib/betterlog/log/severity.rb
betterlog-0.2.2 lib/betterlog/log/severity.rb
betterlog-0.2.1 lib/betterlog/log/severity.rb
betterlog-0.2.0 lib/betterlog/log/severity.rb