Skip to content

Instantly share code, notes, and snippets.

@ErvalhouS
Created September 21, 2017 14:32
Show Gist options
  • Save ErvalhouS/9afac60c17a7bc27c8d42436969d3560 to your computer and use it in GitHub Desktop.
Save ErvalhouS/9afac60c17a7bc27c8d42436969d3560 to your computer and use it in GitHub Desktop.
Initializer to add some helpers into ruby console
module Consolis
def parse_xls(opts={})
opts[:file] = "output" unless opts[:file].present?
opts[:headers] = ["Important", "Data"] unless opts[:headers].present?
opts[:data] = [["foo","bar"]] unless opts[:data].present?
File.open(opts[:file]+".xls", "w+") do |f|
f.write("<meta charset='utf-8'><table border=yes width=100%>")
opts[:size] = 1 unless opts[:size].present?
f.write("<tr>")
opts[:headers].map do |header|
f.write("<td>")
f.write(header)
f.write("</td>")
end
f.write("</tr>")
opts[:data].map do |mapped|
f.write("<tr>")
mapped.each do |content|
f.write("<td>")
f.write(content)
f.write("</td>")
end
f.write("</tr>")
end
f.write("</table>")
end
end
end
include Consolis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment