Class: OoxmlParser::DocumentStyle

Inherits:
OOXMLDocumentObject show all
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 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

#initializeDocumentStyle

Returns a new instance of DocumentStyle.



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

def initialize
  @q_format = false
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



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

def based_on
  @based_on
end

#nameString

Returns name of style.

Returns:

  • (String)

    name of style



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

def name
  @name
end

#next_styleFixNum

Returns id of next style.

Returns:

  • (FixNum)

    id of next style



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

def next_style
  @next_style
end

#paragraph_propertiesDocxParagraph

Returns run properties.

Returns:



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

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



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

def q_format
  @q_format
end

#run_propertiesDocxParagraphRun

Returns run properties.

Returns:



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

def run_properties
  @run_properties
end

#style_idFixNum

Returns number of style.

Returns:

  • (FixNum)

    number of style



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

def style_id
  @style_id
end

#typeSymbol

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

Returns:

  • (Symbol)

    Type of style (:paragraph or :table)



5
6
7
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 5

def type
  @type
end

Class Method Details

.parse(node) ⇒ DocumentStyle

Parse single document style

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 30

def self.parse(node)
  document_style = DocumentStyle.new
  node.attributes.each do |key, value|
    case key
    when 'type'
      document_style.type = value.value.to_sym
    when 'styleId'
      document_style.style_id = value.value.to_i
    end
  end
  node.xpath('*').each do |subnode|
    case subnode.name
    when 'name'
      document_style.name = subnode.attribute('val').value
    when 'basedOn'
      document_style.based_on = subnode.attribute('val').value.to_i
    when 'next'
      document_style.next_style = subnode.attribute('val').value.to_i
    when 'rPr'
      document_style.run_properties = DocxParagraphRun.parse(subnode)
    when 'pPr'
      document_style.paragraph_properties = DocxParagraph.parse_paragraph_style(subnode)
    when 'qFormat'
      document_style.q_format = true
    end
  end
  document_style
end

.parse_listArray, DocumentStyle

Parse all document style list

Returns:



61
62
63
64
65
66
67
68
# File 'lib/ooxml_parser/docx_parser/docx_data/document_structure/document_style.rb', line 61

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