Skip to content

Instantly share code, notes, and snippets.

@Tarrasch
Created January 30, 2012 21:30
Show Gist options
  • Save Tarrasch/1706833 to your computer and use it in GitHub Desktop.
Save Tarrasch/1706833 to your computer and use it in GitHub Desktop.
Script of regexping how much I worked from journal input
#!/usr/bin/ruby
r = /\*\*[\d :\-]+\*\*/
s = $stdin.readlines.join
ms = s.scan r
class Interval
attr_accessor :time0, :time1
def initialize(s)
r = /[*:-]/
h0,m0,h1,m1 = s.gsub(r, " ").split.map(&:to_i)
@time0 = (h0*60+m0)
@time1 = (h1*60+m1)
end
def minutes
@time1-@time0
end
def hours
minutes/60.0
end
end
def to_time(s)
r = /[*:-]/
h0,m0,h1,m1 = s.gsub(r, " ").split.map(&:to_i)
(h1*60+m1) - (h0*60+m0)
end
f = ->(s) { Interval.new(s) }
ivs = ms.map(&f)
p ivs.map { |iv| iv.hours }.inject(:+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment