Class: CSVPlusPlus::Modifier::DataValidation
- Inherits:
-
Object
- Object
- CSVPlusPlus::Modifier::DataValidation
- 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
-
#arguments ⇒ Array<::String>
readonly
The parsed arguments as required by the condition.
-
#condition ⇒ Symbol
readonly
The condition (:blank, :text_eq, :date_before, etc.).
-
#invalid_reason ⇒ ::String?
readonly
If set, the reason why this modifier is not valid.
Instance Method Summary collapse
-
#initialize(value) ⇒ DataValidation
constructor
A new instance of DataValidation.
-
#valid? ⇒ boolean
Each data validation (represented by @condition) has their own requirements for which arguments are valid.
Constructor Details
#initialize(value) ⇒ DataValidation
Returns a new instance of DataValidation.
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
#arguments ⇒ Array<::String> (readonly)
The parsed arguments as required by the condition.
14 15 16 |
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 14 def arguments @arguments end |
#condition ⇒ Symbol (readonly)
The condition (:blank, :text_eq, :date_before, etc.)
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.
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.
30 31 32 |
# File 'lib/csv_plus_plus/modifier/data_validation.rb', line 30 def valid? @invalid_reason.nil? end |