Class: WriteFile

Inherits:
Object
  • Object
show all
Defined in:
lib/writeexcel/write_file.rb

Direct Known Subclasses

BIFFWriter

Instance Method Summary collapse

Constructor Details

#initializeWriteFile

Returns a new instance of WriteFile


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/writeexcel/write_file.rb', line 4

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

Instance Method Details

#append(*args) ⇒ Object

_append($data)

General storage function


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/writeexcel/write_file.rb', line 38

def append(*args)
  data = join_data(args)

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

  data
end

#prepend(*args) ⇒ Object

_prepend($data)

General storage function


25
26
27
28
29
30
# File 'lib/writeexcel/write_file.rb', line 25

def prepend(*args)
  data = join_data(args)
  @data = data + @data

  data
end