ntrwva
Last Updated: February 25, 2016
·
1.195K
· filiptepper
953d27ff0800b1be886aad4a4be8f03f

Convert CSS RGB value to HEX value

A simple function to convert CSS return value of capybara's evaluate_script call to $('.class).css('value') to HEX value:

def rgb_to_hex(value)
  %Q{
    ##{
      value.match(/[\d,\s]+/)[0].split(',').map(&:strip).map { |value|
        value.to_i.to_s(16).rjust(2, '0')
      }.join('')
    }
  }.strip
end
Say Thanks
Respond