Class: MelissaData::NativeObject::Name

Inherits:
Base
  • Object
show all
Defined in:
lib/melissadata/native_object/name.rb

Instance Attribute Summary

Attributes inherited from Base

#data_dir, #input, #obj, #output, #result_codes, #results_string

Instance Method Summary collapse

Methods inherited from Base

#license, #process, #process_result_codes, #valid_input?

Constructor Details

#initialize(opts = {}) ⇒ Name

Returns a new instance of Name.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/melissadata/native_object/name.rb', line 5

def initialize(opts={})
  @obj = MdNameRubyWrapper::MdName.new
  obj.SetPathToNameFiles(data_dir)

  @result_codes = [
    ['NS01', "Parsing was successful"],
    ['NS02', "There was a parse error"],
    ['NS03', "The spelling of the FirstName field was corrected"],
    ['NS04', "The spelling of the FirstName2 field was corrected"],
    ['NE01', "Two names were detected but the FullName string was not in a recognized format"],
    ['NE02', "Multiple first names - could not accurately genderize"],
    ['NE03', "A vulgarity was detected in the first name"],
    ['NE04', "The name contained words found on the list of nuisance names [such as Mickey Mouse]"],
    ['NE05', "The name contained words normally found in a company name"],
    ['NE06', "The named contained a non-alphabetic character"]
  ]

  @defaults = {
    :first_name => '',
    :last_name => ''
  }

  # At least one of these needs to be present
  @required_fields = [:first_name, :last_name, :full_name]

  # 0 - don't correct spelling of first name
  # 1 - attempt to correct common misspellings of first name
  obj.SetFirstNameSpellingCorrection(1) 

  # Formatting of the FullName input
  # 1 - Definitely Full
  # 2 - Very Likely Full
  # 3 - Probably Full
  # 4 - Varying (default)
  # 5 - Probably Inverse
  # 6 - Very Likely Inverse
  # 7 - Definitely Inverse
  # 8 - Mixed First Name
  # 9 - Mixed Last Name
  obj.SetPrimaryNameHint(1)

  super
end

Instance Method Details

#assign_valuesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/melissadata/native_object/name.rb', line 56

def assign_values
  genders = {
    'M' => 'Male',
    'F' => 'Female',
    'U' => 'Unknown first name',
    'N' => 'Neutral first name'
  }

  @output = {
    :prefix => obj.GetPrefix,
    :first_name => obj.GetFirstName,
    :middle_name => obj.GetMiddleName,
    :last_name => obj.GetLastName,
    :suffix => obj.GetSuffix,
    :gender => obj.GetGender,
    :gender_string => genders[obj.GetGender]
  }
  # status_messages << "First name spelling was corrected" if name_obj.GetChangeCode == 1
end

#parse_inputObject



49
50
51
52
53
54
# File 'lib/melissadata/native_object/name.rb', line 49

def parse_input
  input[:full_name] = ("%s %s" % [input[:first_name], input[:last_name]]) if input[:full_name].blank?
  obj.ClearProperties
  obj.SetFullName input[:full_name].to_s
  obj.Parse
end