Module: Probe

Defined in:
lib/csv/probe.rb,
lib/csv/probe/checks.rb,
lib/csv/probe/version.rb

Overview

Probe provides methods for linting a:

  • CSV::Table

  • CSV::Row

The linting methods:

  • lint_rows takes following arguments

    • csv_rows: CSV::Table

    • checks: Array of Probe Checks and

    • options

  • lint_row takes following arguments

    • csv_row: CSV::Row

    • checks: Array of Probe Checks and

    • optsions

Defined Under Namespace

Classes: ChecksInvalidTypeError, ColumnError, ColumnIsDate, ColumnIsEqualTo, ColumnIsListWithDomain, ColumnIsOneOf, ColumnIsSet, ColumnIsSetWithDomain, ColumnMatchesRegEx, ColumnMeetsCondition, ColumnNotMatchesRegEx, ColumnWarning, Error, LintingError, RowError, RowMeetsCondition, RowWarning

Constant Summary collapse

VERSION =
"0.1.6"

Class Method Summary collapse

Class Method Details

.lint_row(csv_row, checks, opts = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/csv/probe.rb', line 30

def self.lint_row(csv_row, checks, opts = {})
  unless checks.is_a? Array
    raise ChecksInvalidTypeError, "checks are expected to be of type error, but are of type '#{checks.class}'"
  end

  return if checks.empty? # nothing to do if there are no checks

  unless csv_row.is_a? CSV::Row
    raise Error "lint_row(csv_row,...), csv_row is not of type CSV::Row, but of type '#{csv_row.class}'"
  end

  checks.each do |check|
    check.evaluate(csv_row, opts)
  rescue LintingError => e
    raise e unless opts[:exception] == false

    puts e.message # if exception oppressed, write error out on stdout
  end
end

.lint_rows(csv_rows, checks, opts = {}) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/csv/probe.rb', line 22

def self.lint_rows(csv_rows, checks, opts = {})
  lineno_start = opts[:headers] ? 2 : 1
  csv_rows.each.with_index(lineno_start) do |row, lineno|
    opts[:lineno] = lineno
    lint_row(row, checks, opts)
  end
end