Module: RubyTodo::TaskMovementHelpers
- Included in:
- AIAssistantCommand
- Defined in:
- lib/ruby_todo/commands/ai_assistant.rb
Overview
Module for handling task movement-related functionality
Instance Method Summary collapse
-
#handle_move_task_by_title(prompt, _cli) ⇒ Object
Handle moving tasks by title or search term.
Instance Method Details
#handle_move_task_by_title(prompt, _cli) ⇒ Object
Handle moving tasks by title or search term
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 711 def handle_move_task_by_title(prompt, _cli) # Pattern for "move the task about X to status" task_about_pattern = / move\s+(?:the\s+)?(?:task|tasks)\s+ (?:about|with|containing|related\s+to)\s+ ([\w\s\-]+)\s+to\s+ (todo|in[\s_-]?progress|done|archived) /ix if prompt.match?(task_about_pattern) match = prompt.match(task_about_pattern) search_term = match[1].strip status = match[2].downcase # Normalize status (ensure 'in progress' becomes 'in_progress') status = "in_progress" if status.match?(/in.*progress/i) # Find tasks that match the search term all_notebooks = RubyTodo::Notebook.all matched_tasks = [] all_notebooks.each do |notebook| notebook.tasks.each do |task| next unless task.title.downcase.include?(search_term.downcase) || (task.description && task.description.downcase.include?(search_term.downcase)) matched_tasks << { notebook: notebook, task: task } end end if matched_tasks.empty? say "No tasks found matching '#{search_term}'".yellow return true end # Move each matched task moved_count = 0 matched_tasks.each do |task_info| if task_info[:task].update(status: status) say "Moved task #{task_info[:task].id}: '#{task_info[:task].title}' to #{status}".green moved_count += 1 else say "Error moving task #{task_info[:task].id}: #{task_info[:task].errors..join(", ")}".red end end say "Moved #{moved_count} task(s) to #{status}".green if moved_count > 0 return true end # Pattern for direct task title movement - "move [title] to [status]" if prompt.match?(%r{move\s+(?:task\s+)?([\w\s\-/'"]+?)\s+to\s+(todo|in[\s_-]?progress|done|archived)}i) match = prompt.match(%r{move\s+(?:task\s+)?([\w\s\-/'"]+?)\s+to\s+(todo|in[\s_-]?progress|done|archived)}i) title_text = match[1].strip status = match[2].downcase # Clean up the title by removing quotes title_text = title_text.gsub(/^['"]|['"]$/, "") # Normalize status status = "in_progress" if status.match?(/in.*progress/i) # Find tasks that match the title all_notebooks = RubyTodo::Notebook.all matched_tasks = [] all_notebooks.each do |notebook| notebook.tasks.each do |task| next unless task.title.downcase.include?(title_text.downcase) matched_tasks << { notebook: notebook, task: task } end end if matched_tasks.empty? say "No tasks found matching '#{title_text}'".yellow return true end # Move each matched task moved_count = 0 matched_tasks.each do |task_info| if task_info[:task].update(status: status) say "Moved task #{task_info[:task].id}: '#{task_info[:task].title}' to #{status}".green moved_count += 1 else say "Error moving task #{task_info[:task].id}: #{task_info[:task].errors..join(", ")}".red end end say "Moved #{moved_count} task(s) to #{status}".green if moved_count > 0 return true end # Specific pattern for "move task(s) with title X to status" task_with_title_pattern = / move\s+(?:the\s+)?(?:task|tasks)\s+ with\s+(?:title|name)\s+ ["']([^"']+)["']\s+to\s+ (todo|in[\s_-]?progress|done|archived) /ix if prompt.match?(task_with_title_pattern) match = prompt.match(task_with_title_pattern) exact_title = match[1] status = match[2].downcase # Normalize status status = "in_progress" if status.match?(/in.*progress/i) # Find tasks that match the exact title all_notebooks = RubyTodo::Notebook.all matched_tasks = [] all_notebooks.each do |notebook| notebook.tasks.each do |task| next unless task.title.downcase == exact_title.downcase matched_tasks << { notebook: notebook, task: task } end end if matched_tasks.empty? say "No tasks found with title '#{exact_title}'".yellow return true end # Move each matched task moved_count = 0 matched_tasks.each do |task_info| if task_info[:task].update(status: status) say "Moved task #{task_info[:task].id}: '#{task_info[:task].title}' to #{status}".green moved_count += 1 else say "Error moving task #{task_info[:task].id}: #{task_info[:task].errors..join(", ")}".red end end say "Moved #{moved_count} task(s) to #{status}".green if moved_count > 0 return true end false end |