Module: HTMLProofer::Utils

Included in:
Cache, Element, Middleware, Runner, UrlValidator, LinkCheck
Defined in:
lib/html-proofer/utils.rb

Instance Method Summary collapse

Instance Method Details

#create_nokogiri(path) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/html-proofer/utils.rb', line 11

def create_nokogiri(path)
  content = if File.exist?(path) && !File.directory?(path)
              File.open(path).read
            else
              path
            end

  Nokogiri::HTML5(content)
end

#pluralize(count, single, plural) ⇒ Object



7
8
9
# File 'lib/html-proofer/utils.rb', line 7

def pluralize(count, single, plural)
  "#{count} #{(count == 1 ? single : plural)}"
end

#swap(href, replacement) ⇒ Object



21
22
23
24
25
26
# File 'lib/html-proofer/utils.rb', line 21

def swap(href, replacement)
  replacement.each do |link, replace|
    href = href.gsub(link, replace)
  end
  href
end