Class: Csvlint::Field

Inherits:
Object
  • Object
show all
Includes:
ErrorCollector
Defined in:
lib/csvlint/field.rb

Instance Attribute Summary collapse

Attributes included from ErrorCollector

#errors, #info_messages, #warnings

Instance Method Summary collapse

Methods included from ErrorCollector

#build_errors, #build_info_messages, #build_warnings, #reset, #valid?

Constructor Details

#initialize(name, constraints = {}, title = nil, description = nil) ⇒ Field

Returns a new instance of Field.



7
8
9
10
11
12
13
14
15
# File 'lib/csvlint/field.rb', line 7

def initialize(name, constraints = {}, title = nil, description = nil)
  @name = name
  @constraints = constraints || {}
  @uniques = Set.new
  @title = title
  @description = description
  @regex = nil
  reset
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



5
6
7
# File 'lib/csvlint/field.rb', line 5

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/csvlint/field.rb', line 5

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/csvlint/field.rb', line 5

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



5
6
7
# File 'lib/csvlint/field.rb', line 5

def title
  @title
end

Instance Method Details

#validate_column(value, row = nil, column = nil, all_errors = []) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/csvlint/field.rb', line 17

def validate_column(value, row = nil, column = nil, all_errors = [])
  reset
  unless all_errors.any? { |error| (error.type == :invalid_regex) && (error.column == column) }
    validate_regex(value, row, column, all_errors)
  end
  validate_length(value, row, column)
  validate_values(value, row, column)
  parsed = validate_type(value, row, column)
  validate_range(parsed, row, column) if !parsed.nil?
  valid?
end