lib/username_suggester/suggester.rb in username_suggester-0.1.0 vs lib/username_suggester/suggester.rb in username_suggester-0.2.0

- old
+ new

@@ -40,11 +40,11 @@ results = [] candidates = name_combinations.clone while results.size < max_num_suggestion and !candidates.blank? candidate = candidates.shift if @options[:validate] and !@options[:validate].call(candidate) - # Do nothing + # Don't add the candidate to result elsif unavailable_set.include? candidate candidates << find_extended_candidate(candidate, unavailable_set) else results << candidate end @@ -54,10 +54,10 @@ private # Generates a candidate with "candidate<number>" which is not included in unavailable_set def find_extended_candidate(candidate, unavailable_set) i = 1 - i+=1 while unavailable_set.include? "#{candidate}#{i}" + i+=rand(10) while unavailable_set.include? "#{candidate}#{i}" "#{candidate}#{i}" end end end \ No newline at end of file