Class: SubCommands::Series

Inherits:
Thor
  • Object
show all
Defined in:
lib/subcommands/series.rb

Instance Method Summary collapse

Instance Method Details

#lsObject



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
# File 'lib/subcommands/series.rb', line 5

def ls
    series = ::Series.all.order(options[:order].to_sym => :desc)

    series_stats = Statistics.new
    table = [['#', 'log', 'start', 'end', 'hours']] # header
    series.each do |s|
        next if s.log_id.blank?

        start = s.start
        finish = s.end

        # total time
        series_stats << timer = start.difference(finish || Time.now)

        start = time_display(start) if start
        finish = time_display(finish) if finish

        table << [s.id,
            s.log.name,
            start,
            finish || "active",
            (timer/3600).round(2).to_s] # row
    end

    puts ''
    print_table table
    puts ''

    say [series.count.to_s, "series out of", ::Series.count].join(' '), :cyan
    say [(series_stats.mean/3600).round(2), " hours avg"].join(' '), :cyan
end

#rm(id) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/subcommands/series.rb', line 39

def rm(id)
    series = ::Series.find(id)

    if !series
        say "Series ##{id} not found", :red
        exit
    end

    if !options[:confirm]
        say "You must --confirm before removing series", :red
        exit
    end

    if !series.finished?
        series.log.deactivate!
    end

    destroyed = series.destroy
    say "Series ##{id} has been destroyed", :green
end