Sha256: 4f20dd7d0e62573b62dd8b2c2547ca2c67ca594ddfa530fc52cd7f529bd39180

Contents?: true

Size: 821 Bytes

Versions: 39

Compression:

Stored size: 821 Bytes

Contents

# frozen_string_literal: true

module Facter
  module Util
    module Resolvers
      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

39 entries across 39 versions & 1 rubygems

Version Path
facter-4.10.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.9.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.8.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.7.1 lib/facter/util/resolvers/uptime_helper.rb
facter-4.7.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.6.1 lib/facter/util/resolvers/uptime_helper.rb
facter-4.6.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.5.2 lib/facter/util/resolvers/uptime_helper.rb
facter-4.5.1 lib/facter/util/resolvers/uptime_helper.rb
facter-4.5.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.4.3 lib/facter/util/resolvers/uptime_helper.rb
facter-4.4.2 lib/facter/util/resolvers/uptime_helper.rb
facter-4.4.1 lib/facter/util/resolvers/uptime_helper.rb
facter-4.4.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.3.1 lib/facter/util/resolvers/uptime_helper.rb
facter-4.3.0 lib/facter/util/resolvers/uptime_helper.rb
facter-4.2.14 lib/facter/util/resolvers/uptime_helper.rb
facter-4.2.13 lib/facter/util/resolvers/uptime_helper.rb
facter-4.2.12 lib/facter/util/resolvers/uptime_helper.rb
facter-4.2.11 lib/facter/util/resolvers/uptime_helper.rb