Created
January 30, 2012 21:30
-
-
Save Tarrasch/1706833 to your computer and use it in GitHub Desktop.
Script of regexping how much I worked from journal input
This file contains hidden or 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 | |
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