Class: OoxmlParser::DocumentStyle
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::DocumentStyle
- 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
-
#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.
-
#table_cell_properties ⇒ CellProperties
Properties of table cell.
-
#table_properties ⇒ TableProperties
Properties of table.
-
#table_row_properties ⇒ TableRowProperties
Properties of table row.
-
#table_style_properties_list ⇒ Array, TableStyleProperties
List of table style properties.
-
#type ⇒ Symbol
Type of style (
:paragraph
or:table
).
Attributes inherited from OOXMLDocumentObject
Class Method Summary collapse
-
.parse_list(parent) ⇒ Array, DocumentStyle
Parse all document style list.
Instance Method Summary collapse
-
#initialize(parent: nil) ⇒ DocumentStyle
constructor
A new instance of DocumentStyle.
- #inspect ⇒ Object
-
#parse(node) ⇒ DocumentStyle
Parse single document style.
- #to_s ⇒ Object
Methods included from DocumentStyleHelper
#based_on_style, #document_style_by_id, #document_style_by_name, #style_exist?
Methods included from TableStylePropertiesHelper
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
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_on ⇒ FixNum
Returns 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 |
#name ⇒ String
Returns 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_style ⇒ FixNum
Returns 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_properties ⇒ DocxParagraph
Returns run properties.
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_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
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_properties ⇒ DocxParagraphRun
Returns run properties.
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_id ⇒ FixNum
Returns 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_properties ⇒ CellProperties
Returns properties of table cell.
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_properties ⇒ TableProperties
Returns properties of table.
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_properties ⇒ TableRowProperties
Returns properties of table row.
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_list ⇒ Array, TableStyleProperties
Returns list of table style properties.
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 |
#type ⇒ Symbol
Returns 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
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
#inspect ⇒ Object
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
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_s ⇒ Object
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 |