Challenge

Problem

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.

Difficulty: Intermediate

Instructions

  1. Read CSV data from input.csv
  2. Read validation rules from rules.json:
    • required: field must not be empty
    • type: integer, float, email, date
    • min/max: numeric range validation
    • pattern: regex pattern matching
  3. Validate each row against all rules
  4. Collect validation errors with row number and field
  5. Print validation report:
    'DATA VALIDATION REPORT'
    '=' * 50
    'File: input.csv'
    'Total rows: X'
    '-' * 50
    'ERRORS'
    'Row X, Field [name]: [error message]'
    (for each error)
    '-' * 50
    'SUMMARY'
    'Valid rows: X'
    'Invalid rows: Y'
    'Total errors: Z'
  6. Exit with status 0 if all valid, 1 if errors found

Files

Editable
Read-only

Hints

Hint 1

CSV.read(file) returns array of arrays (including header)

Hint 2

Use each_with_index to track row numbers during iteration

Hint 3

Collect all errors before reporting (don't exit early)

Hint 4

Check required fields first, skip other validations if empty

Hint 5

Regex for integer: /^-?\d+$/

Hint 6

Regex for float: /^-?\d+\.?\d*$/

Hint 7

Email regex: /^[^@\s]+@[^@\s]+\.[^@\s]+$/

Hint 8

Date.parse raises ArgumentError for invalid dates

Provided Files (Read-only)

1. Multiple validation errors

Input:
validate_csv('input.csv', 'rules.json')
Expected Output:
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

2. All valid data

Input:
validate_csv('input.csv', 'rules.json')
Expected Output:
DATA VALIDATION REPORT
==================================================
File: input.csv
Total rows: 2
--------------------------------------------------
ERRORS
(No errors found)
--------------------------------------------------
SUMMARY
Valid rows: 2
Invalid rows: 0
Total errors: 0

3. Required field missing

Input:
validate_csv('input.csv', 'rules.json')
Expected Output:
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
+ 2 hidden test cases