Class: GuessWhoNoFuzzy::Profiler
- Inherits:
-
Object
- Object
- GuessWhoNoFuzzy::Profiler
- Defined in:
- lib/guess_who_no_fuzzy/profiler.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(email) ⇒ Profiler
constructor
A new instance of Profiler.
- #profile! ⇒ Object
Constructor Details
#initialize(email) ⇒ Profiler
Returns a new instance of Profiler.
10 11 12 13 |
# File 'lib/guess_who_no_fuzzy/profiler.rb', line 10 def initialize(email) @email = email @full_name = "" end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
3 4 5 |
# File 'lib/guess_who_no_fuzzy/profiler.rb', line 3 def email @email end |
#full_name ⇒ Object (readonly)
Returns the value of attribute full_name.
3 4 5 |
# File 'lib/guess_who_no_fuzzy/profiler.rb', line 3 def full_name @full_name end |
Class Method Details
.profile!(email) ⇒ Object
6 7 8 |
# File 'lib/guess_who_no_fuzzy/profiler.rb', line 6 def self.profile!(email) self.new(email).profile! end |
Instance Method Details
#profile! ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |