Class: Rippersnapper::Url
- Inherits:
-
Object
- Object
- Rippersnapper::Url
- Defined in:
- lib/rippersnapper/url.rb
Instance Method Summary collapse
-
#domain ⇒ Object
Pass through to DomainParser object DomainParser#domain see here for more details.
-
#host ⇒ String
convenience method to access URI host See #uri for more information.
-
#initialize(url) ⇒ Url
constructor
A new instance of Url.
-
#ip? ⇒ Boolean
Used to see if the host is an IP address.
-
#path ⇒ String
construct path from uri query and uri path.
-
#port ⇒ String
convenience method to access URI port See #uri for more information.
-
#scheme ⇒ String
convenience method to access URI scheme See #uri for more information.
-
#subdomain ⇒ Object
Pass through to DomainParser object DomainParser#subdomain see here for more details.
-
#suffix ⇒ Object
Pass through to DomainParser object DomainParser#suffix see here for more details.
-
#uri ⇒ URI
URI object from url passed to initialize.
-
#url ⇒ String
If url has a scheme use it if not assume http.
Constructor Details
#initialize(url) ⇒ Url
Returns a new instance of Url.
7 8 9 |
# File 'lib/rippersnapper/url.rb', line 7 def initialize url @url = url.to_s end |
Instance Method Details
#domain ⇒ Object
Pass through to DomainParser object DomainParser#domain see here for more details
46 47 48 |
# File 'lib/rippersnapper/url.rb', line 46 def domain parsed_domain.domain end |
#host ⇒ String
convenience method to access URI host See #uri for more information
70 71 72 |
# File 'lib/rippersnapper/url.rb', line 70 def host uri.host || "" end |
#ip? ⇒ Boolean
Used to see if the host is an IP address
25 26 27 |
# File 'lib/rippersnapper/url.rb', line 25 def ip? !!(host =~ /^\d+\.\d+\.\d+\.\d+$/) end |
#path ⇒ String
construct path from uri query and uri path
76 77 78 79 |
# File 'lib/rippersnapper/url.rb', line 76 def path return "#{uri.path}?#{uri.query}" if uri.query uri.path end |
#port ⇒ String
convenience method to access URI port See #uri for more information
86 87 88 |
# File 'lib/rippersnapper/url.rb', line 86 def port uri.port end |
#scheme ⇒ String
convenience method to access URI scheme See #uri for more information
61 62 63 |
# File 'lib/rippersnapper/url.rb', line 61 def scheme uri.scheme || "" end |
#subdomain ⇒ Object
Pass through to DomainParser object DomainParser#subdomain see here for more details
52 53 54 |
# File 'lib/rippersnapper/url.rb', line 52 def subdomain parsed_domain.subdomain end |
#suffix ⇒ Object
Pass through to DomainParser object DomainParser#suffix see here for more details
40 41 42 |
# File 'lib/rippersnapper/url.rb', line 40 def suffix parsed_domain.suffix end |
#uri ⇒ URI
URI object from url passed to initialize
19 20 21 |
# File 'lib/rippersnapper/url.rb', line 19 def uri @uri ||= URI.parse url end |
#url ⇒ String
If url has a scheme use it if not assume http
31 32 33 34 35 36 |
# File 'lib/rippersnapper/url.rb', line 31 def url return @url if @url =~ /:\/\// || @url.empty? # sensible default "http://#{@url}" end |