Sha256: 3c52830e0452d9a907081d17faca7cfab0c6b6cc0f37ff1f27ec5c76d3d9e10d

Contents?: true

Size: 817 Bytes

Versions: 5

Compression:

Stored size: 817 Bytes

Contents

# typed: true
# frozen_string_literal: true

require 'sorbet-runtime'

module Frontman
  module Toolbox
    class Timer
      extend T::Sig

      sig { returns(Frontman::Toolbox::Timer) }
      def self.start
        timer = new
        timer.begin
        timer
      end

      sig { returns(Time) }
      def begin
        @start = Time.now
      end

      sig { returns(Time) }
      def stop
        @end = Time.now
      end

      sig { returns(Float) }
      def diff
        @end - @start
      end

      sig { returns(T.nilable(Time)) }
      def started_at
        @start
      end

      sig { returns(T.nilable(Time)) }
      def ended_at
        @end
      end

      sig { returns(String) }
      def output
        "Elapsed time: ~#{(diff * 1000).ceil} milliseconds.\n"
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
frontman-ssg-0.1.1 lib/frontman/toolbox/timer.rb
frontman-ssg-0.1.0 lib/frontman/toolbox/timer.rb
frontman-ssg-0.0.4 lib/frontman/toolbox/timer.rb
frontman-ssg-0.0.3 lib/frontman/toolbox/timer.rb
frontman-ssg-0.0.2 lib/frontman/toolbox/timer.rb