Class: Tabula::Writers::TSVWriter

Inherits:
Writer
  • Object
show all
Defined in:
lib/tabula/writers/tsv_writer.rb

Overview

Writes tables in TSV (Tab-Separated Values) format

Instance Method Summary collapse

Methods inherited from Writer

#initialize, to_string, write

Constructor Details

This class inherits a constructor from Tabula::Writers::Writer

Instance Method Details

#write(tables, io) ⇒ Object

Write tables to an IO object

Parameters:

  • tables (Array<Table>) —

    tables to write

  • io (IO) —

    output destination



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/tabula/writers/tsv_writer.rb', line 10

def write(tables, io)
  tables.each_with_index do |table, idx|
    # Add blank line between tables
    io.puts if idx.positive?

    table.to_a.each do |row|
      # Escape tabs and newlines in cell values
      escaped = row.map { |cell| escape_value(cell) }
      io.puts escaped.join("\t")
    end
  end
end