Sha256: c0c240a8d95e91db36526a0baca63aed1c1a1b409e831b6a2c92f0381452bc11

Contents?: true

Size: 822 Bytes

Versions: 11

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

module Facter
  module Resolvers
    module Utils
      module UptimeHelper
        class << self
          def create_uptime_hash(seconds)
            results = {}
            minutes = (seconds / 60) % 60

            results[:seconds] = seconds
            results[:hours]   = seconds / (60 * 60)
            results[:days]    = results[:hours] / 24
            results[:uptime]  = build_uptime_text(results[:days], results[:hours], minutes)

            results
          end

          def build_uptime_text(days, hours, minutes)
            case days
            when 0 then "#{hours}:#{format('%<minutes>02d', minutes: minutes)} hours"
            when 1 then '1 day'
            else
              "#{days} days"
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
facter-4.0.46 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.44 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.43 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.42 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.41 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.40 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.39 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.38 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.37 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.36 lib/facter/resolvers/utils/uptime_helper.rb
facter-4.0.35 lib/facter/resolvers/utils/uptime_helper.rb