# # Ruby CSS Color Module # module ColorUtil def get_rgb(value) if value =~ /^#?(\[a-fA-F0-9\]+)$/ c = $1 if c.length == 3 return Array.new(3) { |i| (c\[i,1\] \* 2).hex } elsif c.length == 6 return \[ c\[0,2\].hex, c\[2,2\].hex, c\[4,2\].hex \] end end raise "format error" end def get_value(rgb) c = "#" rgb.each { |x| c += format("%02x", x) } return c end end