Class: CSVPlusPlus::Modifier::DataValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_plus_plus/modifier/data_validation.rb

Overview

A validation on a cell value. Used to support the ‘validate=` modifier directive. This is mostly based on the Google Sheets API spec:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ DataValidation

Returns a new instance of DataValidation.

Parameters:

  • value (::String)

    The value to parse as a data validation



18
19
20
21
22
23
24
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 18

def initialize(value)
  condition, args = value.split(/\s*:\s*/)
  @arguments = ::CSVPlusPlus::Lexer.unquote(args || '').split(/\s+/)
  @condition = condition.to_sym

  validate!
end

Instance Attribute Details

#argumentsArray<::String> (readonly)

The parsed arguments as required by the condition.

Returns:

  • (Array<::String>)

    the current value of arguments



14
15
16
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 14

def arguments
  @arguments
end

#conditionSymbol (readonly)

The condition (:blank, :text_eq, :date_before, etc.)

Returns:

  • (Symbol)

    the current value of condition



14
15
16
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 14

def condition
  @condition
end

#invalid_reason::String? (readonly)

If set, the reason why this modifier is not valid.

Returns:

  • (::String, nil)

    the current value of invalid_reason



14
15
16
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 14

def invalid_reason
  @invalid_reason
end

Instance Method Details

#valid?boolean

Each data validation (represented by @condition) has their own requirements for which arguments are valid. If this object is invalid, you can see the reason in @invalid_reason.

Returns:

  • (boolean)


30
31
32
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 30

def valid?
  @invalid_reason.nil?
end