Class: Necromancer::ArrayConverters::StringToArrayConverter
- Defined in:
- lib/necromancer/converters/array.rb
Overview
An object that converts a String to an Array
Instance Attribute Summary
Attributes inherited from Converter
#config, #convert, #source, #target
Instance Method Summary collapse
-
#call(value, strict: config.strict) ⇒ Object
Convert string value to array.
Methods inherited from Converter
create, #initialize, #raise_conversion_type
Constructor Details
This class inherits a constructor from Necromancer::Converter
Instance Method Details
#call(value, strict: config.strict) ⇒ Object
Convert string value to array
25 26 27 28 29 30 31 32 33 |
# File 'lib/necromancer/converters/array.rb', line 25 def call(value, strict: config.strict) return [] if value.to_s.empty? if match = value.to_s.match(ARRAY_MATCHER) value.to_s.split(match[:sep]) else strict ? raise_conversion_type(value) : Array(value) end end |