Class: CSVPlusPlus::DataValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_plus_plus/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 which can be seen here:

https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/other#ConditionType

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



16
17
18
19
20
21
22
# File 'lib/csv_plus_plus/data_validation.rb', line 16

def initialize(value)
  condition, args = unquote(value).split(/\s*:\s*/)
  @arguments = 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



12
13
14
# File 'lib/csv_plus_plus/data_validation.rb', line 12

def arguments
  @arguments
end

#conditionSymbol (readonly)

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

Returns:

  • (Symbol)

    the current value of condition



12
13
14
# File 'lib/csv_plus_plus/data_validation.rb', line 12

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



12
13
14
# File 'lib/csv_plus_plus/data_validation.rb', line 12

def invalid_reason
  @invalid_reason
end

Instance Method Details

#valid?boolean

Each data validation represented by (condition) has their own require

Returns:

  • (boolean)


26
27
28
# File 'lib/csv_plus_plus/data_validation.rb', line 26

def valid?
  @invalid_reason.nil?
end