Class: NameTamer

Inherits:
Object
  • Object
show all
Defined in:
lib/name-tamer.rb,
lib/name-tamer/version.rb

Overview

Constant Summary collapse

VERSION =
'0.1.4'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (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

Instance Method Details

#contact_typeObject



65
66
67
68
# File 'lib/name-tamer.rb', line 65

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



70
71
72
73
74
75
76
77
78
# File 'lib/name-tamer.rb', line 70

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_nameObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/name-tamer.rb', line 24

def nice_name
  unless @nice_name
    @nice_name = name.dup          # Start with the name we've received

    tidy_spacing                    # " John   Smith " -> "John Smith"
    consolidate_initials            # "I. B. M." -> "I.B.M."
    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_nameObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/name-tamer.rb', line 41

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_dots_from_abbreviations  # "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

#slugObject



56
57
58
59
60
61
62
63
# File 'lib/name-tamer.rb', line 56

def slug
  unless @slug
    @slug = simple_name.dup         # Start with search name
    slugify                         # "John Doe" -> "john-doe"
  end

  @slug
end