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
Instance Method Summary collapse
-
#call(value, options = {}) ⇒ Object
Convert string value to array.
Methods inherited from Converter
create, #fail_conversion_type, #initialize
Constructor Details
This class inherits a constructor from Necromancer::Converter
Instance Method Details
#call(value, options = {}) ⇒ Object
Convert string value to array
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/necromancer/converters/array.rb', line 21 def call(value, = {}) strict = .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 |