class IOHelpers::Writer

Public Class Methods

file(path, data, options = {}) click to toggle source
# File lib/io_helpers/writer.rb, line 3
def self.file(path, data, options = {})
  File.write(path, string(data, options))
end
string(data, options = {}) click to toggle source
# File lib/io_helpers/writer.rb, line 7
def self.string(data, options = {})
  line_sep = options[:line_sep] || "\n"
  col_sep = options[:col_sep]
  mapper = options[:mapper] || ->(x) { x.to_s }
  if col_sep
    data.map { |line| line.map(&mapper).join(col_sep) }.join(line_sep)
  else
    data.map(&mapper).join(line_sep)
  end
end