Class: OoxmlParser::ParagraphProperties

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb

Constant Summary

Constants inherited from OOXMLDocumentObject

OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file

Constructor Details

#initialize(numbering = Numbering.new) ⇒ ParagraphProperties

Returns a new instance of ParagraphProperties.



8
9
10
11
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 8

def initialize(numbering = Numbering.new)
  @numbering = numbering
  @spacing = Spacing.new(0, 0, 1, :multiple)
end

Instance Attribute Details

#alignObject

Returns the value of attribute align.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def align
  @align
end

#indentObject

Returns the value of attribute indent.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def indent
  @indent
end

#levelObject

Returns the value of attribute level.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def level
  @level
end

#margin_leftObject

Returns the value of attribute margin_left.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def margin_left
  @margin_left
end

#margin_rightObject

Returns the value of attribute margin_right.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def margin_right
  @margin_right
end

#numberingObject

Returns the value of attribute numbering.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def numbering
  @numbering
end

#spacingObject

Returns the value of attribute spacing.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def spacing
  @spacing
end

#spacing_afterObject

Returns the value of attribute spacing_after.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def spacing_after
  @spacing_after
end

#spacing_beforeObject

Returns the value of attribute spacing_before.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def spacing_before
  @spacing_before
end

#tabsObject

Returns the value of attribute tabs.



5
6
7
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 5

def tabs
  @tabs
end

Class Method Details

.parse(paragraph_props_node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ooxml_parser/common_parser/common_data/paragraph/paragraph_properties.rb', line 13

def self.parse(paragraph_props_node)
  paragraph_properties = ParagraphProperties.new
  paragraph_properties.spacing.parse(paragraph_props_node)
  paragraph_props_node.attributes.each do |key, value|
    case key
    when 'algn'
      paragraph_properties.align = Alignment.parse(value)
    when 'lvl'
      paragraph_properties.level = value.value.to_i
    when 'indent'
      paragraph_properties.indent = (value.value.to_f / 360_000.0).round(2)
    when 'marR'
      paragraph_properties.margin_right = (value.value.to_f / 360_000.0).round(2)
    when 'marL'
      paragraph_properties.margin_left = (value.value.to_f / 360_000.0).round(2)
    end
  end
  paragraph_props_node.xpath('*').each do |properties_element|
    case properties_element.name
    when 'buSzPct'
      paragraph_properties.numbering.size = properties_element.attribute('val').value
    when 'buFont'
      paragraph_properties.numbering.font = properties_element.attribute('typeface').value
    when 'buChar'
      paragraph_properties.numbering.symbol = properties_element.attribute('char').value
    when 'buAutoNum'
      paragraph_properties.numbering.type = properties_element.attribute('type').value.to_sym
      paragraph_properties.numbering.start_at = properties_element.attribute('startAt').value if properties_element.attribute('startAt')
    when 'tabLst'
      paragraph_properties.tabs = ParagraphTab.parse(properties_element)
    end
  end
  paragraph_properties
end