Class: Doing::ByDayExport

Inherits:
Object show all
Defined in:
lib/doing/plugins/export/byday.rb

Class Method Summary collapse

Class Method Details

.render(wwid, items, variables: {}) ⇒ Object



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
53
54
55
56
57
58
59
# File 'lib/doing/plugins/export/byday.rb', line 15

def self.render(wwid, items, variables: {})
  return if items.nil?

  days = {}

  items.each do |item|
    date = item.date.strftime('%Y-%m-%d')
    days[date] ||= []
    days[date].push(item)
  end

  totals = {}
  total = 0

  days.each do |day, day_items|
    day_items.each do |item|
      totals[day] ||= 0
      duration = item.interval || 0
      totals[day] += duration
      total += duration
    end
  end

  divider = "+----------+------------------------------------------------------------------------------------------------+--------+"
  out = []
  out << divider
  days.each do |day, day_items|
    first = day_items.slice!(0, 1)[0]
    interval = wwid.get_interval(first, formatted: true) || '00:00:00'
    out << "|#{day}|#{first.title.trunc(94).ljust(96)}|#{interval}|"
    day_items.each do |item|
      interval = wwid.get_interval(item, formatted: true) || '00:00:00'
      out << "|          |#{item.title.trunc(94).ljust(96)}|#{interval}|"
    end
    day_total = "Total: #{totals[day].time_string(format: :clock)}"
    out << divider
    out << "|#{day_total.rjust(116)}|"
    out << divider
  end
  all_total = "Grand Total: #{total.time_string(format: :clock)}"
  out << divider
  out << "|#{all_total.rjust(116)}|"
  out << divider
  Doing::Pager.page out.join("\n")
end

.settingsObject



9
10
11
12
13
# File 'lib/doing/plugins/export/byday.rb', line 9

def self.settings
  {
    trigger: 'byday'
  }
end