class Necromancer::ArrayConverters::StringToArrayConverter
An object that converts a String to an Array
Public Instance Methods
call(value, options = {})
click to toggle source
Convert string value to array
@example
converter.call('a, b, c') # => ['a', 'b', 'c']
@example
converter.call('1 - 2 - 3') # => [1, 2, 3]
@api public
# File lib/necromancer/converters/array.rb, line 20 def call(value, options = {}) strict = options.fetch(:strict, config.strict) case value.to_s when /^\s*?((\d+)(\s*(,|-)\s*)?)+\s*?$/ value.to_s.split($4).map(&:to_i) when /^((\w)(\s*(,|-)\s*)?)+$/ value.to_s.split($4) else strict ? fail_conversion_type(value) : Array(value) end end