Sha256: ceb1411bf1217607da250f30944e9cc4c37368d8431af5d34ac32b6c22f137ae

Contents?: true

Size: 899 Bytes

Versions: 4

Compression:

Stored size: 899 Bytes

Contents

module ExcelAbstraction
  class WorkBook < SimpleDelegator
    attr_accessor :active_sheet

    def initialize(file, format: :xls, skip_default_sheet: false)
      @format = format
      @file = file
      super(workbook)
      unless skip_default_sheet
        @active_sheet = ExcelAbstraction::Sheet.new(workbook.add_worksheet, workbook)
      end
    end


    def title(text)
      set_properties(title: text)
      self
    end

    def organization(name)
      set_properties(company: name)
      self
    end

    private

    attr_reader :format, :file

    def default_options
      {
        :font => 'Calibri',
        :size => 12,
        :align => 'center',
        :text_wrap => 1
      }
    end

    def workbook
      @workbook ||= if format == :xlsx
        WriteXLSX.new(file, default_options)
      else
        WriteExcel.new(file, default_options)
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
excel_templating-0.4.2 lib/excel_templating/excel_abstraction/work_book.rb
excel_templating-0.4.1 lib/excel_templating/excel_abstraction/work_book.rb
excel_templating-0.4.0 lib/excel_templating/excel_abstraction/work_book.rb
excel_templating-0.3.2 lib/excel_templating/excel_abstraction/work_book.rb