Class: Addressable::URI
- Inherits:
-
Object
- Object
- Addressable::URI
- 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
- #host_valid? ⇒ Boolean
- #path_valid? ⇒ Boolean
-
#revhost ⇒ Object
revhost
the dot-reversed host: foo.company.com => com.company.foo. -
#simple? ⇒ Boolean
Does this look like a.
- #simple_connection_part? ⇒ Boolean
-
#url_uuid ⇒ Object
uuid
– RFC-4122 ver.5 uuid; guaranteed to be universally unique.
Instance Method Details
#host_valid? ⇒ 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
19 20 21 |
# File 'lib/imw/utils/uri.rb', line 19 def path_valid? !!(path =~ %r{\A[#{PATH_CHARS}%]*\z}) end |
#revhost ⇒ Object
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
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
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_uuid ⇒ Object
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 |