Class: Rubino::Documents::Converters::Csv

Inherits:
Object
  • Object
show all
Defined in:
lib/rubino/documents/converters/csv.rb

Overview

CSV -> a GFM Markdown table (first row = header), via the shared Table emitter. ‘csv` was removed from Ruby’s default gems in 3.4, so we require it defensively: if it isn’t present we still parse with a tiny built-in splitter (handles the common quoted-field case) rather than going unavailable – CSV is too central to drop on a missing stdlib gem.

Instance Method Summary collapse

Instance Method Details

#accepts?(mime, path) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/rubino/documents/converters/csv.rb', line 16

def accepts?(mime, path)
  m = mime.to_s
  return true if ["text/csv", "application/csv"].include?(m)

  File.extname(path.to_s).downcase == ".csv"
end

#available?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rubino/documents/converters/csv.rb', line 12

def available?
  true
end

#convert(path) ⇒ Object



23
24
25
26
# File 'lib/rubino/documents/converters/csv.rb', line 23

def convert(path)
  rows = parse(path)
  Table.emit(rows)
end