Class: StrongCSV::Types::Optional

Inherits:
Base
  • Object
show all
Defined in:
lib/strong_csv/types/optional.rb

Overview

Optional type

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Optional

Returns a new instance of Optional.

Parameters:



10
11
12
13
# File 'lib/strong_csv/types/optional.rb', line 10

def initialize(type)
  super()
  @type = type
end

Instance Method Details

#cast(value) ⇒ ValueResult

Parameters:

  • value (Object)

Returns:



17
18
19
# File 'lib/strong_csv/types/optional.rb', line 17

def cast(value)
  value.nil? ? ValueResult.new(value: nil, original_value: value) : @type.cast(value)
end