Module: Commands::Stop

Included in:
LogTime
Defined in:
lib/commands/stop.rb

Class Method Summary collapse

Class Method Details

.included(thor) ⇒ Object

[View source]

3
4
5
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
31
32
33
34
35
36
# File 'lib/commands/stop.rb', line 3

def self.included(thor)
    thor.class_eval do
        desc "stop [NAME]", "Stop active timer"
        def stop(name)
            log = Log.find_by(name: name)

            # not found
            if !log
                say name.to_s + " not found", :red
                exit
            end

            # log not active
            if log.inactive?
                say "#{name} not active", :red
                exit
            end

            # stop log
            if log.stop!
                say "#{name} stopped!", :green

                time_total = log.total_time/3600
                time_total = time_total.round(2)
                time_last = Series.find(log.series.last.id).total_time/3600
                time_last = time_last.round(2)
                # time_start =
                say "#{time_last} hours out of #{time_total}", :cyan
            else
                say "#{name} failed to stop", :red
            end
        end
    end
end