Module: ColorHelper
- Included in:
- OoxmlParser::Color
- Defined in:
- lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
Overview
Helper methods for color
Instance Method Summary collapse
-
#parse_hex_string(hex_string) ⇒ Object
Parse string in hex.
Instance Method Details
#parse_hex_string(hex_string) ⇒ Object
Parse string in hex
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ooxml_parser/common_parser/common_data/color/color_helper.rb', line 5 def parse_hex_string(hex_string) return self if %w[auto null].include?(hex_string) char_array = hex_string.split(//) if char_array.length == 3 @red = char_array[0].hex @green = char_array[1].hex @blue = char_array[2].hex elsif char_array.length == 6 @red = (char_array[0] + char_array[1]).hex @green = (char_array[2] + char_array[3]).hex @blue = (char_array[4] + char_array[5]).hex elsif char_array.length == 8 @alpha_channel = (char_array[0] + char_array[1]).hex @red = (char_array[2] + char_array[3]).hex @green = (char_array[4] + char_array[5]).hex @blue = (char_array[6] + char_array[7]).hex end self end |