Class: Selenium::WebDriver::Support::Color
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | rb/lib/selenium/webdriver/support/color.rb |
Constant Summary
-
HEX3_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 39/#(\h)(\h)(\h)/ -
HEX_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 38/#(\h{2})(\h{2})(\h{2})/ -
HSLA_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 43/^\s*hsla\(\s*(\d{1,3})\s*, \s*(\d{1,3})%\s*, \s*(\d{1,3})%\s*, \s*(0|1|0\.\d+)\s*\)\s*$/x -
HSL_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 40/^\s*hsl\(\s*(\d{1,3})\s*, \s*(\d{1,3})%\s*, \s*(\d{1,3})%\s*\)\s*$/x -
RGBA_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 30/^\s*rgba\(\s*(\d{1,3})\s*, \s*(\d{1,3})\s*, \s*(\d{1,3})\s*, \s*(0|1|0\.\d+)\s*\)\s*$/x -
RGBA_PCT_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 34/^\s*rgba\(\s*(\d{1,3}|\d{1,2}\.\d+) %\s*,\s*(\d{1,3}|\d{1,2}\.\d+) %\s*,\s*(\d{1,3}|\d{1,2}\.\d+) %\s*,\s*(0|1|0\.\d+)\s*\)\s*$/x -
RGB_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 24/^\s*rgb\(\s*(\d{1,3})\s*, \s*(\d{1,3})\s*, \s*(\d{1,3})\s*\)\s*$/x -
RGB_PCT_PATTERN =
# File 'rb/lib/selenium/webdriver/support/color.rb', line 27/^\s*rgb\(\s*(\d{1,3}|\d{1,2}\.\d+)%\s*, \s*(\d{1,3}|\d{1,2}\.\d+)%\s*, \s*(\d{1,3}|\d{1,2}\.\d+)%\s*\)\s*$/x
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #==(other) (also: #eql?)
-
#eql?(other)
Alias for #==.
- #hash
- #hex
- #rgb
- #rgba
Constructor Details
.new(red, green, blue, alpha = 1) ⇒ Color
Class Method Details
.from_hsl(hue, sat, light, alpha)
[ GitHub ]# File 'rb/lib/selenium/webdriver/support/color.rb', line 75
def self.from_hsl(hue, sat, light, alpha) hue = Float(hue) / 360 sat = Float(sat) / 100 light = Float(light) / 100 alpha = Float(alpha || 1) if sat.zero? r = light g = r b = r else luminocity2 = light < 0.5 ? light * (sat + 1) : light + sat - (light * sat) luminocity1 = (light * 2) - luminocity2 r = hue_to_rgb(luminocity1, luminocity2, hue + (1.0 / 3.0)) g = hue_to_rgb(luminocity1, luminocity2, hue) b = hue_to_rgb(luminocity1, luminocity2, hue - (1.0 / 3.0)) end new (r * 255).round, (g * 255).round, (b * 255).round, alpha end
.from_string(str)
[ GitHub ]# File 'rb/lib/selenium/webdriver/support/color.rb', line 50
def self.from_string(str) case str when RGB_PATTERN new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3) when RGB_PCT_PATTERN array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)] new(*array.map { |e| Float(e) / 100 * 255 }) when RGBA_PATTERN new Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4) when RGBA_PCT_PATTERN array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)] new(*array.map { |e| Float(e) / 100 * 255 } << Regexp.last_match(4)) when HEX_PATTERN array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)] new(*array.map { |e| e.to_i(16) }) when HEX3_PATTERN array = [Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3)] new(*array.map { |e| (e * 2).to_i(16) }) when HSL_PATTERN, HSLA_PATTERN from_hsl(Regexp.last_match(1), Regexp.last_match(2), Regexp.last_match(3), Regexp.last_match(4)) else raise ArgumentError, "could not convert #{str.inspect} into color" end end
.hue_to_rgb(lum1, lum2, hue)
[ GitHub ]# File 'rb/lib/selenium/webdriver/support/color.rb', line 97
def self.hue_to_rgb(lum1, lum2, hue) hue += 1 if hue < 0.0 hue -= 1 if hue > 1.0 if hue < 1.0 / 6.0 (lum1 + ((lum2 - lum1) * 6.0 * hue)) elsif hue < 1.0 / 2.0 lum2 elsif hue < 2.0 / 3.0 lum1 + ((lum2 - lum1) * ((2.0 / 3.0) - hue) * 6.0) else lum1 end end
Instance Attribute Details
#alpha (readonly)
[ GitHub ]#blue (readonly)
[ GitHub ]#green (readonly)
[ GitHub ]#red (readonly)
[ GitHub ]Instance Method Details
#==(other) Also known as: #eql?
[ GitHub ]#eql?(other)
Alias for #==.
# File 'rb/lib/selenium/webdriver/support/color.rb', line 125
alias eql? ==