File: writer.rb

package info (click to toggle)
ruby-spreadsheet 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,964 kB
  • sloc: ruby: 6,943; makefile: 10
file content (30 lines) | stat: -rw-r--r-- 684 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Spreadsheet
  ##
  # Parent Class for all Writers. Implements the copying of unmodified
  # Spreadsheet documents.
  class Writer
    def initialize io_or_path
      @io_or_path = io_or_path
    end
    def write workbook
      if @io_or_path.respond_to? :seek
        @io_or_path.binmode
        write_workbook workbook, @io_or_path
      else
        File.open(@io_or_path, "wb+") do |fh|
          write_workbook workbook, fh
        end
      end
    end
    private
    def write_workbook workbook, io
      reader = workbook.io
      unless io == reader
        reader.rewind
        data = reader.read
        io.rewind
        io.write data
      end
    end
  end
end