Use new color-proximity gem for better visual matching

This commit is contained in:
Garen Torikian
2015-04-03 18:25:13 -07:00
parent 3d69c047f0
commit 004f9b4710
2 changed files with 10 additions and 4 deletions

View File

@@ -23,5 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'pry' s.add_development_dependency 'pry'
s.add_development_dependency 'rake' s.add_development_dependency 'rake'
s.add_development_dependency 'yajl-ruby' s.add_development_dependency 'yajl-ruby'
s.add_development_dependency 'color-proximity' s.add_development_dependency 'color-proximity', '~> 0.2.1'
end end

View File

@@ -3,12 +3,18 @@ require_relative "./helper"
class TestColorThreshold < Minitest::Test class TestColorThreshold < Minitest::Test
include Linguist include Linguist
def cut_hash(color)
color[1..-1]
end
def test_color_threshold def test_color_threshold
langs_with_colors = Language.all.reject { |language| language.color.nil? } langs_with_colors = Language.all.reject { |language| language.color.nil? }
cp = ColorProximity.new(10, langs_with_colors.map(&:color)) cp = ColorProximity.new(0.02, langs_with_colors.map { |lang| cut_hash(lang.color) })
failing_threshold = langs_with_colors.map do |lang| failing_threshold = langs_with_colors.map do |lang|
state = cp.within_threshold?(lang.color[1..-1]) state = cp.past_threshold?(cut_hash(lang.color))
"- #{lang} (#{lang.color}) is close to #{state.last}" unless state.first if !state.first && lang.color != "##{state.last.first}"
"- #{lang} (#{lang.color}) is too close to #{state.last}"
end
end.compact end.compact
message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold.join("\n")}" message = "The following languages have failing color thresholds. Please modify the hex color.\n#{failing_threshold.join("\n")}"