Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created March 6, 2017 04:53
Show Gist options
  • Select an option

  • Save sonsongithub/96623f4837dbc0042a010722e4e1aa9d to your computer and use it in GitHub Desktop.

Select an option

Save sonsongithub/96623f4837dbc0042a010722e4e1aa9d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
lines = $stdin.map {|line| line }.reverse
titles = lines.pop.split(",")
results = Array.new
lines.each{|line|
line = line.gsub("\"<Null>\"", "")
line = line.chomp
values = line.split(",")
if values.length == titles.length
r = Hash.new
for i in 0..titles.length-1
key = titles[i].chomp
value = values[i].gsub(/^\"(.+)\"$/, '\1')
r[key] = value
end
r["date"] = r["date"].to_f
r["number"] = r["number"].to_i
r["applyToAll"] = r["applyToAll"].to_i
results.push(r)
end
}
print(results.to_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment