Class: ProxyRb::ProxyUrl
- Inherits:
-
Object
- Object
- ProxyRb::ProxyUrl
- Defined in:
- lib/proxy_rb/proxy_url.rb
Overview
A ProxyURL
Class Method Summary collapse
-
.build(hash) ⇒ ProxyUrl
Build a URL from hash.
-
.parse(string) ⇒ ProxyUrl
Create URL from string.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Check if url is empty.
-
#initialize(url) ⇒ ProxyUrl
constructor
A new instance of ProxyUrl.
-
#to_hash ⇒ Hash
Return url as hash.
- #to_s ⇒ Object
-
#without_user_name_and_password ⇒ ProxyUrl
Return URL without user name and password.
Constructor Details
#initialize(url) ⇒ ProxyUrl
Returns a new instance of ProxyUrl.
45 46 47 |
# File 'lib/proxy_rb/proxy_url.rb', line 45 def initialize(url) @url = url end |
Class Method Details
.build(hash) ⇒ ProxyUrl
Build a URL from hash
@param [Hash] hash
An Hash representing the url parts
15 16 17 |
# File 'lib/proxy_rb/proxy_url.rb', line 15 def self.build(hash) new(Addressable::URI.new(hash)) end |
.parse(string) ⇒ ProxyUrl
Create URL from string
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/proxy_rb/proxy_url.rb', line 26 def self.parse(string) string = string.to_s string = if string.empty? string elsif string.start_with?('http://') string else 'http://' + string end new(Addressable::URI.heuristic_parse(string)) end |
Instance Method Details
#empty? ⇒ Boolean
Check if url is empty
64 65 66 |
# File 'lib/proxy_rb/proxy_url.rb', line 64 def empty? url.nil? || url.empty? end |
#to_hash ⇒ Hash
Return url as hash
86 87 88 |
# File 'lib/proxy_rb/proxy_url.rb', line 86 def to_hash url.to_hash end |
#to_s ⇒ Object
57 58 59 60 61 |
# File 'lib/proxy_rb/proxy_url.rb', line 57 def to_s return '' if empty? url.to_s end |
#without_user_name_and_password ⇒ ProxyUrl
Return URL without user name and password
72 73 74 75 76 77 78 79 80 |
# File 'lib/proxy_rb/proxy_url.rb', line 72 def without_user_name_and_password return self.class.new(nil) if empty? h = url.to_hash h.delete :user h.delete :password self.class.build(h) end |