Class: WordSearch::Solver
- Inherits:
-
Object
- Object
- WordSearch::Solver
- Defined in:
- lib/word_search/solver.rb
Instance Attribute Summary collapse
-
#benchmark ⇒ Object
Returns the value of attribute benchmark.
-
#failed ⇒ Object
Returns the value of attribute failed.
-
#plane ⇒ Object
Returns the value of attribute plane.
-
#plane_file ⇒ Object
Returns the value of attribute plane_file.
-
#script ⇒ Object
Returns the value of attribute script.
-
#word_bank ⇒ Object
Returns the value of attribute word_bank.
-
#word_list_file ⇒ Object
Returns the value of attribute word_list_file.
Instance Method Summary collapse
-
#initialize(script, word_list_file, plane_file) ⇒ Solver
constructor
A new instance of Solver.
- #perform ⇒ Object
- #solved? ⇒ Boolean
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
#benchmark ⇒ Object
Returns the value of attribute benchmark.
5 6 7 |
# File 'lib/word_search/solver.rb', line 5 def benchmark @benchmark end |
#failed ⇒ Object
Returns the value of attribute failed.
5 6 7 |
# File 'lib/word_search/solver.rb', line 5 def failed @failed end |
#plane ⇒ Object
Returns the value of attribute plane.
5 6 7 |
# File 'lib/word_search/solver.rb', line 5 def plane @plane end |
#plane_file ⇒ Object
Returns the value of attribute plane_file.
5 6 7 |
# File 'lib/word_search/solver.rb', line 5 def plane_file @plane_file end |
#script ⇒ Object
Returns the value of attribute script.
5 6 7 |
# File 'lib/word_search/solver.rb', line 5 def script @script end |
#word_bank ⇒ Object
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_file ⇒ Object
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
#perform ⇒ Object
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 |