# This transforms any captured variables to an array that are formatted like this:
# "[foo, bar, baz]" => ['foo', 'bar', 'baz']
#
# You can use that in cucumber_factory steps to assign list attributes, for example:
# Given there is a topic list with the topics "[foo, bar, baz]"
#
ParameterTypeProxy.add(
  name: 'array',
  regexp: /\[([^"\[\]]*)\]/,
  type: Array,
  transformer: lambda do |array|
    result = array.split(',').collect(&:strip)
    result.map! do |entry|
      # check if we actually have an integer here
      if entry.to_i.to_s == entry
        entry.to_i
      else
        entry
      end
    end
  end
)
