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. Note: This drill parses CSV manually using string methods rather than Ruby's CSV library.

Difficulty: Intermediate

Instructions

  1. Read CSV data from input.csv (parse manually)
  2. Read validation rules from rules.json:
    • required: field must not be empty
    • type: integer, float, email, date
    • min/max: numeric range validation
  3. Validate each row against all rules
  4. Collect validation errors with row number and field
  5. Print validation report with errors and summary
  6. Return true if all valid, false if errors found

Files

Editable
Read-only

Hints

Hint 1

Parse CSV manually: line.split(',')

Hint 2

Use each_with_index to track row numbers

Hint 3

Collect all errors before reporting

Hint 4

Check required fields first, skip other validations if empty

Hint 5

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

Hint 6

Regex for email: /^[^@\s]+@[^@\s]+\.[^@\s]+$/

Hint 7

Date.parse raises ArgumentError for invalid dates

Ruby 3.4

Provided Files (Read-only)

1. Detects validation errors

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

2. Returns false when errors exist

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

3. valid_email? helper works

Input:
puts valid_email?('test@example.com')
puts valid_email?('invalid')
puts valid_email?('bad@nope')
Expected Output:
true
false
false
+ 2 hidden test cases