Sha256: c5c201d9770defb0f1c72541b2f2dbb018efdcf4580e720cf00c7031b37c8178

Contents?: true

Size: 1.18 KB

Versions: 54

Compression:

Stored size: 1.18 KB

Contents

require 'time'

module Travis
  module Tools
    class Formatter
      DAY         = 24 * 60 * 60
      TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
      CONFIG_KEYS = ['rvm', 'gemfile', 'env', 'jdk', 'otp_release', 'php', 'node_js', 'perl', 'python', 'scala', 'compiler']

      def duration(seconds, suffix = nil)
        return "none" if seconds.nil?
        seconds          = (Time.now - seconds).to_i if seconds.is_a? Time
        output           = []
        minutes, seconds = seconds.divmod(60)
        hours, minutes   = minutes.divmod(60)
        output << "#{hours  } hrs" if hours > 0
        output << "#{minutes} min" if minutes > 0
        output << "#{seconds} sec" if seconds > 0 or output.empty?
        output << suffix           if suffix
        output.join(" ")
      end

      def time(time)
        return "not yet" if time.nil? # or time > Time.now
        #return duration(time, "ago") if Time.now - time < DAY
        time.localtime.strftime(TIME_FORMAT)
      end

      def job_config(config)
        output = []
        config.each_pair do |key, value|
          output << "#{key}: #{value}" if CONFIG_KEYS.include? key
        end
        output.join(", ")
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
travis-1.5.9.travis.360.4 lib/travis/tools/formatter.rb
travis-1.5.9.travis.358.4 lib/travis/tools/formatter.rb
travis-1.5.8 lib/travis/tools/formatter.rb
travis-1.5.8.travis.356.4 lib/travis/tools/formatter.rb
travis-1.5.7 lib/travis/tools/formatter.rb
travis-1.5.7.travis.345.4 lib/travis/tools/formatter.rb
travis-1.5.7.travis.341.4 lib/travis/tools/formatter.rb
travis-1.5.7.travis.338.4 lib/travis/tools/formatter.rb
travis-1.5.6 lib/travis/tools/formatter.rb
travis-1.5.6.travis.337.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.336.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.333.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.332.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.330.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.329.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.326.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.324.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.323.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.320.4 lib/travis/tools/formatter.rb
travis-1.5.6.travis.319.4 lib/travis/tools/formatter.rb