class GuessWhoNoFuzzy::Profiler
Attributes
email[R]
full_name[R]
Public Class Methods
new(email)
click to toggle source
# File lib/guess_who_no_fuzzy/profiler.rb, line 10 def initialize(email) @email = email @full_name = "" end
profile!(email)
click to toggle source
# File lib/guess_who_no_fuzzy/profiler.rb, line 6 def self.profile!(email) self.new(email).profile! end
Public Instance Methods
profile!()
click to toggle source
# File lib/guess_who_no_fuzzy/profiler.rb, line 15 def profile! full_name_arr = [] raw_str = email.split("@")[0].upcase strings = raw_str.split(/[^A-Z]/) strings.each do |str| best = { score: 0, parts: [], count: 0 } token_arrays = Tokenizer.tokenize!(str) Scorer.score!(token_arrays) do |score, tokens| is_better = Comparator.better?(score, best[:score], tokens.size, best[:count]) if is_better best = { score: score, parts: tokens, count: tokens.size } end end best[:parts].each do |part| full_name_arr << part.capitalize end end @full_name = full_name_arr.join(" ") self end