Sha256: 22d8eada43221927b655e4aee7c2e6d9661b5dd50ec42ee14969de374f988bad

Contents?: true

Size: 1.81 KB

Versions: 36

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class for parsing `color` tag
  class OoxmlColor < OOXMLDocumentObject
    # @return [Color] value of color
    attr_reader :value
    # @return [Symbol] theme color name
    attr_reader :theme_color
    # @return [Symbol] theme shade
    attr_reader :theme_shade
    # @return [Integer] theme index
    attr_reader :theme
    # @return [Float] tint
    attr_reader :tint
    # @return [Float] Indexed id
    attr_reader :indexed
    # @return [Color] rgb color
    attr_reader :rgb

    # Convert OoxmlColor to other color type
    # @return [Object] result of conversion
    def to_color
      return Color.get_rgb_by_color_index(indexed) if indexed
      return ThemeColors.new(parent: self).parse_color_theme(theme, tint) if theme
      return rgb if rgb

      value
    end

    # Compare this object to other
    # @param other [Object] any other object
    # @return [True, False] result of comparision
    def ==(other)
      return to_color == other if other.is_a?(Color)
      return to_color == other if other.is_a?(Symbol)

      super
    end

    # Parse OoxmlColor object
    # @param node [Nokogiri::XML:Element] node to parse
    # @return [OoxmlColor] result of parsing
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 'val'
          @value = Color.new.parse_hex_string(value.value.to_s)
        when 'themeColor'
          @theme_color = value.value.to_sym
        when 'themeShade'
          @theme_shade = Integer("0x#{value.value}")
        when 'theme'
          @theme = value.value.to_i
        when 'tint'
          @tint = value.value.to_f
        when 'indexed'
          @indexed = value.value.to_i
        when 'rgb'
          @rgb = Color.new.parse_hex_string(value.value)
        end
      end
      self
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
ooxml_parser-0.32.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.31.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.30.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.29.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.28.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.27.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.26.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.25.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.24.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.23.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.22.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.21.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.20.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.19.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.18.1 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.18.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.17.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.16.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.15.0 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb
ooxml_parser-0.14.2 lib/ooxml_parser/common_parser/common_data/color/ooxml_color.rb