Sha256: 7ac9fb6d5e86bd321078b306aee23f066dd72d8c8b80b2769b509ececcd6a125

Contents?: true

Size: 939 Bytes

Versions: 6

Compression:

Stored size: 939 Bytes

Contents

# frozen_string_literal: true

module OoxmlParser
  # Helper methods for color
  module ColorHelper
    # Parse string in hex
    # @param [String] hex_string with or without alpha-channel
    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
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ooxml_parser-0.7.2 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
ooxml_parser-0.7.1 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
ooxml_parser-0.7.0 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
ooxml_parser-0.6.0 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
ooxml_parser-0.5.1 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb
ooxml_parser-0.5.0 lib/ooxml_parser/common_parser/common_data/color/color_helper.rb