Sha256: f660101438bde5e676cb1235af37c57ce4d2558e10a8794e6b2dd4b7d5a48de6

Contents?: true

Size: 1.45 KB

Versions: 15

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

15 entries across 15 versions & 1 rubygems

Version Path
ooxml_parser-0.24.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.23.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.22.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.21.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.20.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.19.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.18.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.18.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.17.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.16.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.15.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.14.2 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.14.1-mingw32 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.14.1 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb
ooxml_parser-0.14.0 lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_run/run_properties/shade.rb