Class: Rippersnapper::Url

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

Instance Method Summary collapse

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

#domainObject

Pass through to DomainParser object DomainParser#domain see here for more details



40
41
42
# File 'lib/rippersnapper/url.rb', line 40

def domain
  parsed_domain.domain
end

#hostString

convenience method to access URI host See #uri for more information

Examples:

Rippersnapper::Url.new("https://www.google.com").host #=> "google"

Returns:

  • (String)


64
65
66
# File 'lib/rippersnapper/url.rb', line 64

def host
  uri.host || ""
end

#pathString

construct path from uri query and uri path

Returns:

  • (String)


70
71
72
73
# File 'lib/rippersnapper/url.rb', line 70

def path
  return "#{uri.path}?#{uri.query}" if uri.query
  uri.path
end

#portString

convenience method to access URI port See #uri for more information

Examples:

Rippersnapper::Url.new("https://www.google.com").port #=> 443

Returns:

  • (String)


80
81
82
# File 'lib/rippersnapper/url.rb', line 80

def port
  uri.port
end

#schemeString

convenience method to access URI scheme See #uri for more information

Examples:

Rippersnapper::Url.new("https://www.google.com").scheme #=> "https"

Returns:

  • (String)


55
56
57
# File 'lib/rippersnapper/url.rb', line 55

def scheme
  uri.scheme || ""
end

#subdomainObject

Pass through to DomainParser object DomainParser#subdomain see here for more details



46
47
48
# File 'lib/rippersnapper/url.rb', line 46

def subdomain
  parsed_domain.subdomain
end

#suffixObject

Pass through to DomainParser object DomainParser#suffix see here for more details



34
35
36
# File 'lib/rippersnapper/url.rb', line 34

def suffix
  parsed_domain.suffix
end

#uriURI

URI object from url passed to initialize

Examples:

uri = Rippersnapper::Url.new("www.google.com?q=blah")
uri.scheme #=> "https"
uri.host #=> "www.google.com"
uri.path #=> "/"
uri.query #=> "q=blah"

Returns:

  • (URI)

    the URI object



19
20
21
# File 'lib/rippersnapper/url.rb', line 19

def uri
  @uri ||= URI.parse url
end

#urlString

If url has a scheme use it if not assume http

Returns:

  • (String)

    The url to be processed



25
26
27
28
29
30
# File 'lib/rippersnapper/url.rb', line 25

def url
  return @url if @url =~ /:\/\// || @url.empty?

  # sensible default
  "http://#{@url}"
end