docbrown/app/labor/hex_comparer.rb
rhymes e588fa7ece Code cleanups (#659)
* Initial automatic cleanup with rubocop

* Fix syntax error introduced by rubocop

* Cleanup seeds file

* Cleanup lib folder

* Exclude bin folder because it contains auto generated files

* Make Rubocop a little bit more chatty

* Block length should not include comments in the count

* Cleanup config folder

* Cleanup specs

* Updated Rubocop version and generated a todo file

* Fix broken ArticlesApi spec

* Fix tests

* Restored rubocop pre-commit hook
2018-08-07 11:00:13 -04:00

46 lines
1 KiB
Ruby

class HexComparer
attr_accessor :hexes, :amount
def initialize(hexes, amount = 1)
@hexes = hexes
@amount = amount
end
def order
hexes.sort
end
def smallest
order.first
end
def biggest
order.last
end
def brightness(amount = 1)
rgb = smallest.gsub("#", "").scan(/../).map(&:hex).map { |color| color * amount }.map(&:round)
"#%02x%02x%02x" % rgb
rescue StandardError
smallest
end
def accent
if brightness(1.14**amount).size == 7
brightness(1.14**amount)
elsif brightness(1.08**amount).size == 7
brightness(1.08**amount)
elsif brightness(1.06**amount).size == 7
brightness(1.06**amount)
elsif brightness(0.96**amount).size == 7
brightness(0.96**amount)
elsif brightness(0.9**amount).size == 7
brightness(0.9**amount)
elsif brightness(0.8**amount).size == 7
brightness(0.8**amount)
elsif brightness(0.7**amount).size == 7
brightness(0.7**amount)
elsif brightness(0.6**amount).size == 7
brightness(0.6**amount)
end
end
end