Sha256: 9179a703d2dddee9c660961ef480ffdf64bdacec8ff14c0f78c4a0c8532476d9

Contents?: true

Size: 590 Bytes

Versions: 35

Compression:

Stored size: 590 Bytes

Contents

require "time"

module ProconBypassMan
  class Uptime
    # @return [Integer]
    def self.from_boot
      new(uptime_cmd_result: `uptime -s`.chomp).from_boot
    end

    # @param [String] uptime_cmd_result
    def initialize(uptime_cmd_result: )
      @result = uptime_cmd_result
    end

    # @return [Integer]
    def from_boot
      return -1 if @result == '' # darwin系だとsオプションが使えない
      boot_time = Time.parse(@result).to_i
      return Time.now.to_i - boot_time.to_i
    rescue => e
      ProconBypassMan.logger.error(e)
      return -1
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.2.2 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/support/uptime.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/support/uptime.rb