Sha256: 803c2ed4034cbfe8b807150f4ebbfcbe91d332e6acb4df23656ef0cfaa1d6b20

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module OoxmlParser
  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
      @parent = parent
    end

    # TODO: Separate @is_default attribute and remove this method
    def ==(other)
      instance_variables.each do |current_attribute|
        next if current_attribute == :@parent
        next if current_attribute == :@is_default
        unless instance_variable_get(current_attribute) == other.instance_variable_get(current_attribute)
          return false
        end
      end
      true
    end

    def to_s
      'Default: ' + is_default.to_s + ' top: ' + @top.to_s + ', bottom: ' + @bottom.to_s + ', left: ' + @left.to_s + ', right: ' + @right.to_s
    end

    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

1 entries across 1 versions & 1 rubygems

Version Path
ooxml_parser-0.2.0 lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb