Skip to content

Instantly share code, notes, and snippets.

@caged
Last active May 7, 2016 05:13
Show Gist options
  • Select an option

  • Save caged/c42ddd2ab41e80bdaa7a1b67f55ac0d4 to your computer and use it in GitHub Desktop.

Select an option

Save caged/c42ddd2ab41e80bdaa7a1b67f55ac0d4 to your computer and use it in GitHub Desktop.

Revisions

  1. Justin Palmer revised this gist May 7, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion coaches.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    require 'csv'
    coach_years=CSV.read('coaches2.csv')[1..-1]

    i = 0
    stints = coach_years.sort_by(&:reverse).each_with_object([]) do |coach_year, coach_stints|
    season, coach = coach_year
    start_year = season.split('-')[0].to_i
  2. Justin Palmer created this gist May 7, 2016.
    21 changes: 21 additions & 0 deletions coaches.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #!/usr/bin/env ruby

    require 'csv'
    coach_years=CSV.read('coaches2.csv')[1..-1]

    i = 0
    stints = coach_years.sort_by(&:reverse).each_with_object([]) do |coach_year, coach_stints|
    season, coach = coach_year
    start_year = season.split('-')[0].to_i
    end_year = start_year + 1

    last_stint = coach_stints.last
    if [coach, start_year] == last_stint&.fetch_values(:coach, :end_year)
    last_stint[:end_year] = end_year
    else
    coach_stints << { coach: coach, start_year: start_year, end_year: end_year }
    end
    end

    stints.sort_by!{|s| [s[:start_year], s[:end_year]]}
    puts stints