50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File '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
|