File: utils.rb

package info (click to toggle)
ruby-html-proofer 3.19.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,040 kB
  • sloc: ruby: 3,203; sh: 9; makefile: 4; javascript: 1; php: 1
file content (28 lines) | stat: -rw-r--r-- 590 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

require 'nokogiri'

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

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

      Nokogiri::HTML5(content, max_errors: -1)
    end

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