Method: Unix::Exec#uptime_int

Defined in:
lib/beaker/host/unix/exec.rb

#uptime_int(uptime_str) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/beaker/host/unix/exec.rb', line 66

def uptime_int(uptime_str)
  time_array = uptime_str.split(", ")
  accumulated_mins = 0
  time_array.each do |time_segment|
    value, unit = time_segment.split
    if unit.nil?
      # 20:47 case: hours & mins
      hours, mins = value.split(":")
      accumulated_mins += (hours.to_i * 60 + mins.to_i)
    elsif unit =~ /day(s)?/
      accumulated_mins += (value.to_i * 1440) # 60 * 24 = 1440
    elsif unit =~ /min(s)?/
      accumulated_mins += value.to_i
    else
      raise ArgumentError, "can't parse uptime segment: #{time_segment}"
    end
  end

  accumulated_mins
end