Class: Crabbs::Link
- Inherits:
-
Object
- Object
- Crabbs::Link
- Defined in:
- lib/crabbs/link.rb
Instance Method Summary collapse
- #has_html_extension? ⇒ Boolean
- #has_valid_fragment? ⇒ Boolean
-
#initialize(href) ⇒ Link
constructor
A new instance of Link.
- #join(url) ⇒ Object
- #same_host_as?(url) ⇒ Boolean
Constructor Details
#initialize(href) ⇒ Link
Returns a new instance of Link.
4 5 6 7 |
# File 'lib/crabbs/link.rb', line 4 def initialize(href) @href = href @uri = URI.parse(href) end |
Instance Method Details
#has_html_extension? ⇒ Boolean
17 18 19 20 21 22 23 24 25 |
# File 'lib/crabbs/link.rb', line 17 def has_html_extension? link = @href if not @uri.host.nil? link = @href.sub(@uri.host, '') end extension = File.extname(link) extension.empty? or extension == '.html' end |
#has_valid_fragment? ⇒ Boolean
13 14 15 |
# File 'lib/crabbs/link.rb', line 13 def has_valid_fragment? @uri.fragment.nil? or not @uri.fragment.empty? end |
#join(url) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/crabbs/link.rb', line 27 def join(url) new_uri = @uri if @uri.host.nil? new_uri = URI.parse url new_uri = URI.join(new_uri.to_s, @uri.path) unless @uri.path.nil? new_uri = URI.join(new_uri.to_s, "?#{@uri.query}") unless @uri.query.nil? new_uri = URI.join(new_uri.to_s, "##{@uri.fragment}") unless @uri.fragment.nil? end new_uri.to_s end |
#same_host_as?(url) ⇒ Boolean
9 10 11 |
# File 'lib/crabbs/link.rb', line 9 def same_host_as?(url) @uri.host == URI.parse(url).host or @uri.host.nil? end |