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



28
29
30
31
# File 'lib/pdd/rule/text.rb', line 28

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

Instance Method Details

#errorsObject



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

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