Sha256: 148bc493deeffd7de7f06d938b537597dec631a6e48188d0bd696bb7b76a3cfe
Contents?: true
Size: 1.01 KB
Versions: 5
Compression:
Stored size: 1.01 KB
Contents
module TelphinApi # An utility module able to flatten arguments (join arrays into comma-separated strings). module Utils class << self # A multiple version of `#flatten_argument`. It transforms a hash flattening each value and keeping the keys untouched. # @param [Hash] arguments The arguments to flatten. # @return [Hash] Flattened arguments. def flatten_arguments(arguments) arguments.inject({}) do |flat_args, (arg_name, arg_value)| flat_args[arg_name] = flatten_argument(arg_value) flat_args end end # If an argument is an array, it will be joined with a comma; otherwise it'll be returned untouched. # @param [Object] argument The argument to flatten. def flatten_argument(argument) if argument.respond_to?(:join) # if argument is an array, we join it with a comma argument.join(',') else # otherwise leave it untouched argument end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems