Created
January 10, 2011 15:15
-
-
Save mattfawcett/772879 to your computer and use it in GitHub Desktop.
Count the hours
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 -wKU | |
# Textmate command | |
# Given a number in square brackets, add up all these numbers and give us the total. | |
# Used to add up my time extimation documents | |
# example.txt | |
# Go this [1.5] | |
# Do that [2] | |
# output is "2.5 hours" | |
regex = /\[\D*(\d+\.*\d*)\]/ | |
hours = 0.0 | |
STDIN.read.scan(regex).each do |time| | |
hours += time.first.to_f | |
end | |
print "#{hours} hours" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment