Sha256: 45f295fb080819f2ac2fbbb05599143c6cb2cac094b49b56cad20b2c18029ebc

Contents?: true

Size: 1.45 KB

Versions: 17

Compression:

Stored size: 1.45 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class for parsing `w:shd` object
  class Shade < OOXMLDocumentObject
    # @return [Symbol] value of shade
    attr_accessor :value
    # @return [Symbol] color of shade
    attr_accessor :color
    # @return [Color] fill of shade
    attr_accessor :fill

    def initialize(value: nil,
                   color: nil,
                   fill: nil,
                   parent: nil)
      @value = value
      @color = color
      @fill = fill
      super(parent: parent)
    end

    # @return [String] text representation
    def to_s
      "Value: `#{value}`, " \
        "Color: `#{color}`, " \
        "Fill: `#{fill}`"
    end

    # Parse Shade
    # @param [Nokogiri::XML:Node] node with Shade
    # @return [Shade] result of parsing
    def parse(node)
      node.attributes.each do |key, value|
        case key
        when 'val'
          @value = value.value.to_sym
        when 'color'
          @color = value.value.to_sym
        when 'fill'
          @fill = Color.new(parent: self).parse_hex_string(value.value.to_s)
        end
      end
      self
    end

    # Helper method to get background color
    # @return [OoxmlParser::Color]
    def to_background_color
      return nil unless fill

      background_color = fill
      background_color.set_style(value) if value
      background_color
    end

    extend Gem::Deprecate
    deprecate :to_background_color, 'use shade direct methods', 2077, 1
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ooxml_parser-0.37.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.37.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.36.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.36.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.35.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.34.2 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.34.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.34.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.33.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.32.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.31.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.30.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.29.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.28.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.27.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.26.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.25.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb