Class: DatabaseDocumenter::Exporters::ExportToWord
- Inherits:
-
Object
- Object
- DatabaseDocumenter::Exporters::ExportToWord
- Defined in:
- lib/database_documenter/exporters/export_to_word.rb
Instance Attribute Summary collapse
-
#commented_cols_count ⇒ Object
Returns the value of attribute commented_cols_count.
-
#generated_cols_count ⇒ Object
Returns the value of attribute generated_cols_count.
-
#printed_tables ⇒ Object
Returns the value of attribute printed_tables.
-
#table_data ⇒ Object
Returns the value of attribute 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
-
#initialize ⇒ ExportToWord
constructor
A new instance of ExportToWord.
- #load_all_models ⇒ Object
- #skip_class?(klass) ⇒ Boolean
Constructor Details
#initialize ⇒ ExportToWord
7 8 9 10 11 12 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 7 def initialize self.table_data = DatabaseDocumenter::TableData.new self.printed_tables = [] self.generated_cols_count = 0 self.commented_cols_count = 0 end |
Instance Attribute Details
#commented_cols_count ⇒ Object
Returns the value of attribute commented_cols_count.
5 6 7 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 5 def commented_cols_count @commented_cols_count end |
#generated_cols_count ⇒ Object
Returns the value of attribute generated_cols_count.
5 6 7 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 5 def generated_cols_count @generated_cols_count end |
#printed_tables ⇒ Object
Returns the value of attribute printed_tables.
5 6 7 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 5 def printed_tables @printed_tables end |
#table_data ⇒ Object
Returns the value of attribute table_data.
5 6 7 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 5 def table_data @table_data end |
Instance Method Details
#add_word_footer(docx) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 46 def (docx) docx.page_numbers true do align 'center' label DatabaseDocumenter.configuration..to_s end end |
#add_word_header(docx) ⇒ Object
53 54 55 56 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 53 def add_word_header(docx) docx.h1 "Database Design" docx.p "The database design specifies how the data of the software is going to be stored." end |
#call ⇒ Object
14 15 16 17 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 14 def call load_all_models generate_word_document end |
#generate_table_columns(docx, klass) ⇒ Object
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 109 110 111 112 113 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 84 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
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 63 def (docx, klass) = table_data.(klass) docx.p '' docx.h2 "#{klass.table_name} schema" 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
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 23 def generate_word_document Caracal::Document.save 'database.docx' do |docx| add_word_header(docx) (docx) ActiveRecord::Base.descendants.each do |klass| # Skip STI classes # Skip duplicate tables in case of has_and_belongs_to_many # Skip certain modules 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 |
#load_all_models ⇒ Object
19 20 21 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 19 def load_all_models Rails.application.eager_load! end |
#skip_class?(klass) ⇒ Boolean
58 59 60 61 |
# File 'lib/database_documenter/exporters/export_to_word.rb', line 58 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 |