Class: OoxmlParser::DocxParagraph
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::DocxParagraph
- Extended by:
- Gem::Deprecate
- Includes:
- DocxParagraphHelper
- Defined in:
- lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb
Overview
Class for data of DocxParagraph
Instance Attribute Summary collapse
-
#align ⇒ Object
Returns the value of attribute align.
-
#borders ⇒ Object
Returns the value of attribute borders.
-
#character_style_array ⇒ Object
(also: #elements, #runs)
Returns the value of attribute character_style_array.
-
#contextual_spacing ⇒ Object
Returns the value of attribute contextual_spacing.
-
#field_simple ⇒ FieldSimple
readonly
Field simple.
-
#hyperlink ⇒ Hyperlink
readonly
Hyperlink in paragraph.
-
#inserted ⇒ Inserted
Data inserted by review.
-
#keep_lines ⇒ Object
Returns the value of attribute keep_lines.
-
#keep_next ⇒ Object
Returns the value of attribute keep_next.
-
#math_paragraph ⇒ MathParagraph
readonly
Math paragraph.
-
#number ⇒ Object
Returns the value of attribute number.
-
#numbering ⇒ Object
Returns the value of attribute numbering.
-
#orphan_control ⇒ Object
Returns the value of attribute orphan_control.
-
#page_break ⇒ Object
Returns the value of attribute page_break.
-
#page_numbering ⇒ Object
Returns the value of attribute page_numbering.
-
#paragraph_id ⇒ Integer
Id of paragraph (for comment).
-
#paragraph_properties ⇒ ParagraphProperties
Properties of current paragraph.
-
#section_break ⇒ Object
Returns the value of attribute section_break.
-
#sector_properties ⇒ Object
Returns the value of attribute sector_properties.
- #spacing ⇒ Object
-
#style ⇒ Object
Returns the value of attribute style.
-
#text_id ⇒ Integer
Id of text (for comment).
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#==(other) ⇒ True, False
Compare this object to other.
-
#fill_style_data(character_style) ⇒ void
Fill data from styles.
-
#ind ⇒ Indents
Value of indents.
-
#initialize(parent: nil) ⇒ DocxParagraph
constructor
A new instance of DocxParagraph.
-
#initialize_copy(source) ⇒ void
Constructor for copy of object.
-
#nonempty_runs ⇒ Array<OOXMLDocumentObject>
Array of child objects that contains data.
-
#parse(node, par_number = 0, default_character = DocxParagraphRun.new, parent: nil) ⇒ DocxParagraph
Parse object.
-
#parse_paragraph_style(node, default_char_style = DocxParagraphRun.new(parent: self)) ⇒ DocxParagraph
Parse style.
-
#sdt ⇒ OoxmlParser::StructuredDocumentTag
Return first sdt element.
-
#with_data? ⇒ True, false
If structure contain any user data.
Methods included from DocxParagraphHelper
#background_color, #comment_extend_data
Methods inherited from OOXMLDocumentObject
#boolean_attribute_value, #parse_xml
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ DocxParagraph
Returns a new instance of DocxParagraph.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 40 def initialize(parent: nil) @number = 0 @align = :left @spacing = Spacing.new @ind = Indents.new @character_style_array = [] @page_break = false @borders = Borders.new @keep_lines = false @contextual_spacing = false @page_numbering = false @keep_next = false @orphan_control = true super end |
Instance Attribute Details
#align ⇒ Object
Returns the value of attribute align.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def align @align end |
#borders ⇒ Object
Returns the value of attribute borders.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def borders @borders end |
#character_style_array ⇒ Object Also known as: elements, runs
Returns the value of attribute character_style_array.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def character_style_array @character_style_array end |
#contextual_spacing ⇒ Object
Returns the value of attribute contextual_spacing.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def contextual_spacing @contextual_spacing end |
#field_simple ⇒ FieldSimple (readonly)
Returns field simple.
30 31 32 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 30 def field_simple @field_simple end |
#hyperlink ⇒ Hyperlink (readonly)
Returns hyperlink in paragraph.
24 25 26 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 24 def hyperlink @hyperlink end |
#inserted ⇒ Inserted
Returns data inserted by review.
28 29 30 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 28 def inserted @inserted end |
#keep_lines ⇒ Object
Returns the value of attribute keep_lines.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def keep_lines @keep_lines end |
#keep_next ⇒ Object
Returns the value of attribute keep_next.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def keep_next @keep_next end |
#math_paragraph ⇒ MathParagraph (readonly)
Returns math paragraph.
34 35 36 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 34 def math_paragraph @math_paragraph end |
#number ⇒ Object
Returns the value of attribute number.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def number @number end |
#numbering ⇒ Object
Returns the value of attribute numbering.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def numbering @numbering end |
#orphan_control ⇒ Object
Returns the value of attribute orphan_control.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def orphan_control @orphan_control end |
#page_break ⇒ Object
Returns the value of attribute page_break.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def page_break @page_break end |
#page_numbering ⇒ Object
Returns the value of attribute page_numbering.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def page_numbering @page_numbering end |
#paragraph_id ⇒ Integer
Returns id of paragraph (for comment).
32 33 34 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 32 def paragraph_id @paragraph_id end |
#paragraph_properties ⇒ ParagraphProperties
Returns Properties of current paragraph.
26 27 28 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 26 def paragraph_properties @paragraph_properties end |
#section_break ⇒ Object
Returns the value of attribute section_break.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def section_break @section_break end |
#sector_properties ⇒ Object
Returns the value of attribute sector_properties.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def sector_properties @sector_properties end |
#spacing ⇒ Object
226 227 228 229 230 231 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 226 def spacing style_spacing = root_object.styles&.default_style(:paragraph)&.paragraph_properties&.spacing return Spacing.new.fetch_from_valued_spacing(style_spacing) if style_spacing @spacing end |
#style ⇒ Object
Returns the value of attribute style.
19 20 21 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 19 def style @style end |
#text_id ⇒ Integer
Returns id of text (for comment).
38 39 40 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 38 def text_id @text_id end |
Instance Method Details
#==(other) ⇒ True, False
Compare this object to other
89 90 91 92 93 94 95 96 97 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 89 def ==(other) ignored_attributes = %i[@number @parent] all_instance_variables = instance_variables significan_attribues = all_instance_variables - ignored_attributes significan_attribues.each do |current_attributes| return false unless instance_variable_get(current_attributes) == other.instance_variable_get(current_attributes) end true end |
#fill_style_data(character_style) ⇒ void
This method returns an undefined value.
Fill data from styles
246 247 248 249 250 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 246 def fill_style_data(character_style) @style = root_object.document_style_by_id(@paragraph_style_ref.value) parse_paragraph_style(@style.paragraph_properties_node, character_style) if @style.paragraph_properties_node character_style.parse_properties(@style.run_properties_node) if @style.run_properties_node end |
#ind ⇒ Indents
Returns value of indents.
234 235 236 237 238 239 240 241 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 234 def ind return @ind if @ind != Indents.new indents_from_styles = root_object.styles&.default_style(:paragraph)&.paragraph_properties&.indent return indents_from_styles if indents_from_styles Indents.new end |
#initialize_copy(source) ⇒ void
This method returns an undefined value.
Constructor for copy of object
61 62 63 64 65 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 61 def initialize_copy(source) super @character_style_array = source.character_style_array.clone @spacing = source.instance_variable_get(:@spacing).clone end |
#nonempty_runs ⇒ Array<OOXMLDocumentObject>
Returns array of child objects that contains data.
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 68 def nonempty_runs @character_style_array.select do |cur_run| case cur_run when DocxParagraphRun, ParagraphRun !cur_run.empty? when DocxFormula, StructuredDocumentTag, BookmarkStart, BookmarkEnd, CommentRangeStart, CommentRangeEnd true end end end |
#parse(node, par_number = 0, default_character = DocxParagraphRun.new, parent: nil) ⇒ DocxParagraph
Parse object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 105 def parse(node, par_number = 0, default_character = DocxParagraphRun.new, parent: nil) @parent ||= parent default_character_style = default_character.dup character_styles_array = [] custom_character_style = default_character_style.dup custom_character_style.parent = self char_number = 0 node.attributes.each do |key, value| case key when 'paraId' @paragraph_id = value.value.to_i when 'textId' @text_id = value.value.to_i end end node.xpath('*').each do |node_child| case node_child.name when 'bookmarkStart' character_styles_array << BookmarkStart.new(parent: self).parse(node_child) when 'bookmarkEnd' character_styles_array << BookmarkEnd.new(parent: self).parse(node_child) when 'pPr' @paragraph_properties = ParagraphProperties.new(parent: self).parse(node_child) parse_paragraph_style(node_child, custom_character_style) when 'commentRangeStart' character_styles_array << CommentRangeStart.new(parent: self).parse(node_child) when 'commentRangeEnd' character_styles_array << CommentRangeEnd.new(parent: self).parse(node_child) when 'fldSimple' @field_simple = FieldSimple.new(parent: self).parse(node_child) @page_numbering = true if field_simple.page_numbering? character_styles_array += field_simple.runs when 'r' run = custom_character_style.dup node_child.xpath('w:instrText').each do |insrt_text| @page_numbering = true if insrt_text.text.include?('PAGE') end run.parse(node_child, char_number, parent: self) character_styles_array << run char_number += 1 when 'hyperlink' @hyperlink = Hyperlink.new(parent: self).parse(node_child) node_child.xpath('w:r').each do |r_tag| hyperlink_run = default_character_style.dup hyperlink_run.parent = self if @hyperlink.id @hyperlink.parent = hyperlink_run hyperlink_run.link = @hyperlink elsif @hyperlink.anchor hyperlink_run.link = @hyperlink.anchor end hyperlink_run.parse(r_tag, char_number, parent: self) character_styles_array << hyperlink_run char_number += 1 end node_child.xpath('w:fldSimple').each do |simple_field| hyperlink_field_simple = FieldSimple.new(parent: self).parse(simple_field) character_styles_array += hyperlink_field_simple.runs end when 'oMathPara' @math_paragraph = MathParagraph.new(parent: self).parse(node_child) character_styles_array << math_paragraph.math when 'ins' @inserted = Inserted.new(parent: self).parse(node_child) when 'sdt' character_styles_array << StructuredDocumentTag.new(parent: self).parse(node_child) end end @number = par_number character_styles_array.last.text = character_styles_array.last.text.rstrip if character_styles_array.last.instance_of?(DocxParagraphRun) @character_style_array = character_styles_array @parent = parent self end |
#parse_paragraph_style(node, default_char_style = DocxParagraphRun.new(parent: self)) ⇒ DocxParagraph
Parse style
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 184 def parse_paragraph_style(node, default_char_style = DocxParagraphRun.new(parent: self)) node.xpath('*').each do |node_child| case node_child.name when 'pageBreakBefore' @page_break = true if node_child.attribute('val').nil? || node_child.attribute('val').value != 'false' when 'pBdr' @borders = ParagraphBorders.new(parent: self).parse(node_child) when 'keepLines' if node_child.attribute('val').nil? @keep_lines = true else @keep_lines = true unless node_child.attribute('val').value == 'false' end when 'widowControl' @orphan_control = option_enabled?(node_child) when 'keepNext' @keep_next = true when 'contextualSpacing' @contextual_spacing = true when 'pStyle' @paragraph_style_ref = ParagraphStyleRef.new(parent: self).parse(node_child) fill_style_data(default_char_style) when 'ind' @ind = root_object.default_paragraph_style.instance_variable_get(:@ind).dup.parse(node_child) when 'numPr' @numbering = NumberingProperties.new(parent: self).parse(node_child) when 'jc' @justification_object = ValuedChild.new(:string, parent: self).parse(node_child) @align = @justification_object.value.to_sym unless @justification_object.value.nil? @align = :justify if @justification_object.value == 'both' when 'spacing' @valued_spacing = ParagraphSpacing.new(parent: self).parse(node_child) @spacing = @spacing.fetch_from_valued_spacing(@valued_spacing) when 'sectPr' @sector_properties = PageProperties.new(parent: self).parse(node_child, self, default_char_style) @section_break ||= @sector_properties.section_break end end @parent = parent self end |
#sdt ⇒ OoxmlParser::StructuredDocumentTag
Return first sdt element
256 257 258 259 260 261 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 256 def sdt @character_style_array.each do |cur_element| return cur_element if cur_element.is_a?(StructuredDocumentTag) end nil end |
#with_data? ⇒ True, false
Returns if structure contain any user data.
82 83 84 |
# File 'lib/ooxml_parser/docx_parser/document_structure/docx_paragraph.rb', line 82 def with_data? !nonempty_runs.empty? || paragraph_properties&.section_properties end |