-
-
Save aaronmcadam/e59be45a76849277a76d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require "rubyXL" | |
require "pry" | |
require "json" | |
# define from input | |
@key_col = 0 | |
@translation_col = 2 | |
file = PATH_TO_FILE | |
def extract_translations(worksheet) | |
worksheet.extract_data.each_with_object({}) do |data, json| | |
puts data[@key_col] | |
json[clean_up(data[@key_col])] = clean_up(data[@translation_col]) | |
end | |
end | |
def clean_up(input) | |
input.strip! | |
input.gsub(/,\Z/, "").gsub(/\A\"/, "").gsub(/\"\Z/, "") | |
end | |
def create_json_file(worksheet, file_name) | |
File.open(file_name, "w") do |file| | |
file.write(JSON.pretty_generate(extract_translations(worksheet))) | |
end | |
end | |
workbook = RubyXL::Parser.parse(file) | |
workbook.worksheets.each_with_index do |worksheet, index| | |
create_json_file(worksheet, "#{index}.json") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment