Class: WordSearch::Solver

Inherits:
Object
  • Object
show all
Defined in:
lib/word_search/solver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, word_list_file, plane_file) ⇒ Solver



8
9
10
11
12
13
14
15
# File 'lib/word_search/solver.rb', line 8

def initialize(script, word_list_file, plane_file)
  @script         = script
  @word_list_file = word_list_file
  @word_bank      = WordBank.new(word_list_file)
  @plane_file     = plane_file
  @plane          = Plane.make_from_file(plane_file, should_catalog: false)
  @failed         = false
end

Instance Attribute Details

#benchmarkObject

Returns the value of attribute benchmark.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def benchmark
  @benchmark
end

#failedObject

Returns the value of attribute failed.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def failed
  @failed
end

#planeObject

Returns the value of attribute plane.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def plane
  @plane
end

#plane_fileObject

Returns the value of attribute plane_file.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def plane_file
  @plane_file
end

#scriptObject

Returns the value of attribute script.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def script
  @script
end

#word_bankObject

Returns the value of attribute word_bank.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def word_bank
  @word_bank
end

#word_list_fileObject

Returns the value of attribute word_list_file.



5
6
7
# File 'lib/word_search/solver.rb', line 5

def word_list_file
  @word_list_file
end

Instance Method Details

#performObject



17
18
19
20
21
22
23
24
# File 'lib/word_search/solver.rb', line 17

def perform
  return if script.blank?
  bm = benchmark_solution

  return(@benchmark = bm) if !failed && solved?

  "Word Search incorrectly solved"
end

#solved?Boolean



26
27
28
29
30
# File 'lib/word_search/solver.rb', line 26

def solved?
  @word_bank.all? do |word|
    correctly_found?(word, users_solution[word])
  end && proper_direction?
end