Sha256: 892b6e92d5c4be1e5dd0157c73be1154695771145abad9d83531bffa93b64650

Contents?: true

Size: 1.79 KB

Versions: 32

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module OoxmlParser
  # Class for working with Table Margins
  class TableMargins < OOXMLDocumentObject
    attr_accessor :is_default, :top, :bottom, :left, :right

    def initialize(is_default = true, top = nil, bottom = nil, left = nil, right = nil, parent: nil)
      @is_default = is_default
      @top = top
      @bottom = bottom
      @left = left
      @right = right
      super(parent: parent)
    end

    # TODO: Separate @is_default attribute and remove this method
    # Compare this object to other
    # @param other [Object] any other object
    # @return [True, False] result of comparision
    def ==(other)
      instance_variables.each do |current_attribute|
        next if current_attribute == :@parent
        next if current_attribute == :@is_default
        return false unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
      end
      true
    end

    # @return [String] result of convert of object to string
    def to_s
      "Default: #{is_default} top: #{@top}, bottom: #{@bottom}, left: #{@left}, right: #{@right}"
    end

    # Parse TableMargins object
    # @param margin_node [Nokogiri::XML:Element] node to parse
    # @return [TableMargins] result of parsing
    def parse(margin_node)
      margin_node.xpath('*').each do |cell_margin_node|
        case cell_margin_node.name
        when 'left'
          @left = OoxmlSize.new(cell_margin_node.attribute('w').value.to_f)
        when 'top'
          @top = OoxmlSize.new(cell_margin_node.attribute('w').value.to_f)
        when 'right'
          @right = OoxmlSize.new(cell_margin_node.attribute('w').value.to_f)
        when 'bottom'
          @bottom = OoxmlSize.new(cell_margin_node.attribute('w').value.to_f)
        end
      end
      self
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

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