Class: Rippersnapper::DomainParser

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

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ self



6
7
8
# File 'lib/rippersnapper/domain_parser.rb', line 6

def initialize url
  @url = url
end

Instance Method Details

#domainString

Returns The domain for the url taken in initialize.

Examples:

Rippersnapper::DomainParser.new("www.google.com").domain #=> "google"

Returns:

  • (String)

    The domain for the url taken in initialize



27
28
29
30
31
32
# File 'lib/rippersnapper/domain_parser.rb', line 27

def domain
  @domain ||= begin
    remaining = url_parts - suffix_parts
    remaining.last.to_s
  end
end

#subdomainString

Returns The subdomain for the url taken in initialize.

Examples:

Rippersnapper::DomainParser.new("www.google.com").subdomain #=> "www"

Returns:

  • (String)

    The subdomain for the url taken in initialize



37
38
39
40
41
42
# File 'lib/rippersnapper/domain_parser.rb', line 37

def subdomain
  @subdomain ||= begin
    remaining = url_parts - [domain] - suffix_parts
    remaining.join(".")
  end
end

#suffixString

Returns The suffix for the url taken in initialize.

Examples:

Rippersnapper::DomainParser.new("www.google.com").suffix #=> "com"

Returns:

  • (String)

    The suffix for the url taken in initialize



13
14
15
16
17
18
19
20
21
22
# File 'lib/rippersnapper/domain_parser.rb', line 13

def suffix
  @suffix ||= begin
    found = nil
    parts_count.times do |iteration|
      test = url_parts.last(iteration + 1).join(".")
      found = test if suffix_exists?(test)
    end
    found.to_s
  end
end