Class: DataShift::ExcelGenerator

Inherits:
GeneratorBase show all
Includes:
ExcelBase
Defined in:
lib/datashift/generators/excel_generator.rb

Instance Attribute Summary collapse

Attributes included from ExcelBase

#sheet

Attributes inherited from GeneratorBase

#configuration

Instance Method Summary collapse

Methods included from ExcelBase

#ar_to_xls, #ar_to_xls_cell, #ar_to_xls_row, #exportable?, max_columns, #open_excel, #parse_headers, #sanitize_sheet_name, #start_excel

Methods included from Logging

#logdir, #logdir=, #logger, #verbose

Methods inherited from GeneratorBase

#generate_with_associations

Constructor Details

#initializeExcelGenerator

Returns a new instance of ExcelGenerator.



21
22
23
# File 'lib/datashift/generators/excel_generator.rb', line 21

def initialize
  super
end

Instance Attribute Details

#excelObject

Returns the value of attribute excel.



18
19
20
# File 'lib/datashift/generators/excel_generator.rb', line 18

def excel
  @excel
end

#file_nameObject

Returns the value of attribute file_name.



19
20
21
# File 'lib/datashift/generators/excel_generator.rb', line 19

def file_name
  @file_name
end

Instance Method Details

#generate(file_name, klass, options = {}) ⇒ Object

Create an Excel file template (header row) representing supplied Model file_name => Filename for generated template

See DataShift::Exporters::Configuration for options



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/datashift/generators/excel_generator.rb', line 30

def generate(file_name, klass, options = {})

  @file_name = file_name

  start_excel(klass, options)

  @headers = Headers.klass_to_headers(klass)

  @excel.set_headers(@headers)

  logger.info("ExcelGenerator saving generated template #{@file_name}")

  # @excel.autosize if(options[:autosize])

  @excel.write( @file_name )
end