Class: OoxmlParser::Paragraph

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

Overview

Class for parsing ‘p` tags

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(runs = [], formulas = [], parent: nil) ⇒ Paragraph

Returns a new instance of Paragraph.



13
14
15
16
17
18
19
20
# File 'lib/ooxml_parser/common_parser/common_data/paragraph.rb', line 13

def initialize(runs = [],
               formulas = [],
               parent: nil)
  @runs = runs
  @formulas = formulas
  @runs = []
  super(parent: parent)
end

Instance Attribute Details

#alternate_contentAlternateContent

Returns alternate content data.

Returns:



11
12
13
# File 'lib/ooxml_parser/common_parser/common_data/paragraph.rb', line 11

def alternate_content
  @alternate_content
end

#formulasObject

Returns the value of attribute formulas.



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

def formulas
  @formulas
end

#propertiesObject

Returns the value of attribute properties.



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

def properties
  @properties
end

#runsObject Also known as: characters, character_style_array

Returns the value of attribute runs.



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

def runs
  @runs
end

#text_fieldObject

Returns the value of attribute text_field.



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

def text_field
  @text_field
end

Instance Method Details

#parse(node) ⇒ Paragraph

Parse Paragraph object

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ooxml_parser/common_parser/common_data/paragraph.rb', line 30

def parse(node)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'pPr'
      @properties = ParagraphProperties.new(parent: self).parse(node_child)
    when 'fld'
      @text_field = TextField.new(parent: self).parse(node_child)
    when 'r'
      @runs << ParagraphRun.new(parent: self).parse(node_child)
    when 'AlternateContent'
      @alternate_content = AlternateContent.new(parent: self).parse(node_child)
    end
  end
  self
end