Class: Menu::Scheduled

Inherits:
Base
  • Object
show all
Defined in:
lib/menu/scheduled.rb

Overview

MenuConfig handlers

Instance Method Summary collapse

Methods inherited from Base

#initialize, #run_default, #run_selected_command

Constructor Details

This class inherits a constructor from Menu::Base

Instance Method Details

#add_scheduledObject

Add scheduled issue.



43
44
45
46
47
48
# File 'lib/menu/scheduled.rb', line 43

def add_scheduled
  Database.prepare_database
  ScheduledIssuesManager.new.add_scheduled(menu[:add], menu[:repeat],
                                           menu[:date], menu[:start_time],
                                           menu[:duration])
end

#create_input_mapObject



34
35
36
37
38
39
40
# File 'lib/menu/scheduled.rb', line 34

def create_input_map
  {
    add: menu[:add],
    remove: menu[:remove],
    list: menu[:list]
  }
end

#create_procs_mapObject



26
27
28
29
30
31
32
# File 'lib/menu/scheduled.rb', line 26

def create_procs_map
  {
    add: proc { add_scheduled },
    remove: proc { remove_scheduled },
    list: proc { list_scheduled }
  }
end

#list_scheduledObject

List scheduled issues.



62
63
64
65
66
67
68
69
70
71
# File 'lib/menu/scheduled.rb', line 62

def list_scheduled
  Database.prepare_database
  rows = ScheduledIssuesManager.new.all_issues.map { |i| list_row_attributes(i) }
  table = Terminal::Table.new headings: list_headings, rows: rows
  if rows.count.positive?
    puts table
  else
    Utilities.log("Scheduled list is empty.")
  end
end

#remove_scheduledObject

Remove scheduled issue.



51
52
53
54
55
56
57
58
59
# File 'lib/menu/scheduled.rb', line 51

def remove_scheduled
  Database.prepare_database
  deleted_count = ScheduledIssuesManager.new.remove_scheduled(menu[:remove], menu[:date], menu[:repeat])
  if deleted_count.positive?
    Utilities.log("#{deleted_count} #{Utilities.pluralize(deleted_count, 'issue', 'issues')} deleted.")
  else
    Utilities.log("No issues found with the given options.", { type: :error })
  end
end