Class: Addressable::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/imw/utils/uri.rb

Overview

Add the #scrubbed and #revhost calls

Constant Summary collapse

SAFE_CHARS =
%r{a-zA-Z0-9\-\._!\(\)\*\'}
PATH_CHARS =
%r{#{SAFE_CHARS}\$&\+,:=@\/;}
RESERVED_CHARS =
%r{\$&\+,:=@\/;\?\%}
UNSAFE_CHARS =
%r{\\ \"\#<>\[\]\^\`\|\~\{\}}
HOST_HEAD =
'(?:[a-z0-9\-]+\.)+'
HOST_TLD =
'(?:[a-z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'

Instance Method Summary collapse

Instance Method Details

#host_valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/imw/utils/uri.rb', line 16

def host_valid?
  !!(host =~ %r{\A#{HOST_HEAD}#{HOST_TLD}\z}i)
end

#path_valid?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/imw/utils/uri.rb', line 19

def path_valid?
  !!(path =~ %r{\A[#{PATH_CHARS}%]*\z})
end

#revhostObject

revhost the dot-reversed host:

foo.company.com => com.company.foo


40
41
42
43
# File 'lib/imw/utils/uri.rb', line 40

def revhost
  return host unless host =~ /\./
  host.split('.').reverse.join('.')
end

#simple?Boolean

Does this look like a

Returns:

  • (Boolean)


31
32
33
# File 'lib/imw/utils/uri.rb', line 31

def simple?
  host_valid? && path_valid? && simple_connection_part?
end

#simple_connection_part?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/imw/utils/uri.rb', line 22

def simple_connection_part?
  ( ['http', nil].include?(scheme) &&
    [80,     nil].include?(port) &&
    (self.to_hash.values_at(:password, :user).join.blank?) )
end

#url_uuidObject

uuid – RFC-4122 ver.5 uuid; guaranteed to be universally unique

See

http://www.faqs.org/rfcs/rfc4122.html


50
51
52
# File 'lib/imw/utils/uri.rb', line 50

def url_uuid
  UUID.sha1_create(UUID_URL_NAMESPACE, self.normalize.to_s)
end