Class: CommandMapper::Types::KeyValueList

Inherits:
List
  • Object
show all
Defined in:
lib/command_mapper/types/key_value_list.rb

Overview

Represents a list of key=value pairs.

Instance Attribute Summary

Attributes inherited from List

#separator, #type

Instance Method Summary collapse

Methods inherited from List

#allow_empty?, #validate

Methods inherited from Type

#validate

Constructor Details

#initialize(separator: ',', key_value_separator: '=', **kwargs) ⇒ KeyValueList

Initializes the key-value list.

Parameters:

  • separator (String) (defaults to: ',')

    The list separator character (ex: ,).

  • key_value_separator (String) (defaults to: '=')

    The key-value separator (ex: =).

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for CommandMapper::Types::KeyValue#initialize.



23
24
25
26
27
28
# File 'lib/command_mapper/types/key_value_list.rb', line 23

def initialize(separator: ',', key_value_separator: '=', **kwargs)
  super(
    type:      KeyValue.new(separator: key_value_separator, **kwargs),
    separator: separator
  )
end

Instance Method Details

#format(value) ⇒ String

Formats the value.

Parameters:

  • value (Hash, Array((key, value)))

    The list of key-value pairs to format.

Returns:

  • (String)

    The formatted key-value list.



41
42
43
# File 'lib/command_mapper/types/key_value_list.rb', line 41

def format(value)
  super(Array(value).map(&@type.method(:format)))
end