class Paraduct::VariableConverter

Public Class Methods

partial_match?(parent_hash, child_hash) click to toggle source
# File lib/paraduct/variable_converter.rb, line 33
def self.partial_match?(parent_hash, child_hash)
  child_hash.each do |k, v|
    return false unless parent_hash[k] == v
  end
  true
end
product(variables) click to toggle source

@param variables [Hash{String => Array<String>}] Key: variable name, Value: values_pattern which you want to product @return [Array<Hash{String => String}>]

# File lib/paraduct/variable_converter.rb, line 5
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
reject(product_variables, exclude_variables) click to toggle source
# File lib/paraduct/variable_converter.rb, line 27
def self.reject(product_variables, exclude_variables)
  product_variables.each_with_object([]) do |variables, rejected_product_variables|
    rejected_product_variables << variables unless exclude_variables.any? { |exclude| partial_match?(variables, exclude) }
  end
end

Private Class Methods

product_array(array) click to toggle source
# File lib/paraduct/variable_converter.rb, line 40
def self.product_array(array)
  first_values = array.shift
  if array.empty?
    first_values.product
  else
    first_values.product(*array)
  end
end