Sha256: 801e0aa4535e126ef30f5b6ce3e9535a81564e26feac97601849311463bd9f97

Contents?: true

Size: 1.23 KB

Versions: 62

Compression:

Stored size: 1.23 KB

Contents

module Sapience
  module Formatters
    class Base
      attr_accessor :time_format, :precision, :log_host, :log_application

      # Parameters
      #   time_format: [String|Symbol|nil]
      #     See Time#strftime for the format of this string
      #     :iso_8601 Outputs an ISO8601 Formatted timestamp
      #     nil:      Returns Empty string for time ( no time is output ).
      #     Default: '%Y-%m-%d %H:%M:%S.%6N'
      def initialize(options = {})
        options          = options.dup
        @precision       = 6
        default_format   = "%Y-%m-%d %H:%M:%S.%#{precision}N"
        @time_format     = options.key?(:time_format) ? options.delete(:time_format) : default_format
        @log_host        = options.key?(:log_host) ? options.delete(:log_host) : true
        @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
        fail(ArgumentError, "Unknown options: #{options.inspect}") if options.size > 0
      end

      # Return the Time as a formatted string
      def format_time(time)
        case time_format
        when :iso_8601
          time.utc.iso8601(precision)
        when nil
          ""
        else
          time.strftime(time_format)
        end
      end

    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
sapience-2.4.0 lib/sapience/formatters/base.rb
sapience-2.3.5 lib/sapience/formatters/base.rb
sapience-2.3.4 lib/sapience/formatters/base.rb
sapience-2.3.3 lib/sapience/formatters/base.rb
sapience-2.2.3 lib/sapience/formatters/base.rb
sapience-2.2.1 lib/sapience/formatters/base.rb
sapience-2.2.0 lib/sapience/formatters/base.rb
sapience-2.1.0 lib/sapience/formatters/base.rb
sapience-2.0.5 lib/sapience/formatters/base.rb
sapience-2.0.4 lib/sapience/formatters/base.rb
sapience-2.0.3 lib/sapience/formatters/base.rb
sapience-2.0.2 lib/sapience/formatters/base.rb
sapience-2.0.1 lib/sapience/formatters/base.rb
sapience-2.0.0 lib/sapience/formatters/base.rb
sapience-1.0.15 lib/sapience/formatters/base.rb
sapience-1.0.14 lib/sapience/formatters/base.rb
sapience-1.0.13 lib/sapience/formatters/base.rb
sapience-1.0.12 lib/sapience/formatters/base.rb
sapience-1.0.11 lib/sapience/formatters/base.rb
sapience-1.0.10 lib/sapience/formatters/base.rb