Class: MazeCrosser::MazeCrosserRunner

Inherits:
Object
  • Object
show all
Includes:
FileMazeDefiner, PresentationHelper
Defined in:
lib/maze_crosser/maze_crosser_runner.rb

Overview

Class responsible for running the application.

maze_crosser_runner = MazerRunner.new maze_crosser_runner.run(file, algorithm)

Constant Summary

Constants included from FileChecker

FileChecker::ALLOWED_EXTENSIONS

Instance Method Summary collapse

Methods included from FileMazeDefiner

#define

Methods included from FileChecker

#check

Methods included from PresentationHelper

#present_solution

Constructor Details

#initialize(cache_provider) ⇒ MazeCrosserRunner

Returns a new instance of MazeCrosserRunner.



17
18
19
# File 'lib/maze_crosser/maze_crosser_runner.rb', line 17

def initialize(cache_provider)
  @cache_provider = cache_provider
end

Instance Method Details

#run(file = nil, algorithm = 'recursive') ⇒ Object

Raises:

  • (ArgumentError)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/maze_crosser/maze_crosser_runner.rb', line 21

def run(file = nil, algorithm = 'recursive')
  # When an additional grid import method is implemented (e.g. via CLI)
  # the following should be done:
  # 1) The line that raises ArgumentError should be removed
  # 2) Grid assignment should be moved to a private method
  raise ArgumentError, 'Please provide a file' unless file

  grid = define(file) if file

  maze = MazeCrosser::Maze.new(grid)
  algorithm = load_algorithm(algorithm, maze)
  present_solution(MazeSolver.new(maze, algorithm, @cache_provider).solve)
end