class Travis::Tools::Formatter
Constants
- CONFIG_KEYS
- DAY
- TIME_FORMAT
Public Instance Methods
duration(seconds, suffix = nil)
click to toggle source
# File lib/travis/tools/formatter.rb, line 10 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
file_size(input, human = true)
click to toggle source
# File lib/travis/tools/formatter.rb, line 23 def file_size(input, human = true) return "#{input} B" unless human format = "B" iec = %w[KiB MiB GiB TiB PiB EiB ZiB YiB] while human and input > 512 and iec.any? input /= 1024.0 format = iec.shift end input = input.round(2) if input.is_a? Float "#{input} #{format}" end
job_config(config)
click to toggle source
# File lib/travis/tools/formatter.rb, line 41 def job_config(config) output = [] config.each_pair do |key, value| output << "#{key}: #{value}" if CONFIG_KEYS.include? key end output.join(", ") end
time(time)
click to toggle source
# File lib/travis/tools/formatter.rb, line 35 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