Module: Parklife::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/parklife/utils.rb

Instance Method Summary collapse

Instance Method Details

#host_with_port(uri) ⇒ Object



10
11
12
13
# File 'lib/parklife/utils.rb', line 10

def host_with_port(uri)
  default_port = uri.scheme == 'https' ? 443 : 80
  uri.port == default_port ? uri.host : "#{uri.host}:#{uri.port}"
end


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/parklife/utils.rb', line 15

def scan_for_links(html)
  doc = Nokogiri::HTML.parse(html)
  doc.css('a[href]').each do |a|
    uri = URI.parse(a[:href])

    # Don't visit a URL that belongs to a different domain - for now this is
    # a guess that it's not an internal link but it also covers mailto/ftp
    # links.
    next if uri.host

    # Don't visit a path-less URL - this will be the case for a #fragment
    # for example.
    next if uri.path.nil? || uri.path.empty?

    yield uri.path
  end
end