class HtmlColor

Public Instance Methods

best_contrast(colors) click to toggle source
# File lib/generators/active_seed/templates/example_html_colors/html_color.rb, line 20
def best_contrast(colors)
  best_contrast = 0;
  return_color = "000000"
  colors.each do |c|
    contrast = self.luminosity_contrast(c)
    if contrast > best_contrast
      best_contrast = contrast
      return_color = c.hex_code
    end
  end
  return_color
end
blue() click to toggle source
# File lib/generators/active_seed/templates/example_html_colors/html_color.rb, line 41
def blue
  self.hex_code.to_i(16) & 255
end
green() click to toggle source
# File lib/generators/active_seed/templates/example_html_colors/html_color.rb, line 37
def green
  (self.hex_code.to_i(16) >> 8) & 255
end
luminosity_contrast(compare) click to toggle source
# File lib/generators/active_seed/templates/example_html_colors/html_color.rb, line 4
def luminosity_contrast(compare)
  lum1 = 0.2126 * (self.red/255 ** 2.2)
  + 0.7152 * (self.green/255 ** 2.2)
  + 0.0722 * (self.blue/255 ** 2.2)

  lum2 = 0.2126 * (compare.red/255 ** 2.2)
  + 0.7152 * (compare.green/255 ** 2.2)
  + 0.0722 * (compare.blue/255 ** 2.2)
 
  if(lum1 > lum2)
    return (lum1+0.05) / (lum2+0.05);
  else
    return (lum2+0.05) / (lum1+0.05);
  end
end
red() click to toggle source
# File lib/generators/active_seed/templates/example_html_colors/html_color.rb, line 33
def red
  (self.hex_code.to_i(16) >> 16) & 255
end