Zeitscript
|| Woche || Datum || Stunden || Beschreibung ||
|| 1 || 03.04.2007 || 1 || Projekt-Antrag ||
|| 2 || 08.04.2007 || 1 || Coding-Standards ||
Output
Statistik: (Update 2007-04-30)
|| Woche || Total ||
|| 1 || 1.0 ||
|| 2 || 4.0 ||
|| 3 || 13.0 ||
|| 4 || 9.0 ||
Total: 27.0
Script (Version 2)
#!/usr/bin/ruby
require 'date'
weeks = Hash.new(0)
packages = Hash.new(0)
ARGF.each do |line|
(blurb, week_s, date_s, hours_s, package) = line.split("||").collect{|e| e.strip }
next unless week_s =~ /\d+/
week = week_s.to_i
hours = hours_s.to_f
weeks[week] += hours
packages[package] += hours
# puts "#{week} #{date_s} #{hours} #{desc}"
end
puts
puts "== Statistik (Update #{Date.today}) =="
puts
puts "|| '''Woche''' || '''Total''' ||"
weeks.sort.each do |week, hours|
puts "|| #{week} || #{hours} ||"
end
total = weeks.inject(0) {|sum, e| sum + e.last}
puts
puts "Total: #{total}"
puts
puts "|| '''Paket''' || '''Total''' ||"
packages.sort.each do |package, hours|
puts "|| #{package} || #{hours} ||"
end