Method: UrlExtractor::HTML#replace_urls

Defined in:
lib/url_extractor/html.rb

#replace_urls(template) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/url_extractor/html.rb', line 12

def replace_urls(template)
  document = Nokogiri::HTML(template)

  document.search("a").each do |link|
    url = link['href']
    raise InvalidURL, "cannot be blank" if UrlExtractor::Util.blank_string?(url)
    next if ignored_url?(url)

    link['href'] = yield(url)
  end

  document.to_s
end