Class: Timetrap::Formatters::Text
- Inherits:
-
Object
- Object
- Timetrap::Formatters::Text
- Includes:
- Helpers
- Defined in:
- lib/timetrap/formatters/text.rb
Instance Attribute Summary collapse
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
-
#initialize(entries) ⇒ Text
constructor
A new instance of Text.
Methods included from Helpers
#format_date, #format_date_if_new, #format_duration, #format_seconds, #format_time, #format_total, #same_day?, #sheet_name_from_string
Constructor Details
#initialize(entries) ⇒ Text
Returns a new instance of Text.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/timetrap/formatters/text.rb', line 7 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 || Time.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].map[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 << " ---------------------------------------------------------\n OUT\n self.output << \" Total%43s\\n\" % format_total(sheets[sheet])\n self.output << \"\\n\" unless sheet == sheet_names.last\n end\n if sheets.size > 1\n self.output << <<-OUT\n-------------------------------------------------------------\n OUT\n self.output << \"Grand Total%41s\\n\" % format_total(sheets.values.flatten)\n end\nend\n" |
Instance Attribute Details
#output ⇒ Object
Returns the value of attribute output.
4 5 6 |
# File 'lib/timetrap/formatters/text.rb', line 4 def output @output end |