Skip to content

Instantly share code, notes, and snippets.

@tooooolong
Created December 11, 2012 08:20
Show Gist options
  • Save tooooolong/4256851 to your computer and use it in GitHub Desktop.
Save tooooolong/4256851 to your computer and use it in GitHub Desktop.
def package_color_map(color_num)
tmp_hash = package_info
color_num.each do |nums|
i = 0
next if nums.blank?
package_info.each_with_index do |package, index|
colors = tmp_hash[index][:colors] || {}
package[:number].times do
color = nums[i]
i += 1
next if color.blank?
if colors.has_key? color
colors["#{color}"][0] += 1
else
colors["#{color}"] = [1, Color.find_by_num(color).try(:name)]
end
tmp_hash[index][:colors] = colors
end
end
end
tmp_hash
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment