class SubCommands::Series
Public Instance Methods
ls(search=nil)
click to toggle source
# File lib/subcommands/series.rb, line 5 def ls(search=nil) if search.nil? series = ::Series.all.order(options[:order].to_sym => :desc) else log = Log.find_by_name(search) if log series = ::Series.where(log: log).order(options[:order].to_sym => :desc) else output do say "Could not find #{search}!", :red end exit end end 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 and finish dates start = time_display(start) if start finish = time_display(finish) if finish # name name = '' name = s.log.name if !s.log.name.empty? table << [s.id, name || '', start, finish || "active", (timer/3600).round(2).to_s] # row end output do print_table table output_spacer say [series.count.to_s, "series out of", ::Series.count].join(' '), :cyan say [(series_stats.mean/3600).round(2), "hours avg"].join(' '), :cyan end end
rm(id)
click to toggle source
# File lib/subcommands/series.rb, line 60 def rm(id) series = ::Series.find(id) if !series output do say "Series ##{id} not found", :red end exit end if !options[:confirm] output do say "You must --confirm before removing series", :red end exit end if !series.finished? series.log.deactivate! end destroyed = series.destroy output do say "Series ##{id} has been destroyed", :green end end