Sha256: 7e5582b9fc74ff2571e2a5a79f71cf7c8632b6fc2c2e018bca5fd610e5c98297

Contents?: true

Size: 687 Bytes

Versions: 2

Compression:

Stored size: 687 Bytes

Contents

# frozen_string_literal: true

module WSDirector
  module Ext
    # Extend Object through refinements
    module Formatting
      refine ::Object do
        def truncate(*) ;  itself; end
      end

      refine ::String do
        def truncate(limit)
          return self if size <= limit

          "#{self[0..(limit - 3)]}..."
        end
      end

      refine ::Hash do
        def truncate(limit)
          str = to_json

          str.truncate(limit)
        end
      end

      refine ::Float do
        def duration
          if self > 1
            "#{truncate(2)}s"
          else
            "#{(self * 1000).to_i}ms"
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wsdirector-core-1.0.3 lib/.rbnext/3.0/wsdirector/ext/formatting.rb
wsdirector-core-1.0.2 lib/.rbnext/3.0/wsdirector/ext/formatting.rb