Class: OoxmlParser::DocumentStyle

Inherits:
OOXMLDocumentObject show all
Includes:
DocumentStyleHelper, TableStylePropertiesHelper
Defined in:
lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb

Overview

Class for describing styles containing in styles.xml

Constant Summary

Constants included from TableStylePropertiesHelper

TableStylePropertiesHelper::TABLE_STYLES_NAMES_HASH

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DocumentStyleHelper

#based_on_style, #document_style_by_id, #document_style_by_name, #style_exist?

Methods included from TableStylePropertiesHelper

#fill_empty_table_styles

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(parent: nil) ⇒ DocumentStyle

Returns a new instance of DocumentStyle.



35
36
37
38
39
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 35

def initialize(parent: nil)
  @q_format = false
  @table_style_properties_list = []
  @parent = parent
end

Instance Attribute Details

#based_onFixNum

Returns id of style on which this style is based.

Returns:

  • (FixNum)

    id of style on which this style is based



14
15
16
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 14

def based_on
  @based_on
end

#nameString

Returns name of style.

Returns:

  • (String)

    name of style



12
13
14
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 12

def name
  @name
end

#next_styleFixNum

Returns id of next style.

Returns:

  • (FixNum)

    id of next style



16
17
18
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 16

def next_style
  @next_style
end

#paragraph_propertiesDocxParagraph

Returns run properties.

Returns:



20
21
22
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 20

def paragraph_properties
  @paragraph_properties
end

#q_formatTrue, False Also known as: visible?

Used to determine if current style is visible in style list in editors According to www.wordarticles.com/Articles/WordStyles/LatentStyles.php

Returns:

  • (True, False)

    Latent Style Primary Style Setting



32
33
34
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 32

def q_format
  @q_format
end

#run_propertiesDocxParagraphRun

Returns run properties.

Returns:



18
19
20
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 18

def run_properties
  @run_properties
end

#style_idFixNum

Returns number of style.

Returns:

  • (FixNum)

    number of style



10
11
12
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 10

def style_id
  @style_id
end

#table_cell_propertiesCellProperties

Returns properties of table cell.

Returns:



28
29
30
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 28

def table_cell_properties
  @table_cell_properties
end

#table_propertiesTableProperties

Returns properties of table.

Returns:



22
23
24
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 22

def table_properties
  @table_properties
end

#table_row_propertiesTableRowProperties

Returns properties of table row.

Returns:



26
27
28
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 26

def table_row_properties
  @table_row_properties
end

#table_style_properties_listArray, TableStyleProperties

Returns list of table style properties.

Returns:



24
25
26
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 24

def table_style_properties_list
  @table_style_properties_list
end

#typeSymbol

Returns Type of style (:paragraph or :table).

Returns:

  • (Symbol)

    Type of style (:paragraph or :table)



8
9
10
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 8

def type
  @type
end

Class Method Details

.parse_list(parent) ⇒ Array, DocumentStyle

Parse all document style list

Returns:



90
91
92
93
94
95
96
97
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 90

def self.parse_list(parent)
  styles_array = []
  doc = Nokogiri::XML(File.open(OOXMLDocumentObject.path_to_folder + 'word/styles.xml'))
  doc.search('//w:style').each do |style|
    styles_array << DocumentStyle.new(parent: parent).parse(style)
  end
  styles_array
end

Instance Method Details

#inspectObject



45
46
47
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 45

def inspect
  to_s
end

#parse(node) ⇒ DocumentStyle

Parse single document style

Returns:



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 51

def parse(node)
  node.attributes.each do |key, value|
    case key
    when 'type'
      @type = value.value.to_sym
    when 'styleId'
      @style_id = value.value
    end
  end
  node.xpath('*').each do |subnode|
    case subnode.name
    when 'name'
      @name = subnode.attribute('val').value
    when 'basedOn'
      @based_on = subnode.attribute('val').value
    when 'next'
      @next_style = subnode.attribute('val').value
    when 'rPr'
      @run_properties = DocxParagraphRun.new.parse_properties(subnode)
    when 'pPr'
      @paragraph_properties = ParagraphProperties.new(parent: self).parse(subnode)
    when 'tblPr'
      @table_properties = TableProperties.new(parent: self).parse(subnode)
    when 'trPr'
      @table_row_properties = TableRowProperties.new(parent: self).parse(subnode)
    when 'tcPr'
      @table_cell_properties = CellProperties.new(parent: self).parse(subnode)
    when 'tblStylePr'
      @table_style_properties_list << TableStyleProperties.new(parent: self).parse(subnode)
    when 'qFormat'
      @q_format = true
    end
  end
  fill_empty_table_styles
  self
end

#to_sObject



41
42
43
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 41

def to_s
  "Table style properties list: #{@table_style_properties_list.join(',')}"
end