Class: OoxmlParser::DocumentStyle

Inherits:
OOXMLDocumentObject show all
Includes:
DocumentStyleHelper, TableStylePropertiesHelper
Defined in:
lib/ooxml_parser/docx_parser/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

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

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

#initialize(parent: nil) ⇒ DocumentStyle

Returns a new instance of DocumentStyle.



47
48
49
50
51
# File 'lib/ooxml_parser/docx_parser/document_structure/document_style.rb', line 47

def initialize(parent: nil)
  @q_format = false
  @table_style_properties_list = []
  super
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



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

def based_on
  @based_on
end

#defaultTrue, False (readonly)

Returns is style default.

Returns:

  • (True, False)

    is style default



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

def default
  @default
end

#nameString

Returns name of style.

Returns:

  • (String)

    name of style



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

def name
  @name
end

#next_styleFixNum

Returns id of next style.

Returns:

  • (FixNum)

    id of next style



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

def next_style
  @next_style
end

#paragraph_propertiesDocxParagraph

Returns run properties.

Returns:



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

def paragraph_properties
  @paragraph_properties
end

#paragraph_properties_nodeNokogiri::XML:Node

Returns paragraph properties node.

Returns:

  • (Nokogiri::XML:Node)

    paragraph properties node



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

def paragraph_properties_node
  @paragraph_properties_node
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



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

def q_format
  @q_format
end

#raw_nodeNokogiri::XML:Element (readonly)

Returns raw node value.

Returns:

  • (Nokogiri::XML:Element)

    raw node value



43
44
45
# File 'lib/ooxml_parser/docx_parser/document_structure/document_style.rb', line 43

def raw_node
  @raw_node
end

#run_propertiesDocxParagraphRun

Returns run properties.

Returns:



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

def run_properties
  @run_properties
end

#run_properties_nodeNokogiri::XML:Node

Returns run properties node.

Returns:

  • (Nokogiri::XML:Node)

    run properties node



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

def run_properties_node
  @run_properties_node
end

#style_idFixNum

Returns number of style.

Returns:

  • (FixNum)

    number of style



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

def style_id
  @style_id
end

#table_cell_propertiesCellProperties

Returns properties of table cell.

Returns:



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

def table_cell_properties
  @table_cell_properties
end

#table_propertiesTableProperties

Returns properties of table.

Returns:



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

def table_properties
  @table_properties
end

#table_row_propertiesTableRowProperties

Returns properties of table row.

Returns:



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

def table_row_properties
  @table_row_properties
end

#table_style_properties_listArray, TableStyleProperties

Returns list of table style properties.

Returns:



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

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)



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

def type
  @type
end

Instance Method Details

#inspectString

Returns inspect of object for debug means.

Returns:

  • (String)

    inspect of object for debug means



59
60
61
# File 'lib/ooxml_parser/docx_parser/document_structure/document_style.rb', line 59

def inspect
  to_s
end

#parse(node) ⇒ DocumentStyle

Parse single document style

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/ooxml_parser/docx_parser/document_structure/document_style.rb', line 65

def parse(node)
  @raw_node = node
  node.attributes.each do |key, value|
    case key
    when 'type'
      @type = value.value.to_sym
    when 'styleId'
      @style_id = value.value
    when 'default'
      @default = attribute_enabled?(value.value)
    end
  end
  node.xpath('*').each do |subnode|
    case subnode.name
    when 'name'
      @name_object = ValuedChild.new(:string, parent: self).parse(subnode)
      @name = @name_object.value
    when 'basedOn'
      @based_on_object = ValuedChild.new(:string, parent: self).parse(subnode)
      @based_on = @based_on_object.value
    when 'next'
      @next_style_object = ValuedChild.new(:string, parent: self).parse(subnode)
      @next_style = @next_style_object.value
    when 'rPr'
      @run_properties_node = subnode
      @run_properties = DocxParagraphRun.new(parent: self).parse_properties(@run_properties_node)
    when 'pPr'
      @paragraph_properties_node = subnode
      @paragraph_properties = ParagraphProperties.new(parent: self).parse(@paragraph_properties_node)
    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_sString

Returns result of convert of object to string.

Returns:

  • (String)

    result of convert of object to string



54
55
56
# File 'lib/ooxml_parser/docx_parser/document_structure/document_style.rb', line 54

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