Examples:
xform = StringValue::ToArray.new(fields: :r1, delim: ';')
input = [
{r1: 'a;b', r2: 'foo;bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: ['a','b'], r2: 'foo;bar'}
]
expect(result).to eq(expected)
Delimiter is not provided
xform = StringValue::ToArray.new(fields: :r1)
input = [
{r1: 'a|b', r2: 'foo|bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: ['a','b'], r2: 'foo|bar'}
]
expect(result).to eq(expected)
xform = StringValue::ToArray.new(fields: :r1, delim: nil)
input = [
{r1: 'a;b', r2: 'foo;bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: ['a;b'], r2: 'foo;bar'}
]
expect(result).to eq(expected)
Mulitple fields using default delimiter
xform = StringValue::ToArray.new(fields: [:r1,:r2])
input = [
{r1: 'a|b', r2: 'foo|bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: ['a','b'], r2: ['foo','bar']}
]
expect(result).to eq(expected)
Empty array when fieldval is nil and delim is nil
xform = StringValue::ToArray.new(fields: :r1, delim: nil)
input = [
{r1: nil, r2: 'foo;bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: [], r2: 'foo;bar'}
]
expect(result).to eq(expected)
Empty array when fieldval is nil
xform = StringValue::ToArray.new(fields: :r1)
input = [
{r1: nil, r2: 'foo;bar'}
]
result = input.map{|row| xform.process(row)}
expected = [
{r1: [], r2: 'foo;bar'}
]
expect(result).to eq(expected)