Sha256: 9aceb2aeaebef001f2fea0d88157deb4db97704c7d5b2e098bb99cc1b7539601

Contents?: true

Size: 912 Bytes

Versions: 8

Compression:

Stored size: 912 Bytes

Contents

require "petitest/texts/base_text"

module Petitest
  module Texts
    class TimesText < ::Petitest::Texts::BaseText
      # @return [Time]
      attr_reader :finished_at

      # @return [Time]
      attr_reader :started_at

      # @param finished_at [Time]
      # @param started_at [Time]
      def initialize(
        finished_at:,
        started_at:
      )
        @finished_at = finished_at
        @started_at = started_at
      end

      # @note Override
      def to_s
        [
          heading,
          indent(body, 2),
        ].join("\n\n")
      end

      private

      # @return [String]
      def body
        [
          "Started:  #{started_at.iso8601(6)}",
          "Finished: #{finished_at.iso8601(6)}",
          "Total:    %.6fs" % (finished_at - started_at),
        ].join("\n")
      end

      # @return [String]
      def heading
        "Times:"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
petitest-0.3.1 lib/petitest/texts/times_text.rb
petitest-0.3.0 lib/petitest/texts/times_text.rb
petitest-0.2.1 lib/petitest/texts/times_text.rb
petitest-0.2.0 lib/petitest/texts/times_text.rb
petitest-0.1.3 lib/petitest/texts/times_text.rb
petitest-0.1.2 lib/petitest/texts/times_text.rb
petitest-0.1.1 lib/petitest/texts/times_text.rb
petitest-0.1.0 lib/petitest/texts/times_text.rb