Created
May 29, 2011 10:35
-
-
Save mat813/997637 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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