Class: OoxmlParser::TableMargins

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

Direct Known Subclasses

ParagraphMargins

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?

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.



5
6
7
8
9
10
11
12
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 5

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

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



3
4
5
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 3

def bottom
  @bottom
end

#is_defaultObject

Returns the value of attribute is_default.



3
4
5
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 3

def is_default
  @is_default
end

#leftObject

Returns the value of attribute left.



3
4
5
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 3

def left
  @left
end

#rightObject

Returns the value of attribute right.



3
4
5
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 3

def right
  @right
end

#topObject

Returns the value of attribute top.



3
4
5
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 3

def top
  @top
end

Instance Method Details

#==(other) ⇒ Object

TODO: Separate @is_default attribute and remove this method



15
16
17
18
19
20
21
22
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 15

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) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 28

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

#to_sObject



24
25
26
# File 'lib/ooxml_parser/common_parser/common_data/table/margins/table_margins.rb', line 24

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