class Powerball::Lottery

Public Class Methods

new(attendees = 'attendees.csv', winners = 'winners.csv') click to toggle source

first = item last = item email = item slack = item company = item addr1 = item addr2 = item city = item state = item zip = item country = item phone = item

# File lib/powerball/lottery.rb, line 17
def initialize(attendees = 'attendees.csv', winners = 'winners.csv')
  @winners   = CSV.read(winners) rescue []
  @attendees = CSV.read(attendees) rescue []
  @header    = @attendees.shift # remove header

  @attendees.reject! do |attendee|
    email   = attendee[4].strip.downcase
    company = attendee[16].strip.downcase

    (company == 'puppet'                \
      || email.end_with?('@puppet.com') \
      || email.end_with?('@puppetlabs.com'))
  end

  @attendees.map! do |attendee|
    attendee[13].strip!
    attendee[13].slice!(0) if attendee[13].start_with?('@')

    attendee
  end

  puts "INFO: #{@attendees.size} eligible attendees"
end

Public Instance Methods

chatroom=(chatroom) click to toggle source
# File lib/powerball/lottery.rb, line 41
def chatroom=(chatroom)
  @chatroom = chatroom
end
drawing() click to toggle source
# File lib/powerball/lottery.rb, line 45
def drawing
  @chatroom.start_drawing

  active = @chatroom.active_members
  pool   = @attendees.select do |attendee|
    active.include? attendee[13]
  end

  puts "INFO: eligible and active attendees: #{pool.map {|a| "#{a[2]} #{a[3]} (#{a[13]})" }.inspect}"

  if pool.size > 0
    winner = pool.sample
    @winners << winner
    @attendees.delete winner

    @chatroom.post_winner(winner[13])
    @chatroom.alert_admins("New winner: #{winner[2]} #{winner[3]} (#{winner[13]})")
    write_winners
  else
    @chatroom.alert_admins("WARNING: there are no currently eligible active members.")
  end
end
write_winners() click to toggle source
# File lib/powerball/lottery.rb, line 68
def write_winners
  CSV.open('winners.csv', "wb") do |csv|
    csv << @header # copy the input header
    @winners.each do |row|
      csv << row
    end
  end
end