Class: Retriever::Link
- Inherits:
-
Object
- Object
- Retriever::Link
- Defined in:
- lib/retriever/link.rb
Constant Summary collapse
- HTTP_RE =
Regexp.new(/^http/i).freeze
- SINGLE_SLASH_RE =
Regexp.new(/^\/{1}[^\/]/).freeze
- DOUBLE_SLASH_RE =
Regexp.new(/^\/{2}[^\/]/).freeze
- NO_SLASH_PAGE_RE =
Regexp.new(/^[a-z0-9\-\_\=\?\.]+\z/ix).freeze
- DUB_DUB_DUB_DOT_RE =
Regexp.new(/^www\./i).freeze
Instance Method Summary collapse
-
#initialize(host, link) ⇒ Link
constructor
A new instance of Link.
- #path ⇒ Object
Constructor Details
#initialize(host, link) ⇒ Link
Returns a new instance of Link.
9 10 11 12 |
# File 'lib/retriever/link.rb', line 9 def initialize(host, link) @host = host @link = link end |
Instance Method Details
#path ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/retriever/link.rb', line 14 def path return link if HTTP_RE =~ link return "http://#{link}" if DUB_DUB_DUB_DOT_RE =~ link return "http://#{host}#{link}" if SINGLE_SLASH_RE =~ link return "http:#{link}" if DOUBLE_SLASH_RE =~ link #link begins with '//' (maybe a messed up link?) return "http://#{host}/#{link}" if NO_SLASH_PAGE_RE =~ link #link uses relative path with no slashes at all, people actually this - imagine that. end |