Skip to content

Instantly share code, notes, and snippets.

@mat813
Created May 29, 2011 10:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mat813/997637 to your computer and use it in GitHub Desktop.
Save mat813/997637 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
input = $stdin.readlines.map do |l|
l.chomp!
title = true
l.split(/\s+/).inject([""]) do |acc, a|
if /^\d?\d:\d\d$/ =~ a
title = false
acc << a.sub(/^0/, '')
elsif title
acc[0] << a << " "
end
acc
end
end
START = input.inject(0) {|acc, ligne| [acc, ligne[0].length].max } + 3
POS = (9..23).inject({}) {|a,i| a[i] = (i-9)*6 + START; a}
print " \n"
POS.keys.sort.inject(0) do |acc,heure|
pos = POS[heure]
(pos-acc).times { print " " }
heure = "#{heure}h"
print heure
pos+heure.length
end
print "\n"
input.each do |l|
film = l.shift
print "%-#{START - 3}s: " % [film]
l.grep(/^\d?\d:\d\d$/).inject(START) do |acc,heure|
h,m = heure.split(/:/).map {|i| i.to_i}
pos = POS[h] + m/10
(pos - acc).times { print " " }
print heure
pos + heure.length
end
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment