Class: Asimov::Utils::JsonlValidator
- Inherits:
-
Object
- Object
- Asimov::Utils::JsonlValidator
- Defined in:
- lib/asimov/utils/jsonl_validator.rb
Overview
Validates that a file is a JSONL file. Subclassed by more specific file validators.
Direct Known Subclasses
ClassificationsFileValidator, TextEntryFileValidator, TrainingFileValidator
Instance Method Summary collapse
Instance Method Details
#validate(file) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/asimov/utils/jsonl_validator.rb', line 10 def validate(file) file.each_line.with_index { |line, idx| validate_line(line, idx) } true rescue JSON::ParserError raise JsonlFileCannotBeParsedError, "Expected file to have the JSONL format." end |
#validate_line(line, idx) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/asimov/utils/jsonl_validator.rb', line 17 def validate_line(line, idx) JSON.parse(line) rescue JSON::ParserError raise JsonlFileCannotBeParsedError, "Expected file to have the JSONL format. Error found on line #{idx + 1}." end |