module Agenndy

Agenndy parser and printer

Public Class Methods

parse(filename) click to toggle source
# File bin/agenndy, line 14
def parse(filename)
  content = File.read filename
  content.lines.map(&:strip).reduce([]) do |a, e|
    if e.start_with? '['
      date = e.split('[').last.split(']').first
      a << [date, []]
    elsif e.start_with?(/\d/)
      timespan, task = e.strip.split(/(?<=\d\d)\s/)
      start, finish = timespan.split('-').map { |ee| Time.parse ee }
      hours = (finish - start) / 3600
      a[-1].last << [timespan, hours.round(2), task]
    end
    a
  end
end
print_csv(year, month, database) click to toggle source