Sha256: 9c9c87a9f9c47e2aa986556c5f3791f6d7629f50168d24ee3273a638dba89a3f
Contents?: true
Size: 942 Bytes
Versions: 15
Compression:
Stored size: 942 Bytes
Contents
module Paraduct class VariableConverter # @param variables [Hash{String => Array<String>}] Key: variable name, Value: values_pattern which you want to product # @return [Array<Hash{String => String}>] def self.product(variables) return [] if variables.empty? values_patterns = product_array(variables.values) product_variables = [] values_patterns.each do |values_pattern| entry = {} keys = variables.keys.to_enum values = values_pattern.to_enum loop do key = keys.next value = values.next entry[key] = value end product_variables << entry end product_variables end def self.product_array(array) first_values = array.shift if array.empty? first_values.product else first_values.product(*array) end end private_class_method :product_array end end
Version data entries
15 entries across 15 versions & 1 rubygems