Class: MazeCrosser::CacheProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/maze_crosser/cache_provider.rb

Overview

Class responsible for maintaining a cache of already solved mazes.

cache_provider = CacheProvider.new

Add solution to cache cache_provider.add(grid, solution)

Get a solution cache_provider.get_solution(grid)

Empty cache cache_provider.empty_cache!

Instance Method Summary collapse

Constructor Details

#initialize(solutions = {}) ⇒ CacheProvider

Returns a new instance of CacheProvider.



15
16
17
# File 'lib/maze_crosser/cache_provider.rb', line 15

def initialize(solutions = {})
  @solutions = solutions
end

Instance Method Details

#add(grid, solution) ⇒ Object



19
20
21
# File 'lib/maze_crosser/cache_provider.rb', line 19

def add(grid, solution)
  @solutions[grid] = solution
end

#empty_cache!Object



27
28
29
# File 'lib/maze_crosser/cache_provider.rb', line 27

def empty_cache!
  @solutions = {}
end

#get_solution(grid) ⇒ Object



23
24
25
# File 'lib/maze_crosser/cache_provider.rb', line 23

def get_solution(grid)
  @solutions[grid]
end