Class: DatabaseDocumenter::Exporters::ExportToWord
- Inherits:
-
BaseExporter
- Object
- BaseExporter
- DatabaseDocumenter::Exporters::ExportToWord
- Defined in:
- lib/database_documenter/exporters/export_to_word.rb
Constant Summary
Constants inherited from BaseExporter
BaseExporter::APP_NAME, BaseExporter::HEADER_SECOND_LINE
Instance Attribute Summary
Attributes inherited from BaseExporter
#commented_cols_count, #generated_cols_count, #printed_tables, #table_data
Instance Method Summary collapse
- #add_word_footer(docx) ⇒ Object
- #add_word_header(docx) ⇒ Object
- #call ⇒ Object
- #generate_table_columns(docx, klass) ⇒ Object
- #generate_table_metadata(docx, klass) ⇒ Object
- #generate_word_document ⇒ Object
- #skip_class?(klass) ⇒ Boolean
Methods inherited from BaseExporter
Constructor Details
This class inherits a constructor from DatabaseDocumenter::Exporters::BaseExporter
Instance Method Details
#add_word_footer(docx) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 30 def (docx) docx.page_numbers true do align 'center' label DatabaseDocumenter.configuration..to_s end end |
#add_word_header(docx) ⇒ Object
37 38 39 40 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 37 def add_word_header(docx) docx.h1 "#{APP_NAME} Database Design" docx.p HEADER_SECOND_LINE end |
#call ⇒ Object
5 6 7 8 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 5 def call load_all_models generate_word_document end |
#generate_table_columns(docx, klass) ⇒ Object
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 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 68 def generate_table_columns(docx, klass) columns_header = ["Attribute", "Description", "Type", "Example of values"] columns = [] columns_data = table_data.get_columns_data(klass) columns_data.each do |col| data = [col[:name]] if col[:description_generated] self.generated_cols_count += 1 else self.commented_cols_count += 1 end broken_cell_para = Caracal::Core::Models::TableCellModel.new do |c| col[:description].flatten.each do |s| c.p s end end data << broken_cell_para data << col[:type] data << col[:value] columns << data end docx.page docx.table [columns_header] + columns, border_size: 4 do cell_style rows[0], background: 'e0e0e0', bold: true end end |
#generate_table_metadata(docx, klass) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 47 def (docx, klass) = table_data.(klass) docx.p '' docx.h2 klass.table_name.to_s docx.hr word_table = [ ["Table Name", [:name]], ["Description", [:description]], ["Primary Key", [:primary_key]], ["SQL Code", [:sql_code]] ] docx.table word_table, border_size: 4 do cell_style rows[0][0], background: 'b4b4b4', bold: true, width: 2000 cell_style rows[1][0], background: 'e0e0e0', bold: true, width: 2000 cell_style rows[2][0], background: 'e0e0e0', bold: true, width: 2000 cell_style rows[3][0], background: 'e0e0e0', bold: true, width: 2000 end end |
#generate_word_document ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 10 def generate_word_document Caracal::Document.save 'database.docx' do |docx| add_word_header(docx) (docx) ActiveRecord::Base.descendants.each do |klass| next if skip_class?(klass) printed_tables << klass.table_name (docx, klass) generate_table_columns(docx, klass) docx.page end end Rails.logger.info "Number of columns with generated description #{generated_cols_count}" Rails.logger.info "Number of columns with description from comments #{commented_cols_count}" end |
#skip_class?(klass) ⇒ Boolean
42 43 44 45 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 42 def skip_class?(klass) (klass.class.name != klass.base_class.class.name) || klass.abstract_class? || (printed_tables.include? klass.table_name) || (DatabaseDocumenter.configuration.skipped_modules.include? klass.parent.name) end |