Class: Uniword::Lint::BuiltinRules::MaxParagraphLength
- Defined in:
- lib/uniword/lint/builtin_rules/max_paragraph_length.rb
Overview
Rule: paragraphs longer than max 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(max: 200, **rest) ⇒ MaxParagraphLength
constructor
A new instance of MaxParagraphLength.
Methods inherited from Rule
#finding, register, type, types
Constructor Details
#initialize(max: 200, **rest) ⇒ MaxParagraphLength
Returns a new instance of MaxParagraphLength.
11 12 13 14 |
# File 'lib/uniword/lint/builtin_rules/max_paragraph_length.rb', line 11 def initialize(max: 200, **rest) super(**rest) @max = max end |
Instance Method Details
#check(document) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/uniword/lint/builtin_rules/max_paragraph_length.rb', line 16 def check(document) document.paragraphs.each_with_index do |paragraph, idx| text = paragraph.text.to_s word_count = text.split.length next if word_count <= @max yield finding( message: "Paragraph #{idx + 1} has #{word_count} words " \ "(max #{@max})", path: "paragraph[#{idx}]", ) end end |