Class: Travis::Tools::Formatter
- Inherits:
-
Object
- Object
- Travis::Tools::Formatter
- Defined in:
- lib/travis/tools/formatter.rb
Constant Summary collapse
- DAY =
24 * 60 * 60
- TIME_FORMAT =
'%Y-%m-%d %H:%M:%S'
- CONFIG_KEYS =
%w[rvm gemfile env jdk otp_release php node_js perl python scala compiler os].freeze
Instance Method Summary collapse
- #duration(seconds, suffix = nil) ⇒ Object
- #file_size(input, human: true) ⇒ Object
- #job_config(config) ⇒ Object
- #time(time) ⇒ Object
Instance Method Details
#duration(seconds, suffix = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/travis/tools/formatter.rb', line 13 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.positive? output << "#{minutes} min" if minutes.positive? output << "#{seconds} sec" if seconds.positive? || output.empty? output << suffix if suffix output.join(' ') end |
#file_size(input, human: true) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/travis/tools/formatter.rb', line 27 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 && (input > 512) && iec.any? input /= 1024.0 format = iec.shift end input = input.round(2) if input.is_a? Float "#{input} #{format}" end |
#job_config(config) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/travis/tools/formatter.rb', line 47 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) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/travis/tools/formatter.rb', line 40 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 |