Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created March 27, 2012 01:01
Show Gist options
  • Save tlehman/2211341 to your computer and use it in GitHub Desktop.
Save tlehman/2211341 to your computer and use it in GitHub Desktop.
find hours left in sow.txt file
# a very inelegant script to find the total number of hours in the scope of work file
# by tlehman
# get the lines from the sow file
file = File.open('sow.txt')
lines = file.readlines
file.close
# join list of strings and regex out the hours, then turn those strings into ints
hours_list = lines.join.scan(/(\d+) hours/i).map {|hs| hs.first.to_i}
# sum up the list of hours
total_hours = hours_list.reduce(:+)
puts "#{total_hours} hours total"
# find the number of hours in the scope of work file that have not been done
lines_not_done = lines.select { |line| not (line =~ /DONE/) }
hours_left = lines_not_done.join.scan(/(\d+) hours/).map {|hs| hs.first.to_i}
total_hours_left = hours_left.reduce(:+)
puts "#{total_hours_left} hours left"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment