From 8cb16abb16de6d96ccdfefa44a0b693f51875f16 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Thu, 15 May 2025 17:02:41 +0200 Subject: [PATCH] extract method --- app/models/command/ai/parser.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/models/command/ai/parser.rb b/app/models/command/ai/parser.rb index 53a008932..14ca49968 100644 --- a/app/models/command/ai/parser.rb +++ b/app/models/command/ai/parser.rb @@ -11,19 +11,23 @@ class Command::Ai::Parser def parse(query) query_json = resolve_named_params_to_ids command_translator.as_normalized_json(query) - query_context = context_from_query(query_json) - resolved_context = query_context || context - - commands = Array.wrap(commands_from_query(query_json, resolved_context)) - - if query_context - commands.unshift Command::VisitUrl.new(user: user, url: query_context.url, context: resolved_context) - end - - Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context) + build_composite_command_for query_json, query end private + def build_composite_command_for(query_json, query) + query_context = context_from_query(query_json) + resolved_context = query_context || context + + commands = Array.wrap(commands_from_query(query_json, resolved_context)) + + if query_context + commands.unshift Command::VisitUrl.new(user: user, url: query_context.url, context: resolved_context) + end + + Command::Composite.new(title: query, commands: commands, user: user, line: query, context: resolved_context) + end + def command_translator Command::Ai::Translator.new(context) end