class PDD::Rule::Text::MinWords

Rule for minimum length of description.

Public Class Methods

new(xml, min) click to toggle source

Ctor.

xml

XML with puzzles

# File lib/pdd/rule/text.rb, line 28
def initialize(xml, min)
  @xml = xml
  @min = min.to_i
end

Public Instance Methods

errors() click to toggle source
# 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