Class: PDD::Rule::Text::MinWords

Inherits:
Object
  • Object
show all
Defined in:
lib/pdd/rule/text.rb

Overview

Rule for minimum length of description.

Instance Method Summary collapse

Constructor Details

#initialize(xml, min) ⇒ MinWords

Ctor.

xml

XML with puzzles



11
12
13
14
# File 'lib/pdd/rule/text.rb', line 11

def initialize(xml, min)
  @xml = xml
  @min = min.to_i
end

Instance Method Details

#errorsObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/pdd/rule/text.rb', line 16

def errors
  @xml.xpath('//puzzle').map do |p|
    words = p.xpath('body/text()').to_s.split.size
    next nil if words >= @min

    "Puzzle #{p.xpath('file/text()')}:#{p.xpath('lines/text()')} " \
      "has a very short description of just #{words} words while " \
      "a minimum of #{@min} is required"
  end.compact
end