Class: Rippersnapper::DomainParser
- Inherits:
-
Object
- Object
- Rippersnapper::DomainParser
- Defined in:
- lib/rippersnapper/domain_parser.rb
Instance Method Summary collapse
-
#domain ⇒ String
The domain for the url taken in initialize.
- #initialize(url) ⇒ self constructor
-
#subdomain ⇒ String
The subdomain for the url taken in initialize.
-
#suffix ⇒ String
The suffix for the url taken in initialize.
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
#domain ⇒ String
Returns 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 |
#subdomain ⇒ String
Returns 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 |
#suffix ⇒ String
Returns 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 |