Data validation is critical for maintaining data integrity in applications. This drill teaches you to build a flexible validation system that checks CSV data against business rules, reports errors with helpful messages, and generates validation summaries. You'll learn rule-based validation, error collection, data type checking, and comprehensive reporting—essential skills for building data pipelines, import systems, and quality assurance tools. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.
Parse CSV manually: line.split(',')
Use each_with_index to track row numbers
Collect all errors before reporting
Check required fields first, skip other validations if empty
Regex for integer: /^-?\d+$/
Regex for email: /^[^@\s]+@[^@\s]+\.[^@\s]+$/
Date.parse raises ArgumentError for invalid dates
validate_csv('input.csv', 'rules.json')
DATA VALIDATION REPORT ================================================== File: input.csv Total rows: 3 -------------------------------------------------- ERRORS Row 3, Field age: Value must be at least 18 Row 3, Field email: Invalid email format -------------------------------------------------- SUMMARY Valid rows: 2 Invalid rows: 1 Total errors: 2
result = validate_csv('input.csv', 'rules.json')
puts result
DATA VALIDATION REPORT ================================================== File: input.csv Total rows: 3 -------------------------------------------------- ERRORS Row 3, Field age: Value must be at least 18 Row 3, Field email: Invalid email format -------------------------------------------------- SUMMARY Valid rows: 2 Invalid rows: 1 Total errors: 2 false
puts valid_email?('test@example.com')
puts valid_email?('invalid')
puts valid_email?('bad@nope')
true false false
Console output will appear here...
Are you sure?
You're making great progress
Become a Ruby Pro
1,600+ problems to master every concept