Create a gist now

Instantly share code, notes, and snippets.

@thephw /lunching.rb Secret
Created Feb 19, 2016

What would you like to do?
Lunching Script
#!/usr/bin/env ruby
require "CSV"
# Read data - team, first name, last name, email address
filepath = "./csv_data.csv"
max_per_table = 4
people = CSV.read(filepath).map! do |row|
{
team: row[0].rstrip,
first_name: row[1].rstrip,
last_name: row[2].rstrip,
email: row[3].rstrip
}
end.sort! do |x,y|
x[:team] <=> y[:team]
end
# Chunk by team and then zip into groups
teams = people.chunk{ |person| person[:team] }.map(&:last).shuffle
biggest_team = teams.delete(teams.max{|t| t.count})
zipped_people = biggest_team.zip(*teams).flatten.compact
groups = zipped_people.each_slice(max_per_table)
# Output to screen
IO.popen("pbcopy", "w") do |pipe|
pipe.puts "## #{Date.current.to_s(:long)}\n"
groups.each.with_index do |group, index|
group_email_link = group.map{|p| p[:email]}.join(',')
pipe.puts "### [Group ##{index+1}](mailto:#{group_email_link})\n"
group.each do |person|
pipe.puts "- [#{person[:first_name]} #{person[:last_name]}](mailto:#{person[:email]}), #{person[:team]}"
end
pipe.puts "\n"
end
end
puts "Copied to clipboard!"
%x[open https://gist.github.com]
# TO DO - make calendar invites
# https://github.com/icalendar/icalendar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment