Skip to content

Instantly share code, notes, and snippets.

@davestevens
Created May 29, 2014 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save davestevens/f532a2b5f5ce2f8cd931 to your computer and use it in GitHub Desktop.
Save davestevens/f532a2b5f5ce2f8cd931 to your computer and use it in GitHub Desktop.
#!/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