Last active
December 11, 2015 08:19
-
-
Save vtim/4572698 to your computer and use it in GitHub Desktop.
My first ruby script (for: http://wolfslittlestore.be/2013/01/looking-for-shell-programming-expert/) Usage in terminal: ./billing.rb < input.txt > output.txt
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/ruby | |
require 'date' | |
reLine1 = Regexp.new(/\[b([\d,]+)h\] (.*)/) | |
reLine2 = Regexp.new(/scheduled (.*)/) | |
@@hours = nil | |
@@title = nil | |
@@date = nil | |
@@totalHours = 0 | |
STDIN.each_line { |line| | |
match = reLine1.match(line) | |
if match | |
@@hours = match[1] | |
@@title = match[2] | |
else | |
match = reLine2.match(line) | |
if match | |
@@date = Date.parse(match[1]) | |
@@totalHours += @@hours.tr(",", ".").to_f | |
puts "#{@@date.strftime('%d-%m-%y')}\t#{@@hours}\t#{@@title}" | |
end | |
end | |
} | |
puts "\nTotaal: #{@@totalHours}" |
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
[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 |
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
24-10-12 4 WORK @ Sample project | |
05-11-12 3,5 Sample project | |
Totaal: 7.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks Tim :)
I hope you did this from a learning point of view, I might go with another solution because my own Ruby skills are nonexistant
will also answer to https://gist.github.com/4572970