Class: NameTamer::Name
- Inherits:
-
Object
- Object
- NameTamer::Name
- Includes:
- Name::PrivateMethodsNiceName, Name::PrivateMethodsSimpleName, Name::Utilities
- Defined in:
- lib/name_tamer/name.rb,
lib/name_tamer/name/utilities.rb,
lib/name_tamer/name/private_methods_nice_name.rb,
lib/name_tamer/name/private_methods_simple_name.rb
Defined Under Namespace
Modules: PrivateMethodsNiceName, PrivateMethodsSimpleName, Utilities
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
References: http://www.w3.org/International/questions/qa-personal-names https://github.com/berkmancenter/namae https://github.com/mericson/people http://en.wikipedia.org/wiki/Types_of_business_entity http://en.wikipedia.org/wiki/List_of_post-nominal_letters_(USA) http://en.wikipedia.org/wiki/List_of_post-nominal_letters_(United_Kingdom) http://en.wikipedia.org/wiki/Nobiliary_particle http://en.wikipedia.org/wiki/Spanish_naming_customs http://linguistlist.org/pubs/tocs/JournalUnifiedStyleSheet2007.pdf [PDF].
Instance Method Summary collapse
- #array ⇒ Object
- #contact_type ⇒ Object
- #contact_type=(new_contact_type) ⇒ Object
-
#each_word ⇒ Object
Useful method for iterating through the words in the name.
- #nice_name ⇒ Object
- #simple_name ⇒ Object
- #slug ⇒ Object
- #tidy_name ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
References: http://www.w3.org/International/questions/qa-personal-names https://github.com/berkmancenter/namae https://github.com/mericson/people http://en.wikipedia.org/wiki/Types_of_business_entity http://en.wikipedia.org/wiki/List_of_post-nominal_letters_(USA) http://en.wikipedia.org/wiki/List_of_post-nominal_letters_(United_Kingdom) http://en.wikipedia.org/wiki/Nobiliary_particle http://en.wikipedia.org/wiki/Spanish_naming_customs http://linguistlist.org/pubs/tocs/JournalUnifiedStyleSheet2007.pdf [PDF]
19 20 21 |
# File 'lib/name_tamer/name.rb', line 19 def name @name end |
Instance Method Details
#array ⇒ Object
69 70 71 |
# File 'lib/name_tamer/name.rb', line 69 def array @array ||= slug.split(SLUG_DELIMITER) end |
#contact_type ⇒ Object
73 74 75 76 |
# File 'lib/name_tamer/name.rb', line 73 def contact_type nice_name # make sure we've done the bit which infers contact_type contact_type_best_effort end |
#contact_type=(new_contact_type) ⇒ Object
78 79 80 |
# File 'lib/name_tamer/name.rb', line 78 def contact_type=(new_contact_type) @contact_type = new_contact_type.to_sym end |
#each_word ⇒ Object
Useful method for iterating through the words in the name
83 84 85 86 |
# File 'lib/name_tamer/name.rb', line 83 def each_word(&) @words ||= slug.split(SLUG_DELIMITER) @words.each(&) end |
#nice_name ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/name_tamer/name.rb', line 35 def nice_name unless @nice_name @nice_name = tidy_name.dup # Start with the tidied name remove_adfixes # prefixes and suffixes: "Smith, John, Jr." -> "Smith, John" fixup_last_name_first # "Smith, John" -> "John Smith" fixup_mismatched_braces # "Ceres (AZ" -> "Ceres (AZ)" remove_adfixes # prefixes and suffixes: "Mr John Smith Jr." -> "John Smith" name_wrangle # proper name case and non-breaking spaces use_nonbreaking_spaces_in_compound_names end @nice_name end |
#simple_name ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/name_tamer/name.rb', line 50 def simple_name unless @simple_name @simple_name = nice_name.dup # Start with nice name remove_initials # "John Q. Doe" -> "John Doe" remove_middle_names # "Philip Seymour Hoffman" -> "Philip Hoffman" remove_periods_from_initials # "J.P.R. Williams" -> "JPR Williams" standardize_words # "B&Q Intl" -> "B and Q International" @simple_name = Strings.whitespace_to(@simple_name, ASCII_SPACE) end @simple_name end |
#slug ⇒ Object
65 66 67 |
# File 'lib/name_tamer/name.rb', line 65 def slug @slug ||= NameTamer.parameterize simple_name.dup # "John Doe" -> "john-doe" end |
#tidy_name ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/name_tamer/name.rb', line 21 def tidy_name unless @tidy_name @tidy_name = name.dup # Start with the name we've received unescape # Unescape percent-encoded characters and fix UTF-8 encoding remove_zero_width # remove zero-width characters tidy_spacing # " John Smith " -> "John Smith" fix_encoding_errors # "Ren\u00c3\u00a9 Descartes" -> "Ren\u00e9 Descartes" consolidate_initials # "I. B. M." -> "I.B.M." end @tidy_name end |