Class: MelissaData::NativeObject::Phone

Inherits:
Base
  • Object
show all
Defined in:
lib/melissadata/native_object/phone.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 = {}) ⇒ Phone

Returns a new instance of Phone.



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
# File 'lib/melissadata/native_object/phone.rb', line 5

def initialize(opts={})
  @obj = MdPhoneRubyWrapper::MdPhone.new
  if obj.Initialize(data_dir) != 0
    raise obj.GetInitializeErrorString
  end

  @result_codes = [
    ["PS01", "10 digit match"],
    ["PS02", "7 digit match"],
    ["PS03", "Corrected Area Code"],
    ["PS04", "Outside Demo Range"],
    ["PS05", "Expired Database"],
    ["PS06", "Updated Area Code"],
    ["PS07", "Exchange Type: Cell Phone"],
    ["PS08", "Exchange Type: Land Line"],
    ["PS09", "Exchange Type: VOIP"],
    ["PS10", "Phone Type: Residential"],
    ["PS11", "Phone Type: Business"],
    ["PS12", "Phone Type: Small Business or Home Office"],
    ["PE01", "Bad area code"],
    ["PE02", "Blank phone number"],
    ["PE03", "Bad phone number - too many or too few digits"],
    ["PE04", "Multiple phone matches"],
    ["PE05", "Bad prefix - does not exist in the database"],
    ["PE06", "Bad zip code"]
  ]

  @defaults = {
    :phone => '',
    :zip => ''
  }

  # At least one of these needs to be present
  @required_fields = [:phone]

  super
end

Instance Method Details

#assign_valuesObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/melissadata/native_object/phone.rb', line 47

def assign_values
  @output = {
    :lat => obj.GetLatitude,
    :lng => obj.GetLongitude,
    :city => obj.GetCity,
    :state => obj.GetState,
    :county_name => obj.GetCountyName,
    :county_fips => obj.GetCountyFips,
    :country_code => obj.GetCountryCode,
    :time_zone => obj.GetTimeZone,
    :time_zone_code => obj.GetTimeZoneCode,
    :msa => obj.GetMsa,
    :pmsa => obj.GetPmsa,
    :time_zone => obj.GetTimeZone,
    :time_zone_code => obj.GetTimeZoneCode,
    :area_code => obj.GetAreaCode,
    :prefix => obj.GetPrefix,
    :suffix => obj.GetSuffix,
    :extension => obj.GetExtension
  }

  codes = result_codes.split(',')
  output[:exchange_type] =  if codes.include?('PS07')
                              'Cell Phone'

                            elsif codes.include?('PS08')
                              'Land Line'

                            elsif codes.include?('PS09')
                              'VOIP'
                            end

  output[:phone_type] = if codes.include?('PS07')
                          'Residential'

                        elsif codes.include?('PS07')
                          'Business'

                        elsif codes.include?('PS07')
                          'Small Business or Home Office'
                        end

  # if opts[:zip].present?
  #   phone_obj.CorrectAreaCode(opts[:phone], opts[:zip])
  #   hsh[:new_area_code] = phone_obj.GetNewAreaCode
  # end

  output[:formatted_phone] = "(#{output[:area_code]}) #{output[:prefix]}-#{output[:suffix]}"
  output[:formatted_phone] << " x#{output[:extension]}" if output[:extension].present?
end

#parse_inputObject



43
44
45
# File 'lib/melissadata/native_object/phone.rb', line 43

def parse_input
  obj.Lookup(input[:phone].to_s, input[:zip].to_s)
end