Skip to content

Instantly share code, notes, and snippets.

@originalhat
Created January 15, 2013 05:34
Show Gist options
  • Save originalhat/4536437 to your computer and use it in GitHub Desktop.
Save originalhat/4536437 to your computer and use it in GitHub Desktop.
find hash permutations that are not whitelisted, and are not duplicated.
# combinations that may have the same colors
no_matches = [
  %w(primary link),
  %w(secondary first_hover),
  %w(secondary second_hover),
]

# obtain all color combinations
valid_permutations = STYLE_ATTRIBUTE_NAMES.permutation(2).to_a

# keep unique combinations
valid_permutations.each { |p| valid_permutations.delete p if valid_permutations.include? p.reverse }

# remove whitelisted combinations
no_matches.each do |no_match|
  valid_permutations.delete no_match
  valid_permutations.delete no_match.reverse
end

# check for overlapping values /colors
valid_permutations.each do |p|
  if attributes_hash[p[0]] and attributes_hash[p[1]]
    if attributes_hash[p[0]].downcase == attributes_hash[p[1]].downcase
      abort ">> Duplicate color: '#{p[0]}' '#{p[1]}'"
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment