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.
CSV.read(file) returns array of arrays (including header)
Use each_with_index to track row numbers during iteration
Collect all errors before reporting (don't exit early)
Check required fields first, skip other validations if empty
Regex for integer: /^-?\d+$/
Regex for float: /^-?\d+\.?\d*$/
Email regex: /^[^@\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 2, Field age: Value must be at least 18 Row 2, Field email: Invalid email format Row 2, Field signup_date: Invalid date format -------------------------------------------------- SUMMARY Valid rows: 2 Invalid rows: 1 Total errors: 3
validate_csv('input.csv', 'rules.json')
DATA VALIDATION REPORT ================================================== File: input.csv Total rows: 2 -------------------------------------------------- ERRORS (No errors found) -------------------------------------------------- SUMMARY Valid rows: 2 Invalid rows: 0 Total errors: 0
validate_csv('input.csv', 'rules.json')
DATA VALIDATION REPORT ================================================== File: input.csv Total rows: 2 -------------------------------------------------- ERRORS Row 2, Field email: Field is required -------------------------------------------------- SUMMARY Valid rows: 1 Invalid rows: 1 Total errors: 1
Console output will appear here...
Are you sure?
You're making great progress