Class: AnagramSolver::Finder

Inherits:
Object
  • Object
show all
Extended by:
ActionView::Helpers::TextHelper
Defined in:
lib/anagram_solver/finder.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.anagramsObject

Returns the value of attribute anagrams.



16
17
18
# File 'lib/anagram_solver/finder.rb', line 16

def anagrams
  @anagrams
end

.finished_atObject

Returns the value of attribute finished_at.



15
16
17
# File 'lib/anagram_solver/finder.rb', line 15

def finished_at
  @finished_at
end

.started_atObject

Returns the value of attribute started_at.



15
16
17
# File 'lib/anagram_solver/finder.rb', line 15

def started_at
  @started_at
end

.timeObject

Returns the value of attribute time.



16
17
18
# File 'lib/anagram_solver/finder.rb', line 16

def time
  @time
end

.wordObject

Returns the value of attribute word.



16
17
18
# File 'lib/anagram_solver/finder.rb', line 16

def word
  @word
end

Class Method Details

.find_for(key, list) ⇒ Object

Finds anagrams for a given key ( i.e word ) and a list, which should be already precomputed. It returns a JSON object, see anagrams_found!.



28
29
30
31
# File 'lib/anagram_solver/finder.rb', line 28

def find_for(key, list)
  timer { look_up(list, key) }
  anagrams_found!
end

.look_up(list, _word_) ⇒ Object

Look for anagrams



36
37
38
39
40
# File 'lib/anagram_solver/finder.rb', line 36

def look_up(list, _word_)
  @word       = _word_
  key         = list.sort!(word)
  @anagrams   = list.precomputed_list[key]
end