Class: StrongCSV::Types::Union
- Defined in:
- lib/strong_csv/types/union.rb
Overview
Union type is a type that combine multiple types.
Instance Method Summary collapse
- #cast(value) ⇒ ValueResult
-
#initialize(type, *types) ⇒ Union
constructor
A new instance of Union.
Constructor Details
#initialize(type, *types) ⇒ Union
Returns a new instance of Union.
11 12 13 14 |
# File 'lib/strong_csv/types/union.rb', line 11 def initialize(type, *types) super() @types = [type, *types] end |
Instance Method Details
#cast(value) ⇒ ValueResult
18 19 20 21 22 23 24 |
# File 'lib/strong_csv/types/union.rb', line 18 def cast(value) results = @types.map { |type| type.cast(value) } results.find(&:success?) || results.reduce do |memo, result| memo..concat(result.).uniq! memo end end |