Class: Ptimelog::Command::Show

Inherits:
Base
  • Object
show all
Defined in:
lib/ptimelog/command/show.rb

Overview

show entries of one day or all of them

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Show

Returns a new instance of Show.



7
8
9
10
11
# File 'lib/ptimelog/command/show.rb', line 7

def initialize(*args)
  @durations = Hash.new(0)

  super
end

Instance Method Details

#duration(date) ⇒ Object



45
46
47
# File 'lib/ptimelog/command/show.rb', line 45

def duration(date)
  Time.at(@durations[date]).utc.strftime('%H:%M')
end

#entries=(entries) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/ptimelog/command/show.rb', line 34

def entries=(entries)
  entries.each do |date, list|
    @entries[date] = []

    list.each do |entry|
      @durations[date] += entry.duration
      @entries[date] << entry.to_s
    end
  end
end

#needs_entries?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/ptimelog/command/show.rb', line 13

def needs_entries?
  true
end

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ptimelog/command/show.rb', line 17

def run
  @entries.each do |date, list|
    puts date,
         '----------'

    next if list.empty?

    list.each do |entry|
      puts entry
    end
    puts '----------',
         "Total work done: #{duration(date)} hours",
         '----------------------------',
         nil
  end
end