Class: OoxmlParser::TableMargins

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb

Overview

Class for working with Table Margins

Direct Known Subclasses

ParagraphMargins

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(is_default = true, top = nil, bottom = nil, left = nil, right = nil, parent: nil) ⇒ TableMargins

Returns a new instance of TableMargins.



8
9
10
11
12
13
14
15
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 8

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

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 6

def bottom
  @bottom
end

#is_defaultObject

Returns the value of attribute is_default.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 6

def is_default
  @is_default
end

#leftObject

Returns the value of attribute left.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 6

def left
  @left
end

#rightObject

Returns the value of attribute right.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 6

def right
  @right
end

#topObject

Returns the value of attribute top.



6
7
8
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 6

def top
  @top
end

Instance Method Details

#==(other) ⇒ True, False

TODO: Separate @is_default attribute and remove this method Compare this object to other

Parameters:

  • other (Object)

    any other object

Returns:

  • (True, False)

    result of comparision



21
22
23
24
25
26
27
28
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 21

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

#parse(margin_node) ⇒ TableMargins

Parse TableMargins object

Parameters:

  • margin_node (Nokogiri::XML:Element)

    node to parse

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 38

def parse(margin_node)
  margin_node.xpath('*').each do |cell_margin_node|
    case cell_margin_node.name
    when 'left'
      @left = OoxmlSize.new(parent: self).parse(cell_margin_node)
    when 'top'
      @top = OoxmlSize.new(parent: self).parse(cell_margin_node)
    when 'right'
      @right = OoxmlSize.new(parent: self).parse(cell_margin_node)
    when 'bottom'
      @bottom = OoxmlSize.new(parent: self).parse(cell_margin_node)
    end
  end
  self
end

#to_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



31
32
33
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 31

def to_s
  "Default: #{is_default} top: #{@top}, bottom: #{@bottom}, left: #{@left}, right: #{@right}"
end