Skip to content

Instantly share code, notes, and snippets.

@mattfawcett
Created January 10, 2011 15:15
Show Gist options
  • Save mattfawcett/772879 to your computer and use it in GitHub Desktop.
Save mattfawcett/772879 to your computer and use it in GitHub Desktop.
Count the hours
#!/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