Class: IOHelpers::Writer
- Inherits:
-
Object
- Object
- IOHelpers::Writer
- Defined in:
- lib/io_helpers/writer.rb
Class Method Summary collapse
Class Method Details
.file(path, data, options = {}) ⇒ Object
3 4 5 |
# File 'lib/io_helpers/writer.rb', line 3 def self.file(path, data, = {}) File.write(path, string(data, )) end |
.string(data, options = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/io_helpers/writer.rb', line 7 def self.string(data, = {}) line_sep = [:line_sep] || "\n" col_sep = [:col_sep] mapper = [: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 |