Sha256: 78e46bf772b813d8aa1ee4367338072438509a31792238ef21a684ac912b76f6

Contents?: true

Size: 1.31 KB

Versions: 28

Compression:

Stored size: 1.31 KB

Contents

# -*- coding: utf-8 -*-

class WriteFile
  def initialize
    @data            = ''
    @datasize        = 0
    @limit           = 8224

    # Open a tmp file to store the majority of the Worksheet data. If this fails,
    # for example due to write permissions, store the data in memory. This can be
    # slow for large files.
    @filehandle = Tempfile.new('writeexcel')
    @filehandle.binmode

    # failed. store temporary data in memory.
    @using_tmpfile = @filehandle ? true : false
  end

  ###############################################################################
  #
  # _prepend($data)
  #
  # General storage function
  #
  def prepend(*args)
    data = join_data(args)
    @data = data + @data

    data
  end

  ###############################################################################
  #
  # _append($data)
  #
  # General storage function
  #
  def append(*args)
    data = join_data(args)

    if @using_tmpfile
      @filehandle.write(data)
    else
      @data += data
    end

    data
  end

  private

  def join_data(args)
    data =
      ruby_18 { args.join } ||
      ruby_19 { args.compact.collect{ |arg| arg.dup.force_encoding('ASCII-8BIT') }.join }
    # Add CONTINUE records if necessary
    data = add_continue(data) if data.bytesize > @limit

    @datasize += data.bytesize

    data
  end
end

Version data entries

28 entries across 28 versions & 3 rubygems

Version Path
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/write_file.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/writeexcel-0.6.13/lib/writeexcel/write_file.rb
writeexcel-0.6.13 lib/writeexcel/write_file.rb
ricardoo27-writeexcel-0.6.12.2 lib/writeexcel/write_file.rb
ricardoo27-writeexcel-0.6.12.1 lib/writeexcel/write_file.rb
writeexcel-0.6.12 lib/writeexcel/write_file.rb
writeexcel-0.6.11 lib/writeexcel/write_file.rb
writeexcel-0.6.10 lib/writeexcel/write_file.rb