Sha256: df7a776c6ee5827dda3c3a98e996861ed845ca8a53da9412e496e52d98853105

Contents?: true

Size: 1.83 KB

Versions: 13

Compression:

Stored size: 1.83 KB

Contents

module Timetrap
  module Formatters
    class Text
      attr_accessor :output
      include Timetrap::Helpers

      def initialize entries
        self.output = ''
        sheets = entries.inject({}) do |h, e|
          h[e.sheet] ||= []
          h[e.sheet] << e
          h
        end
        (sheet_names = sheets.keys.sort).each do |sheet|
          self.output <<  "Timesheet: #{sheet}\n"
          id_heading = Timetrap::CLI.args['-v'] ? 'Id' : '  '
          self.output <<  "#{id_heading}  Day                Start      End        Duration   Notes\n"
          last_start = nil
          from_current_day = []
          sheets[sheet].each_with_index do |e, i|
            from_current_day << e
            e_end = e.end_or_now
            self.output <<  "%-4s%16s%11s -%9s%10s    %s\n" % [
              (Timetrap::CLI.args['-v'] ? e.id : ''),
              format_date_if_new(e.start, last_start),
              format_time(e.start),
              format_time(e.end),
              format_duration(e.start, e_end),
              e.note
            ]

            nxt = sheets[sheet].to_a[i+1]
            if nxt == nil or !same_day?(e.start, nxt.start)
              self.output <<  "%52s\n" % format_total(from_current_day)
              from_current_day = []
            else
            end
            last_start = e.start
          end
          self.output <<  <<-OUT
    ---------------------------------------------------------
          OUT
          self.output <<  "    Total%43s\n" % format_total(sheets[sheet])
          self.output <<  "\n" unless sheet == sheet_names.last
        end
        if sheets.size > 1
          self.output <<  <<-OUT
-------------------------------------------------------------
          OUT
          self.output <<  "Grand Total%41s\n" % format_total(sheets.values.flatten)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
timetrap-1.7.3 lib/timetrap/formatters/text.rb
timetrap-1.7.2 lib/timetrap/formatters/text.rb
timetrap-1.7.1 lib/timetrap/formatters/text.rb
timetrap-1.7.0 lib/timetrap/formatters/text.rb
timetrap-1.6.1 lib/timetrap/formatters/text.rb
timetrap-1.6.0 lib/timetrap/formatters/text.rb
timetrap-1.5.3 lib/timetrap/formatters/text.rb
timetrap-1.5.2 lib/timetrap/formatters/text.rb
timetrap-1.5.1 lib/timetrap/formatters/text.rb
timetrap-1.5.0 lib/timetrap/formatters/text.rb
timetrap-1.4.1 lib/timetrap/formatters/text.rb
timetrap-1.4.0 lib/timetrap/formatters/text.rb
timetrap-1.3.0 lib/timetrap/formatters/text.rb