Sha256: 40965d448268c89a9b09194a501cc2081f0c3fc8cbdd66709ad5a143f11b550e

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Border Properties Data
  class BordersProperties < OOXMLDocumentObject
    attr_accessor :color, :space, :val, :shadow, :frame, :side
    # @return [OoxmlSize] size of border
    attr_reader :size

    def initialize(color = :auto, size = 0, val = :none, space = 0, parent: nil)
      @color = color
      @size = size
      @val = val
      @space = space
      @parent = parent
    end

    # @return [OoxmlSize] alias for sz
    def sz
      size
    end

    extend Gem::Deprecate
    deprecate :sz, 'size', 2020, 1

    def nil?
      size.zero? && val == :none
    end

    def to_s
      return '' if nil?

      "borders color: #{@color}, size: #{size}, space: #{@space}, value: #{@val}"
    end

    def copy
      BordersProperties.new(@color, size, @val, @space)
    end

    def visible?
      return false if nil?

      val != 'none'
    end

    # Parse BordersProperties
    # @param [Nokogiri::XML:Element] node with BordersProperties
    # @return [BordersProperties] value of BordersProperties
    def parse(node)
      return nil if node.attribute('val').value == 'nil'

      node.attributes.each do |key, value|
        case key
        when 'val'
          @val = value.value.to_sym
        when 'sz'
          @size = OoxmlSize.new(value.value.to_f, :one_eighth_point)
        when 'space'
          @space = OoxmlSize.new(value.value.to_f, :point)
        when 'color'
          @color = value.value.to_s
          @color = Color.new(parent: self).parse_hex_string(@color) if @color != 'auto'
        when 'shadow'
          @shadow = value.value
        end
      end
      self
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ooxml_parser-0.6.0 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.5.1 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.5.0 lib/ooxml_parser/common_parser/common_data/borders_properties.rb