Skip to content

Instantly share code, notes, and snippets.

@trauber
Last active January 29, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trauber/454c6c703c54bf6823150910aeaafe4a to your computer and use it in GitHub Desktop.
Save trauber/454c6c703c54bf6823150910aeaafe4a to your computer and use it in GitHub Desktop.

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