Module: NameTamer::Name::PrivateMethodsSimpleName
- Defined in:
- lib/name_tamer/name/private_methods_simple_name.rb
Instance Method Summary collapse
- #find_first_usable_name(parts) ⇒ Object
- #find_last_usable_name(parts) ⇒ Object
-
#remove_initials ⇒ Object
Remove initials from personal names unless they are the only identifier.
- #remove_middle_names ⇒ Object
- #remove_periods_from_initials ⇒ Object
- #standardize_words ⇒ Object
Instance Method Details
#find_first_usable_name(parts) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 29 def find_first_usable_name(parts) part = nil parts.each_index do |i| part = parts[i] next if part.gsub(FILTER_COMPAT, '').empty? parts = parts.slice(i + 1, parts.length) # don't use "slice!" break end [part, parts] end |
#find_last_usable_name(parts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 43 def find_last_usable_name(parts) part = nil parts.reverse_each do |p| next if p.gsub(FILTER_COMPAT, '').empty? part = p break end part end |
#remove_initials ⇒ Object
Remove initials from personal names unless they are the only identifier. i.e. only remove initials if there's also a proper name there
8 9 10 11 12 13 14 15 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 8 def remove_initials return unless @contact_type == :person temp_name = @simple_name.gsub(/\b([a-z](?:\.*\s+|\.))/i, '') # If the name still has at least one space we're OK @simple_name = temp_name if temp_name.include?(ASCII_SPACE) end |
#remove_middle_names ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 17 def remove_middle_names return unless @contact_type == :person first_name, parts = find_first_usable_name(@simple_name.split) last_name, = find_last_usable_name(parts) return unless first_name || last_name separator = first_name && last_name ? ' ' : '' @simple_name = "#{first_name}#{separator}#{last_name}" end |
#remove_periods_from_initials ⇒ Object
56 57 58 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 56 def remove_periods_from_initials @simple_name = Strings.remove_periods_from_initials(@simple_name) end |
#standardize_words ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/name_tamer/name/private_methods_simple_name.rb', line 60 def standardize_words words = @simple_name .gsub(/ *& */, ' and ') # replace ampersand characters with ' and ' .gsub(/ *\+ */, ' plus ') # replace plus signs with ' plus ' .gsub(/\bintl\b/i, 'International') # replace 'intl' with 'International' .gsub(/[־‐‑‒–—―−﹘﹣-]/, SLUG_DELIMITER) # Replace Unicode dashes with ASCII hyphen @simple_name = Strings.strip_unwanted(words, /["“”™℠®©℗]/) # remove quotes and commercial decoration end |