class GradesFirst::PairCommand

Implementation of a Thor command for determining who your next pair is for pair programming or code review.

Public Class Methods

description() click to toggle source

Description of the “gf pair” Thor command that will be used in the commandline help.

# File lib/gradesfirst/pair_command.rb, line 10
def self.description
  'Show the current developer pairings.'
end
long_description() click to toggle source

Description of the “gf pair” Thor commeand that will be used in the commandline help to provide a complete description.

# File lib/gradesfirst/pair_command.rb, line 16
    def self.long_description
      <<-LONG_DESCRIPTION
      Developer pairings are calculated based on a zero day date and the list
      people who are developers.  The actual pairings are made by a round robin
      tournament algorithm.

      In order for this command to work correctly, the environment variables
      GF_DAY_ZERO and GF_DEVELOPERS need to be properly defined.  These can
      be actual environment variables, a .env file, or .env.master file.  The
      .env file can be in the current directory or the home directory.  The
      .env.master file must be in the current directory.  The precedence order
      is environment variables, .env in the current directory, .env in the
      home directory, and .env.master in the current directory.  It is
      recommended that .env.master be committed to source control and the
      other options used to override .env.master.

      GF_DAY_ZERO is a date in a valid Ruby date string format.

      GF_DEVELOPERS is a pipe (|) delimited list of names.

      Examples:

      GF_DAY_ZERO="2014-3-10 00:00:00"

      GF_DEVELOPERS="Anthony Crumley|Tom Miller|Andrew Sellers"
      LONG_DESCRIPTION
    end

Public Instance Methods

execute() click to toggle source

Performs the gf pair Thor command which determines the current developer pairings.

# File lib/gradesfirst/pair_command.rb, line 46
def execute
  @pairing = pairings[pairing_index]
end
response() click to toggle source

Generates the command line output response. The output of the pair command will be a list of developer pairings for code review, pair programming, etc.

# File lib/gradesfirst/pair_command.rb, line 53
def response
  @pairing.map{|pair| pair.compact.join(' and ')}.join("\n") + "\n"
end

Private Instance Methods

developers() click to toggle source

Currently returns a hard coded list but could be moved to a configuration file in the future.

# File lib/gradesfirst/pair_command.rb, line 61
def developers
  return @developers unless @developers.nil?

  @developers = config.developers.sort
  @developers << nil if @developers.length.odd?

  @developers
end
max_pairing_index() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 92
def max_pairing_index
  developers.length - 1
end
now() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 119
def now
  Time.now
end
pairing_index() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 88
def pairing_index
  sprint % max_pairing_index
end
pairings() click to toggle source

This algorithm was written by Tom Miller based on the wikipedia article on round robin tournaments.

en.wikipedia.org/wiki/Round-robin_tournament

# File lib/gradesfirst/pair_command.rb, line 74
def pairings
  top, bottom = developers.each_slice(developers.length/2).to_a
  pivot, *top = top

  result = []
  (developers.length-1).times do
    top.unshift(bottom.shift)
    bottom.push(top.pop)
    result << [pivot, *top].zip(bottom)
  end

  result
end
seconds_in_a_week() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 110
def seconds_in_a_week
  days_in_a_week = 7
  hours_in_a_day = 24
  minutes_in_an_hour = 60
  seconds_in_a_minute = 60

  days_in_a_week * hours_in_a_day * minutes_in_an_hour * seconds_in_a_minute
end
sprint() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 96
def sprint
  week / sprint_length_in_weeks
end
sprint_length_in_weeks() click to toggle source

Currently this is hard coded but could be moved to a configuration file in the future.

# File lib/gradesfirst/pair_command.rb, line 102
def sprint_length_in_weeks
  2
end
week() click to toggle source
# File lib/gradesfirst/pair_command.rb, line 106
def week
  (now.to_i - day_zero.to_i) / seconds_in_a_week
end