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



30
31
32
33
# File 'lib/pdd/rule/text.rb', line 30

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

Instance Method Details

#errorsObject



35
36
37
38
39
40
41
42
43
# File 'lib/pdd/rule/text.rb', line 35

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