Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/string_ext.rb

Overview

Extend string to include some helpful stuff

Instance Method Summary collapse

Instance Method Details

#fqdn?Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/string_ext.rb', line 25

def fqdn?
  begin
    resolve_fqdn
  rescue SocketError
    return false
  end

  if ip_addr?
    return false
  else
    return true
  end
end

#ip_addr?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
15
16
17
18
19
# File 'lib/string_ext.rb', line 9

def ip_addr?
  begin
    IPAddr.new(self)

  # Using ArgumentError instead of IPAddr::InvalidAddressError for 1.9.3 backward compatability
  rescue ArgumentError
    return false
  end

  return true
end

#resolve_fqdnObject



21
22
23
# File 'lib/string_ext.rb', line 21

def resolve_fqdn
  @fqdn ||= TCPSocket.gethostbyname(self)[3]
end

#unhexifyObject



5
6
7
# File 'lib/string_ext.rb', line 5

def unhexify
  [self].pack("H*")
end