Class: Redpomo::EntriesPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/redpomo/entries_printer.rb

Class Method Summary collapse

Class Method Details



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/redpomo/entries_printer.rb', line 6

def self.print(entries)
  require 'terminal-table'
  entries.group_by(&:date).each do |date, entries|
    duration = 0
    rows = entries.map do |entry|
      task = entry.to_task
      duration += entry.duration
      [
        task.context,
        task.project,
        task.issue,
        task.text,
        entry.duration.seconds_in_words,
        I18n.l(entry.time, format: "%H:%M"),
        I18n.l(entry.end_time, :format => "%H:%M")
      ]
    end
    puts Terminal::Table.new(
      title: "#{ I18n.l(date, format: "%A %x") } - #{ duration.seconds_in_words }",
      headings: [ "Context", "Project", "Issue #", "Description", "Duration", "From", "To" ],
      rows: rows
    )
    puts
  end
end