Class: API::Validations::Types::CommaSeparatedToArray

Inherits:
Object
  • Object
show all
Defined in:
lib/api/validations/types/comma_separated_to_array.rb

Direct Known Subclasses

CommaSeparatedToIntegerArray

Class Method Summary collapse

Class Method Details

.coerceObject



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/api/validations/types/comma_separated_to_array.rb', line 7

def self.coerce
  lambda do |value|
    case value
    when String
      value.split(',').map(&:strip)
    when Array
      value.flat_map { |v| v.to_s.split(',').map(&:strip) }
    else
      []
    end
  end
end