Class: StrongCSV::ValueResult
- Inherits:
-
Object
- Object
- StrongCSV::ValueResult
- Defined in:
- lib/strong_csv/value_result.rb
Overview
ValueResult represents whether a CSV field is valid or not, and contains its casted value if it’s valid.
Instance Attribute Summary collapse
-
#error_messages ⇒ Array<String>?
readonly
The error messages for the field.
Instance Method Summary collapse
-
#initialize(original_value:, value: DEFAULT_VALUE, error_messages: nil) ⇒ ValueResult
constructor
A new instance of ValueResult.
-
#success? ⇒ Boolean
It returns true if the value is successfully casted.
-
#value ⇒ ::Float, ...
The casted value if it’s valid.
Constructor Details
#initialize(original_value:, value: DEFAULT_VALUE, error_messages: nil) ⇒ ValueResult
Returns a new instance of ValueResult.
12 13 14 15 16 |
# File 'lib/strong_csv/value_result.rb', line 12 def initialize(original_value:, value: DEFAULT_VALUE, error_messages: nil) @value = value @original_value = original_value @error_messages = end |
Instance Attribute Details
#error_messages ⇒ Array<String>? (readonly)
Returns The error messages for the field.
10 11 12 |
# File 'lib/strong_csv/value_result.rb', line 10 def @error_messages end |
Instance Method Details
#success? ⇒ Boolean
It returns true if the value is successfully casted.
26 27 28 |
# File 'lib/strong_csv/value_result.rb', line 26 def success? @error_messages.nil? end |
#value ⇒ ::Float, ...
Returns The casted value if it’s valid. Otherwise, returns the original value.
19 20 21 |
# File 'lib/strong_csv/value_result.rb', line 19 def value success? ? @value : @original_value end |