Sha256: edae9c4837bf600c586d09e3726dba536ba8b0fe2629e79d209ea7aaa3f411f1

Contents?: true

Size: 966 Bytes

Versions: 131

Compression:

Stored size: 966 Bytes

Contents

module RSpec
  module Core
    module Formatters

      module Helpers
        SUB_SECOND_PRECISION = 5
        DEFAULT_PRECISION = 2

        def format_duration(duration)
          if duration > 60
            minutes = duration.to_i / 60
            seconds = duration - minutes * 60

            "#{pluralize(minutes, 'minute')} #{format_seconds(seconds)} seconds"
          else
            "#{format_seconds(duration)} seconds"
          end
        end

        def format_seconds(float)
          precision ||= (float < 1) ? SUB_SECOND_PRECISION : DEFAULT_PRECISION
          formatted = sprintf("%.#{precision}f", float)
          strip_trailing_zeroes(formatted)
        end

        def strip_trailing_zeroes(string)
          stripped = string.sub(/[^1-9]+$/, '')
          stripped.empty? ? "0" : stripped
        end

        def pluralize(count, string)
          "#{count} #{string}#{'s' unless count == 1}"
        end

      end

    end
  end
end

Version data entries

131 entries across 79 versions & 13 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
tnargav-1.3.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/formatters/helpers.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-core-2.10.1/lib/rspec/core/formatters/helpers.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.9.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-core-2.10.0/lib/rspec/core/formatters/helpers.rb