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

Version Path
paraduct-0.0.1.beta15 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta14 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta13 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta12 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta11 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta10 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta9 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta8 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta7 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta6 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta5 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta4 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta3 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta2 lib/paraduct/variable_converter.rb
paraduct-0.0.1.beta1 lib/paraduct/variable_converter.rb