#!/usr/bin/ruby #### This is a script to generate a report on director attendance ## Parse input files # Loop over each directory '\d{4}' # Loop over each file '*minutes*' # Find 'Directors Present' # Load names until empty line # Find 'Directors Absent' # Load names until empty line class Meeting attr_reader :date def initialize(file) @participants = [] @absentees = [] @guests = [] file =~ /^board_[^_]*_([0-9_]*)\.txt/ @date = $1 end def addParticipant(participant) @participants << participant end def participants @participants end def addAbsentee(absentee) @absentees << absentee end def absentees @absentees end def addGuest(guest) @guests << guest end def guests @guests end end def clean(input) input.gsub(/\([^)]*\)/, '').gsub(/\[[^\]]*\]/, '').sub(/,.*$/, '').strip end ### BEGIN #TODO: Pass in ARGV[0], location of minutes #TODO: Pass in ARGV[1], location of agenda #TODO: Actually parse the agenda file meetings = [] years = Dir["[1-2][0-9][0-9][0-9]"] years.each do |dirname| dir = Dir.new(dirname) dir.each do |filename| unless filename =~ /^board_minutes_.*txt$/ || filename =~ /^board_agenda_.*txt$/ next else meeting = Meeting.new(filename) meetings << meeting end parsing_present = false parsing_absent = false parsing_guests = false File.open(dirname + '/' + filename).each do |fileline| line = fileline.strip if line == "" || line.downcase == "none" next end # 1: Find the date, this is used in the title and various other places if !parsing_present if line =~ /Directors[^P]*Present/ parsing_present = true end next end # In case absent and guests don't appear in the minutes if fileline =~ /^[^\t][^ ]/ break end if !parsing_absent if line =~ /Directors[^A]*Absent/ parsing_absent = true next end meeting.addParticipant( clean(line) ) next end if !parsing_guests if line =~ /Guests/ parsing_guests = true next end meeting.addAbsentee( clean(line) ) next end meeting.addGuest( clean(line) ) end end end ### Munge into name -> attendance (yes, could have done this directly above) class Attendance attr_reader :name, :present, :absent, :guest def initialize(who) @name = who @present = 0 @absent = 0 @guest = 0 end def incr_present @present = @present + 1 end def incr_absent @absent = @absent + 1 end def incr_guest @guest = @guest + 1 end end attendances = Hash.new { |name| Attendance.new(name) } # TODO: Parse Meetings/ directory to guess when boards change meetings.each do |meeting| meeting.participants.each do |participant| attendances[participant].incr_present end meeting.absentees.each do |absentee| attendances[absentee].incr_absent end meeting.guests.each do |guest| attendances[guest].incr_guest end end # Output attendances.each do |name, attendance| puts "#{name}: #{attendance.present}/#{attendance.absent} and #{attendance.guest} as guest" end