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.



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

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

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



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

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



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

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#titleObject (readonly)

Returns the value of attribute title.



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

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
  return valid?
end