Skip to content

Instantly share code, notes, and snippets.

@trauber
Last active January 29, 2020 19:11
Embed
What would you like to do?

Timetrap TSV Formatter

Hacked from csv.rb.

module Timetrap
  module Formatters
    class Tsv
      attr_reader :output

      def initialize entries
        @output = entries.inject("start\tend\tnote\tsheet\n") do |out, e|
          next(out) unless e.end
          out << %|#{e.start.strftime(time_format)}\t#{e.end.strftime(time_format)}\t#{e.note}\t#{e.sheet}\n|
        end
      end

      private
      def time_format
        "%Y-%m-%d %H:%M:%S"
      end
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment