Class: OoxmlParser::DocumentStyle
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::DocumentStyle
- 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
-
#based_on ⇒ FixNum
Id of style on which this style is based.
-
#name ⇒ String
Name of style.
-
#next_style ⇒ FixNum
Id of next style.
-
#paragraph_properties ⇒ DocxParagraph
Run properties.
-
#q_format ⇒ True, False
(also: #visible?)
Used to determine if current style is visible in style list in editors According to www.wordarticles.com/Articles/WordStyles/LatentStyles.php.
-
#run_properties ⇒ DocxParagraphRun
Run properties.
-
#style_id ⇒ FixNum
Number of style.
-
#type ⇒ Symbol
Type of style (
:paragraphor:table).
Class Method Summary collapse
-
.parse(node) ⇒ DocumentStyle
Parse single document style.
-
.parse_list ⇒ Array, DocumentStyle
Parse all document style list.
Instance Method Summary collapse
-
#initialize ⇒ DocumentStyle
constructor
A new instance of DocumentStyle.
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
#initialize ⇒ DocumentStyle
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_on ⇒ FixNum
Returns 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 |
#name ⇒ String
Returns 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_style ⇒ FixNum
Returns 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_properties ⇒ DocxParagraph
Returns run properties.
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_format ⇒ True, 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
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_properties ⇒ DocxParagraphRun
Returns run properties.
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_id ⇒ FixNum
Returns 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 |
#type ⇒ Symbol
Returns 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
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_list ⇒ Array, DocumentStyle
Parse all document style list
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 |