Class: Ghost::Host

Inherits:
Struct
  • Object
show all
Defined in:
lib/ghost/host.rb

Defined Under Namespace

Classes: NotResolvable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, ip = "127.0.0.1") ⇒ Host

Returns a new instance of Host.



12
13
14
# File 'lib/ghost/host.rb', line 12

def initialize(host, ip = "127.0.0.1")
  super(host, resolve_ip(ip))
end

Instance Attribute Details

#ipObject Also known as: ip_address

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



4
5
6
# File 'lib/ghost/host.rb', line 4

def ip
  @ip
end

#nameObject Also known as: to_s, host, hostname

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



4
5
6
# File 'lib/ghost/host.rb', line 4

def name
  @name
end

Instance Method Details

#<=>(host) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/ghost/host.rb', line 16

def <=>(host)
  if ip == host.ip
    name <=> host.name
  else
    ip <=> host.ip
  end
end

#match(name) ⇒ Object



24
25
26
# File 'lib/ghost/host.rb', line 24

def match(name)
  host.match(name)
end

#resolve_ip(ip_or_hostname) ⇒ Object



28
29
30
31
32
# File 'lib/ghost/host.rb', line 28

def resolve_ip(ip_or_hostname)
  IPSocket.getaddress(ip_or_hostname)
rescue SocketError
  raise Ghost::Host::NotResolvable, "#{ip_or_hostname} is not resolvable."
end