Skip to content

Instantly share code, notes, and snippets.

@mwlang
Created June 14, 2013 17:34
Show Gist options
  • Save mwlang/5783780 to your computer and use it in GitHub Desktop.
Save mwlang/5783780 to your computer and use it in GitHub Desktop.
Pivitol exporter viewer
require 'csv'
raise "usage: ruby show.rb filename" unless ARGV[0]
fn = ARGV[0]
raise "specified file, #{fn.inspect} does not exist" unless File.exist? fn
flattened_tasks = CSV.read(fn)
headers = flattened_tasks.shift
tasks = flattened_tasks.map do |t|
columns = headers.map{|h| h.downcase.gsub(" ", "_").to_sym}
hash = {}.tap do |h|
until columns.first == :comment do
h[columns.shift] = t.shift
end
comments = []
until columns.first != :comment do
comments << t.shift
columns.shift
end
h[:comments] = comments.compact.reject{|r| r.empty?}
tasks = []
until t.empty? do
task = {
task: t.shift,
status: t.shift,
}
tasks << task unless task[:task].to_s.empty?
end
h[:tasks] = tasks
end
end
def show(task)
task.keys.reject{|k| task[k].is_a?(Array)}.each do |field|
unless [:comments, :tasks].include? field
puts "%15s: %s" % [field, task[field]]
end
end
puts "\nComments:" unless task[:comments].empty?
task[:comments].each_with_index do |comment, index|
puts "#{index + 1}: #{comment}"
end
puts "\nTasks:" unless task[:tasks].empty?
task[:tasks].each_with_index do |task, index|
puts "#{index + 1}: [#{task[:status]}] #{task[:task]}"
end
end
if ARGV[1] and (task = tasks.detect{ |d| d[:id] == ARGV[1] })
show(task)
else
tasks.each do |task|
show(task)
puts "=" * 70
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment