Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/whatlanguage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ def languages

# Very inefficient method for now.. but still beats the non-Bloom alternatives.
# Change to better bit comparison technique later..
def process_text(text)
def process_text(text, options = {})
options = {
exit_early: true
}.merge options

results = Hash.new(0)
it = 0
text.downcase.split.each do |word|
Expand All @@ -41,7 +45,7 @@ def process_text(text)
end

# Every now and then check to see if we have a really convincing result.. if so, exit early.
if it % 4 == 0 && results.size > 1
if options[:exit_early] && it % 4 == 0 && results.size > 1
top_results = results.sort_by{|a,b| -b}[0..1]

# Next line may need some tweaking one day..
Expand Down