class Eaternet::Lives_1_0::LegendGroup::ComprehensiveValidator
Check that all the items in this LegendGroup:
1. Are of the class, Legend 2. Cover the range of scores from 0-100 without overlap
@todo: Refactor
Public Instance Methods
validate_each(record, attribute, legends)
click to toggle source
# File lib/eaternet/lives_1_0/legend_group.rb, line 27 def validate_each(record, attribute, legends) scores = (0..100).to_a legends.each do |legend| unless legend.class == Legend record.errors.add attribute, 'must be a Legend' return end range = (legend.minimum_score..legend.maximum_score) range.each do |score| if scores.delete(score).nil? unless score == legend.minimum_score || score == legend.maximum_score record.errors.add attribute, 'may not overlap' return end end end end unless scores.empty? record.errors.add attribute, 'do not cover entire span from 0–100' end end