Sha256: 5dbbdba0b3bf9fefc22a8fa8f7f5610632493e77767f0434021b36bb7d83ea47

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 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

    # @return [String] result of convert of object to string
    def to_s
      return '' if nil?

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

    # Method to copy object
    # @return [BordersProperties] copied object
    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

5 entries across 5 versions & 1 rubygems

Version Path
ooxml_parser-0.8.1 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.8.0 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.7.2 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.7.1 lib/ooxml_parser/common_parser/common_data/borders_properties.rb
ooxml_parser-0.7.0 lib/ooxml_parser/common_parser/common_data/borders_properties.rb