Sha256: 9f814a501006318c7898a75b079b081ea0cdaabdf8f86abaea7793d6a76a8ab9

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

module Csv2hash::StructureValidator
  class ValidationError < StandardError ; end

  def validate_structure!
    definition.structure_rules.each do |rule, options|
      begin
        rule_instance(rule, options).validate! data_source
      rescue => e
        self.errors << { y: nil, x: nil, message: e.message, key: nil }
        raise if exception_mode
      end
    end
  end

  def rule_instance rule, options
    Csv2hash::StructureValidator.const_get(rule).new(options)
  end

  module Validator
    def validate! source
      source.index { |line| validate_line line }.tap do |line|
        raise Csv2hash::StructureValidator::ValidationError, error_message(line) unless line.nil?
      end
      true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csv2hash-0.2.1 lib/csv2hash/structure_validator.rb