class Grell::Page::VisitedPage::Link

Private class to group all the methods related to links.

Public Class Methods

new(anchor) click to toggle source
# File lib/grell/page.rb, line 222
def initialize(anchor)
  @anchor = anchor
end

Public Instance Methods

disabled?() click to toggle source

Is the link disabled by either Javascript or CSS?

# File lib/grell/page.rb, line 232
def disabled?
  @anchor.disabled? || !!@anchor.native.attributes['disabled']
end
href() click to toggle source

Some links may use data-href + javascript to do interesting things

# File lib/grell/page.rb, line 242
def href
  @anchor['href'] || @anchor['data-href']
end
inside_header?() click to toggle source

<link> can only be used in the <head> as of: developer.mozilla.org/en/docs/Web/HTML/Element/link

# File lib/grell/page.rb, line 227
def inside_header?
  @anchor.tag_name == 'link'
end
js_href?() click to toggle source

Does the href use javascript?

# File lib/grell/page.rb, line 237
def js_href?
  href.start_with?('javascript:')
end
to_url(host) click to toggle source

We only accept links in this same host that start with a path

# File lib/grell/page.rb, line 247
def to_url(host)
  uri = URI.parse(href)
  if uri.absolute?
    if uri.host != URI.parse(host).host
      Grell.logger.debug "GRELL does not follow links to external hosts: #{href}"
      nil
    else
      href # Absolute link to our own host
    end
  else
    if uri.path.nil?
      Grell.logger.debug "GRELL does not follow links without a path: #{uri}"
      nil
    end
    if uri.path.start_with?('/')
      host + href  # convert to full URL
    else # links like href="google.com" the browser would go to http://google.com like "http://#{link}"
      Grell.logger.debug "GRELL Bad formatted link: #{href}, assuming external"
      nil
    end
  end
rescue URI::InvalidURIError # Invalid links propagating till we navigate to them
  href
end