Class: NameTamer
- Inherits:
-
Object
- Object
- NameTamer
- Defined in:
- lib/name-tamer.rb,
lib/name-tamer/version.rb
Overview
References: www.w3.org/International/questions/qa-personal-names github.com/berkmancenter/namae github.com/mericson/people en.wikipedia.org/wiki/Types_of_business_entity en.wikipedia.org/wiki/List_of_post-nominal_letters_(USA) en.wikipedia.org/wiki/List_of_post-nominal_letters_(United_Kingdom) en.wikipedia.org/wiki/Nobiliary_particle en.wikipedia.org/wiki/Spanish_naming_customs linguistlist.org/pubs/tocs/JournalUnifiedStyleSheet2007.pdf [PDF]
Constant Summary collapse
- VERSION =
'0.2.12'
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .[](name, args = {}) ⇒ Object
-
.parameterize(string, args = {}) ⇒ Object
Make a slug from a string.
Instance Method Summary collapse
- #contact_type ⇒ Object
- #contact_type=(new_contact_type) ⇒ Object
- #nice_name ⇒ Object
- #simple_name ⇒ Object
- #slug ⇒ Object
- #tidy_name ⇒ Object
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/name-tamer.rb', line 16 def name @name end |
Class Method Details
.[](name, args = {}) ⇒ Object
19 20 21 |
# File 'lib/name-tamer.rb', line 19 def [](name, args = {}) new name, args end |
.parameterize(string, args = {}) ⇒ Object
Make a slug from a string
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/name-tamer.rb', line 24 def parameterize(string, args = {}) sep = args[:sep] || SLUG_DELIMITER rfc3987 = args[:rfc3987] || false filter = args[:filter] || (rfc3987 ? FILTER_RFC3987 : FILTER_COMPAT) new_string = string.dup new_string .whitespace_to!(sep) .invalid_chars_to!(sep) .strip_unwanted!(filter) .fix_separators!(sep) .approximate_latin_chars! # Have we got anything left? new_string = '_' if new_string.empty? # downcase any latin characters new_string.downcase end |
Instance Method Details
#contact_type ⇒ Object
94 95 96 97 |
# File 'lib/name-tamer.rb', line 94 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
99 100 101 102 103 104 105 106 107 |
# File 'lib/name-tamer.rb', line 99 def contact_type=(new_contact_type) ct_as_sym = new_contact_type.to_sym unless @contact_type.nil? || @contact_type == ct_as_sym puts "Changing contact type of #{@name} from #{@contact_type} to #{new_contact_type}" end @contact_type = ct_as_sym end |
#nice_name ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/name-tamer.rb', line 60 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
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/name-tamer.rb', line 75 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.whitespace_to!(ASCII_SPACE) end @simple_name end |
#slug ⇒ Object
90 91 92 |
# File 'lib/name-tamer.rb', line 90 def slug @slug ||= NameTamer.parameterize simple_name.dup # "John Doe" -> "john-doe" end |
#tidy_name ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/name-tamer.rb', line 46 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 |