Class: Uniword::Lint::BuiltinRules::BannedWords
- Defined in:
- lib/uniword/lint/builtin_rules/banned_words.rb
Overview
Rule: paragraphs containing banned words trigger a finding.
Constant Summary
Constants inherited from Rule
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
- #check(document) ⇒ Object
-
#initialize(words:, **rest) ⇒ BannedWords
constructor
A new instance of BannedWords.
Methods inherited from Rule
#finding, register, type, types
Constructor Details
#initialize(words:, **rest) ⇒ BannedWords
Returns a new instance of BannedWords.
13 14 15 16 |
# File 'lib/uniword/lint/builtin_rules/banned_words.rb', line 13 def initialize(words:, **rest) super(**rest) @banned = Set.new(Array(words).map(&:downcase)) end |
Instance Method Details
#check(document) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/uniword/lint/builtin_rules/banned_words.rb', line 18 def check(document) document.paragraphs.each_with_index do |paragraph, idx| text = paragraph.text.to_s.downcase @banned.each do |word| next unless text.match?(/\b#{Regexp.escape(word)}\b/) yield finding( message: "Paragraph #{idx + 1} contains banned word " \ "'#{word}'", path: "paragraph[#{idx}]", ) end end end |