Skip to content

Instantly share code, notes, and snippets.

@kreeger
Created January 14, 2013 20:13
Show Gist options
  • Save kreeger/4532960 to your computer and use it in GitHub Desktop.
Save kreeger/4532960 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Convert a text crossword into JSON.
require 'active_resource'
ActiveResource::Base
filename = ARGV[0]
data = File.open(filename, 'r') { |f| f.read }
sections = data.split(/(author\n|\nlayout\n|\nsolution\n|\nacross\n|\ndown\n)/)
sections = sections.reject {|e| e.empty? }
hash = Hash[sections.each_slice(2).map {|el| [el[0].strip.to_sym, el[1]] }]
puts hash.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment