Module: NameTamer::Name::PrivateMethodsNiceName
- Defined in:
- lib/name_tamer/name/private_methods_nice_name.rb
Instance Method Summary collapse
-
#consolidate_initials ⇒ Object
Remove spaces from groups of initials.
- #fix_encoding_errors ⇒ Object
-
#fixup_last_name_first ⇒ Object
Names in the form "Smith, John" need to be turned around to "John Smith".
-
#fixup_mismatched_braces ⇒ Object
Sometimes we end up with mismatched braces after adfix stripping e.g.
- #name_wrangle ⇒ Object
- #name_wrangle_single_name ⇒ Object
- #name_wrangle_split_name ⇒ Object
-
#remove_adfixes ⇒ Object
An adfix is either a prefix or a suffix.
- #remove_zero_width ⇒ Object
- #tidy_spacing ⇒ Object
- #unescape ⇒ Object
-
#use_nonbreaking_spaces_in_compound_names ⇒ Object
Conjoin compound names with non-breaking spaces.
Instance Method Details
#consolidate_initials ⇒ Object
Remove spaces from groups of initials
23 24 25 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 23 def consolidate_initials @tidy_name = Strings.ensure_space_after_initials(Strings.remove_spaces_from_initials(@tidy_name)) end |
#fix_encoding_errors ⇒ Object
18 19 20 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 18 def fix_encoding_errors @tidy_name = Strings.fix_encoding_errors(@tidy_name) end |
#fixup_last_name_first ⇒ Object
Names in the form "Smith, John" need to be turned around to "John Smith"
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 55 def fixup_last_name_first return if @contact_type == :organization parts = @nice_name.split ', ' return unless parts.count == 2 @last_name = parts[0] # Sometimes the last name alone is all caps and we can name-case it @remainder = parts[1] end |
#fixup_mismatched_braces ⇒ Object
Sometimes we end up with mismatched braces after adfix stripping e.g. "Ceres (Ceres Holdings LLC)" -> "Ceres (Ceres Holdings"
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 68 def fixup_mismatched_braces left_brace_count = @nice_name.count '(' right_brace_count = @nice_name.count ')' if left_brace_count > right_brace_count @nice_name += ')' elsif left_brace_count < right_brace_count @nice_name = "(#{@nice_name}" end end |
#name_wrangle ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 79 def name_wrangle # Fix case if all caps or all lowercase if @last_name.nil? name_wrangle_single_name else name_wrangle_split_name end end |
#name_wrangle_single_name ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 88 def name_wrangle_single_name lowercase = @nice_name.downcase uppercase = @nice_name.upcase fix_case = false if @contact_type == :organization fix_case = true if @nice_name == uppercase && @nice_name.length > 4 elsif [uppercase, lowercase].include?(@nice_name) fix_case = true end @nice_name = name_case(lowercase) if fix_case end |
#name_wrangle_split_name ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 102 def name_wrangle_split_name # It's a person if we've split the name, so no organization logic here lowercase = @last_name.downcase uppercase = @last_name.upcase @last_name = name_case(lowercase) if [uppercase, lowercase].include?(@last_name) @nice_name = "#{@remainder} #{@last_name}" end |
#remove_adfixes ⇒ Object
An adfix is either a prefix or a suffix
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 28 def remove_adfixes if @last_name.nil? # Our name is still in one part, not two loop do @nice_name = remove_outermost_adfix(:suffix, @nice_name) break unless @adfix_found end loop do @nice_name = remove_outermost_adfix(:prefix, @nice_name) break unless @adfix_found end else # Our name is currently in two halves loop do @last_name = remove_outermost_adfix(:suffix, @last_name) break unless @adfix_found end loop do @remainder = remove_outermost_adfix(:prefix, @remainder) break unless @adfix_found end end end |
#remove_zero_width ⇒ Object
10 11 12 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 10 def remove_zero_width @tidy_name = Strings.strip_unwanted(@tidy_name, ZERO_WIDTH_FILTER) end |
#tidy_spacing ⇒ Object
14 15 16 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 14 def tidy_spacing @tidy_name = Strings.whitespace_to(Strings.space_around_comma(@tidy_name).strip, ASCII_SPACE) end |
#unescape ⇒ Object
6 7 8 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 6 def unescape @tidy_name = Strings.unescape_html(Strings.safe_unescape(Strings.ensure_safe(@tidy_name))) end |
#use_nonbreaking_spaces_in_compound_names ⇒ Object
Conjoin compound names with non-breaking spaces
111 112 113 |
# File 'lib/name_tamer/name/private_methods_nice_name.rb', line 111 def use_nonbreaking_spaces_in_compound_names @nice_name = Strings.nbsp_in_name_modifier(Strings.nbsp_in_compound_name(@nice_name)) end |