Created
September 21, 2017 14:32
-
-
Save ErvalhouS/9afac60c17a7bc27c8d42436969d3560 to your computer and use it in GitHub Desktop.
Initializer to add some helpers into ruby console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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