From 3824dda1f184158c8946f02a4f2d533a17e95cd4 Mon Sep 17 00:00:00 2001 From: Szymon Szukalski Date: Thu, 24 Oct 2024 13:04:16 +1100 Subject: Execute actions via the FamilyTreeManager - Added logic for executing different FamilyTreeManager methods based on actions - More test coverage --- lib/action_file_executor.rb | 11 ++++++++++- lib/family_tree_manager.rb | 9 +++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/action_file_executor.rb b/lib/action_file_executor.rb index 15d4f63..1cd3a94 100644 --- a/lib/action_file_executor.rb +++ b/lib/action_file_executor.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'family_tree_manager' + class ActionFileExecutor def initialize(file_path) @file_path = file_path @@ -10,7 +12,14 @@ class ActionFileExecutor File.open(@file_path, 'r') do |file| file.each_line do |line| action, *params = line.split(' ') - puts "Executing action: #{action} with params: #{params.join(', ')}" + case action + when 'ADD_CHILD' + FamilyTreeManager.instance.add_child(*params) + when 'GET_RELATIONSHIP' + FamilyTreeManager.instance.query_hierarchy(*params) + else + puts "Ignoring unsupported action: [#{action}]" + end end end end diff --git a/lib/family_tree_manager.rb b/lib/family_tree_manager.rb index 75e1b05..6b0bc12 100644 --- a/lib/family_tree_manager.rb +++ b/lib/family_tree_manager.rb @@ -9,6 +9,11 @@ class FamilyTreeManager @family_members = {} end - def add_child(*params); end - def query_hierarchy(*params); end + def add_child(*params) + puts "Adding Child with params: #{params.join(', ')}" + end + + def query_hierarchy(*params) + puts "Querying Hierarcy with params: #{params.join(', ')}" + end end -- cgit v1.2.3