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
# File bin/agenndy, line 30 def print_csv(year, month, database) database.each do |e| e.last.each do |ee| day = e.first timespan, hours, task = ee start_time, end_time = timespan.split '-' puts "#{year}-#{month}-#{day}#{FS}#{start_time}#{FS}#{end_time}#{FS}"\ "#{hours}#{FS}#{task}" end end end