Module: RubyTodo::AIAssistant::CommandProcessor

Includes:
ParamExtractor
Included in:
RubyTodo::AIAssistantCommand
Defined in:
lib/ruby_todo/ai_assistant/command_processor.rb

Overview

Helper module for processing task-related commands

Instance Method Summary collapse

Methods included from ParamExtractor

#extract_description_param, #extract_due_date_param, #extract_tags_param, #extract_task_params

Instance Method Details

#process_notebook_create(cmd) ⇒ Object

Process notebook create commands



105
106
107
108
109
110
111
112
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 105

def process_notebook_create(cmd)
  parts = cmd.split(/\s+/)
  return unless parts.size >= 2

  notebook_name = parts[1]
  cli_args = ["notebook:create", notebook_name]
  RubyTodo::CLI.start(cli_args)
end

#process_notebook_list(_cmd) ⇒ Object

Process notebook list commands



115
116
117
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 115

def process_notebook_list(_cmd)
  RubyTodo::CLI.start(["notebook:list"])
end

#process_stats(cmd) ⇒ Object

Process stats commands



120
121
122
123
124
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 120

def process_stats(cmd)
  parts = cmd.split(/\s+/)
  cli_args = ["stats"] + parts[1..]
  RubyTodo::CLI.start(cli_args)
end

#process_task_add(cmd) ⇒ Object

Process task add commands



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 12

def process_task_add(cmd)
  # More specific patterns first
  case cmd
  when /task:add\s+"([^"]+)"\s+"([^"]+)"(?:\s+(.*))?/, /task:add\s+'([^']+)'\s+'([^']+)'(?:\s+(.*))?/,
       /task:add\s+([^\s"']+)\s+"([^"]+)"(?:\s+(.*))?/, /task:add\s+([^\s"']+)\s+'([^']+)'(?:\s+(.*))?/

    notebook_name = Regexp.last_match(1)
    title = Regexp.last_match(2)
    params = Regexp.last_match(3)

    cli_args = ["task:add", notebook_name, title]

    # Extract optional parameters
    extract_task_params(params, cli_args) if params

    RubyTodo::CLI.start(cli_args)
  # Handle cases where quotes might be missing or mixed
  when /task:add\s+([^\s]+)\s+([^\s-][^-]+?)(?:\s+(.*))?/
    notebook_name = Regexp.last_match(1).gsub(/["']/, "")  # Remove any quotes
    title = Regexp.last_match(2).gsub(/["']/, "")          # Remove any quotes
    params = Regexp.last_match(3)

    cli_args = ["task:add", notebook_name, title]

    # Process parameters
    extract_task_params(params, cli_args) if params

    RubyTodo::CLI.start(cli_args)
  # Handle missing notebook name by using default notebook
  when /task:add\s+"([^"]+)"(?:\s+(.*))?/, /task:add\s+'([^']+)'(?:\s+(.*))?/
    title = Regexp.last_match(1)
    params = Regexp.last_match(2)

    # Get default notebook
    default_notebook = RubyTodo::Notebook.default_notebook
    notebook_name = default_notebook ? default_notebook.name : "default"

    cli_args = ["task:add", notebook_name, title]

    # Process parameters
    extract_task_params(params, cli_args) if params

    RubyTodo::CLI.start(cli_args)
  else
    say "Invalid task:add command format".red
    message = "Expected: task:add \"notebook_name\" \"task_title\" [--description \"desc\"] " \
              "[--priority level][--tags \"tags\"]"
    say message.yellow
  end
end

#process_task_delete(cmd) ⇒ Object

Process task delete commands



93
94
95
96
97
98
99
100
101
102
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 93

def process_task_delete(cmd)
  if cmd =~ /task:delete\s+"([^"]+)"\s+(\d+)/
    notebook_name = Regexp.last_match(1)
    task_id = Regexp.last_match(2)
    cli_args = ["task:delete", notebook_name, task_id]
    RubyTodo::CLI.start(cli_args)
  else
    say "Invalid task:delete command format".red
  end
end

#process_task_list(cmd) ⇒ Object

Process task list commands



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 77

def process_task_list(cmd)
  if cmd =~ /task:list\s+"([^"]+)"(?:\s+(.*))?/
    notebook_name = Regexp.last_match(1)
    filters = Regexp.last_match(2)
    cli_args = ["task:list", notebook_name]

    # Add any filters that were specified
    cli_args.concat(filters.split(/\s+/)) if filters

    RubyTodo::CLI.start(cli_args)
  else
    say "Invalid task:list command format".red
  end
end

#process_task_move(cmd) ⇒ Object

Process task move commands



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruby_todo/ai_assistant/command_processor.rb', line 64

def process_task_move(cmd)
  if cmd =~ /task:move\s+"([^"]+)"\s+(\d+)\s+(\w+)/ || cmd =~ /task:move\s+([^\s"]+)\s+(\d+)\s+(\w+)/
    notebook_name = Regexp.last_match(1)
    task_id = Regexp.last_match(2)
    status = Regexp.last_match(3)
    cli_args = ["task:move", notebook_name, task_id, status]
    RubyTodo::CLI.start(cli_args)
  else
    say "Invalid task:move command format".red
  end
end