Class: Tabula::Writers::MarkdownWriter
- Defined in:
- lib/tabula/writers/markdown_writer.rb
Overview
Writes tables in Markdown format (GitHub-flavored)
Instance Method Summary collapse
-
#initialize(alignment: nil, **options) ⇒ MarkdownWriter
constructor
A new instance of MarkdownWriter.
-
#write(tables, io) ⇒ Object
Write tables to an IO object.
Methods inherited from Writer
Constructor Details
#initialize(alignment: nil, **options) ⇒ MarkdownWriter
Returns a new instance of MarkdownWriter.
8 9 10 11 |
# File 'lib/tabula/writers/markdown_writer.rb', line 8 def initialize(alignment: nil, **) super(**) @alignment = alignment end |
Instance Method Details
#write(tables, io) ⇒ Object
Write tables to an IO object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/tabula/writers/markdown_writer.rb', line 16 def write(tables, io) tables.each_with_index do |table, idx| # Add blank line between tables io.puts if idx.positive? rows = table.to_a next if rows.empty? col_count = rows.map(&:size).max || 0 next if col_count.zero? # Write header row (first row) write_row(io, rows.first, col_count) # Write separator row write_separator(io, col_count) # Write data rows rows.drop(1).each do |row| write_row(io, row, col_count) end end end |