Class/Module Index [+]

Quicksearch

HammerCLI::Options::Normalizers::KeyValueList

Public Instance Methods

description() click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 25
def description
  _("Comma-separated list of key=value.")
end
format(val) click to toggle source
# File lib/hammer_cli/options/normalizers.rb, line 29
def format(val)
  return {} unless val.is_a?(String)
  return {} if val.empty?

  result = {}

  pair_re = '([^,=]+)=([^,\[]+|\[[^\[\]]*\])'
  full_re = "^((%s)[,]?)+$" % pair_re

  unless Regexp.new(full_re).match(val)
    raise ArgumentError, _("value must be defined as a comma-separated list of key=value")
  end

  val.scan(Regexp.new(pair_re)) do |key, value|
    value = value.strip
    value = value.scan(/[^,\[\]]+/) if value.start_with?('[')

    result[key.strip] = strip_value(value)
  end
  return result
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.