Class: Ghost::Host
- Inherits:
-
Struct
- Object
- Struct
- Ghost::Host
- Defined in:
- lib/ghost/host.rb
Defined Under Namespace
Classes: NotResolvable
Instance Attribute Summary collapse
-
#ip ⇒ Object
(also: #ip_address)
Returns the value of attribute ip.
-
#name ⇒ Object
(also: #to_s, #host, #hostname)
Returns the value of attribute name.
Instance Method Summary collapse
- #<=>(host) ⇒ Object
-
#initialize(host, ip = "127.0.0.1") ⇒ Host
constructor
A new instance of Host.
- #match(name) ⇒ Object
- #resolve_ip(ip_or_hostname) ⇒ Object
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
#ip ⇒ Object Also known as: ip_address
Returns the value of attribute ip
4 5 6 |
# File 'lib/ghost/host.rb', line 4 def ip @ip end |
#name ⇒ Object Also known as: to_s, host, hostname
Returns the value of attribute 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 |