Module: RubyTodo::AIAssistantHelpers
- Included in:
- AIAssistantCommand
- Defined in:
- lib/ruby_todo/commands/ai_assistant.rb
Overview
Handle utility methods for AI assistant
Instance Method Summary collapse
- #format_table_with_wrapping(headers, rows) ⇒ Object
- #load_api_key_from_config ⇒ Object
- #save_config(key, value) ⇒ Object
-
#truncate_text(text, max_length = 50, ellipsis = "...") ⇒ Object
Text formatting methods.
- #wrap_text(text, width = 50) ⇒ Object
Instance Method Details
#format_table_with_wrapping(headers, rows) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 53 def format_table_with_wrapping(headers, rows) table = TTY::Table.new( header: headers, rows: rows ) table.render(:ascii, padding: [0, 1], width: 150, resize: true) do |renderer| renderer.border.separator = :each_row renderer.multiline = true # Configure column widths renderer.column_widths = [ 5, # ID 50, # Title 12, # Status 10, # Priority 20, # Due Date 20, # Tags 30 # Description ] end end |
#load_api_key_from_config ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 15 def load_api_key_from_config config_file = File.("~/.ruby_todo/ai_config.json") return nil unless File.exist?(config_file) config = JSON.parse(File.read(config_file)) config["api_key"] end |
#save_config(key, value) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 23 def save_config(key, value) config_dir = File.("~/.ruby_todo") FileUtils.mkdir_p(config_dir) config_file = File.join(config_dir, "ai_config.json") config = if File.exist?(config_file) JSON.parse(File.read(config_file)) else {} end config[key] = value File.write(config_file, JSON.pretty_generate(config)) end |
#truncate_text(text, max_length = 50, ellipsis = "...") ⇒ Object
Text formatting methods
39 40 41 42 43 44 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 39 def truncate_text(text, max_length = 50, ellipsis = "...") return "" unless text return text if text.length <= max_length text[0...(max_length - ellipsis.length)] + ellipsis end |
#wrap_text(text, width = 50) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/ruby_todo/commands/ai_assistant.rb', line 46 def wrap_text(text, width = 50) return "" unless text return text if text.length <= width text.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip end |