Class: LgPodPlugin::Ping

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/net-ping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Ping

Returns a new instance of Ping.



12
13
14
# File 'lib/lg_pod_plugin/net-ping.rb', line 12

def initialize(url)
  self.uri = LUtils.git_to_uri(url)
end

Instance Attribute Details

#ipObject

Returns the value of attribute ip.



10
11
12
# File 'lib/lg_pod_plugin/net-ping.rb', line 10

def ip
  @ip
end

#network_okObject

Returns the value of attribute network_ok.



11
12
13
# File 'lib/lg_pod_plugin/net-ping.rb', line 11

def network_ok
  @network_ok
end

#uriObject

Returns the value of attribute uri.



9
10
11
# File 'lib/lg_pod_plugin/net-ping.rb', line 9

def uri
  @uri
end

Instance Method Details

#pingObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lg_pod_plugin/net-ping.rb', line 16

def ping
  return false unless self.uri
  result = %x(ping #{uri.host} -t 1)
  if result.include?("timeout")
    return false
  end
  if result && result.include?("(") && result.include?("):")
    ip_address = result.split("(").last.split(")").first
    begin
      if IPAddr.new ip_address
        self.ip = ip_address
        return  true
      else
        return false
      end
    rescue
      return false
    end
  else
    return false
  end
end