Skip to content

Instantly share code, notes, and snippets.

@nickyp
Forked from vtim/billing.rb
Last active December 11, 2015 08:28
Show Gist options
  • Save nickyp/4572970 to your computer and use it in GitHub Desktop.
Save nickyp/4572970 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'date'
re_line1 = /^\[b([\d,]+)h\](.*)/
re_line2 = /^scheduled (.*)/
total_hours = 0.0
STDIN.each_slice(3) { |entry| # iterate per 3 lines
hours_and_description, schedule = entry[0], entry[1]
hours_and_description =~ re_line1
hours, title = $1, $2
total_hours += hours.gsub(",", ".").to_f
schedule =~ re_line2
date = Date.parse($1)
puts "#{date.strftime('%d-%m-%y')}\t#{hours.ljust(4)}\t#{title}"
}
puts "\nTotaal: #{total_hours}"
[b4h] WORK @ Sample project
scheduled 24 Oct 2012 from 08:00 to 12:00
[b3,5h] Sample project
scheduled 5 Nov 2012 from 08:30 to 12:00
[b3,75h] Sample project
scheduled 5 Nov 2012 from 08:30 to 12:00
24-10-12 4 WORK @ Sample project
05-11-12 3,5 Sample project
05-11-12 3,75 Sample project
Totaal: 11.25
@Wolfr
Copy link

Wolfr commented Jan 19, 2013

Thanks for your input :)

Unfortunately I'm not well versed in Ruby.

As stated in the blogpost I am looking for someone who can write this but also expand on it if I have additional requests (this is why I want it to be a paid project so I don't have to depend on someone's goodwill/free time)

I didn't expect people to start writing code already, I guess it's a small "programmer's challenge" :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment