Class: PDD::Rule::MaxDuplicates
- Inherits:
-
Object
- Object
- PDD::Rule::MaxDuplicates
- Defined in:
- lib/pdd/rule/duplicates.rb
Overview
Rule for max duplicates.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(xml, max) ⇒ MaxDuplicates
constructor
Ctor.
Constructor Details
#initialize(xml, max) ⇒ MaxDuplicates
Ctor.
xml
-
XML with puzzles
27 28 29 30 |
# File 'lib/pdd/rule/duplicates.rb', line 27 def initialize(xml, max) @xml = xml @max = max.to_i end |
Instance Method Details
#errors ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pdd/rule/duplicates.rb', line 32 def errors @xml .xpath('//puzzle') .group_by { |p| p.xpath('body/text()').to_s } .map do |_, puzzles| next nil if puzzles.count <= @max "there are #{puzzles.count} duplicate(s) of the same puzzle: " + puzzles.map do |p| "#{p.xpath('file/text()')}:#{p.xpath('lines/text()')}" end.join(', ') + ", while maximum #{@max} duplicate is allowed" end.compact end |