Sha256: ac8c72d10e9df7a3073ec7ef72f5f8616c5200ccc0523c28d066351970bbb5c8

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'axlsx'
require_relative 'workbook'

module Smerp
  module Exporter
    module Excel

      class ExporterConfig
        attr_accessor :source
        attr_accessor :start_row, :start_col

        def initialize
          @start_row = 0
          @start_col = 0
        end
      end

      class Exporter
        include TR::CondUtils

        def self.instance
          Exporter.new 
        end

        def initialize
          @wbRec = {}
        end

        def start_cell(row, col = 0)
          config.start_row = row
          config.start_col = col

          trigger_config_changed
        end

        def start_col=(col)
          config.start_col = col
          trigger_config_changed
        end

        def start_row=(row)
          config.start_row = row
          trigger_config_changed
        end

        def worksheet(name, *args, &block)
          raise ExporterException, "Name is required" if is_empty?(name)
          workbook.worksheet(name, *args, &block) 
        end

        def save_to(output)
          writer.serialize(output) 
        end

        def config
          if @_config.nil?
            @_config = ExporterConfig.new
          end
          @_config
        end

        def writer
          if @_writer.nil?
            @_writer = Axlsx::Package.new
          end
          @_writer
        end

        def workbook
          if @_workbook.nil?
            wb = writer.workbook
            @_workbook = Workbook.new(wb, config)
          end
          @_workbook
        end

        def trigger_config_changed
          @wbRec.each do |k,v|
            v.config = config
          end
        end
        
        
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
smerp-exporter-excel-0.1.1 lib/smerp/exporter/excel/exporter.rb
smerp-exporter-excel-0.1.0 lib/smerp/exporter/excel/exporter.rb