Class: MelissaData::NativeObject::Geo

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

Returns a new instance of Geo.



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

def initialize(opts={})
  @obj = MdGeoRubyWrapper::MdGeo.new
  obj.SetPathToGeoCodeDataFiles(data_dir)
  obj.SetPathToGeoPointDataFiles(data_dir)

  @result_codes = [
    ['GS01', "Geocoded to ZIP+4"],
    ['GS02', "Geocoded to ZIP+2"],
    ['GS03', "Geocoded to ZIP"],
    ['GS05', "Geocoded to rooftop level"],
    ['GS06', "Geocoded to interpolated rooftop level"],
    ['GE01', "Invalid zip code"],
    ['GE02', "Zip code not found"],
    ['GE03', "Demo mode"],
    ['GE04', "Expired database"]
  ]

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

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

  super
end

Instance Method Details

#assign_valuesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/melissadata/native_object/geo.rb', line 41

def assign_values
  @output = {
    :lat => obj.GetLatitude,
    :lng => obj.GetLongitude,
    :county_name => obj.GetCountyName,
    :county_fips => obj.GetCountyFips,
    :census_tract => obj.GetCensusTract,
    :census_block => obj.GetCensusBlock,
    :place_name => obj.GetPlaceName,
    :place_code => obj.GetPlaceCode,
    :time_zone => obj.GetTimeZone,
    :time_zone_code => obj.GetTimeZoneCode,

    :cbsa_code => obj.GetCBSACode,
    :cbsa_level => obj.GetCBSALevel,
    :cbsa_title => obj.GetCBSATitle,
    :cbsa_division_code => obj.GetCBSADivisionCode,
    :cbsa_division_title => obj.GetCBSADivisionTitle,
    :cbsa_division_level => obj.GetCBSADivisionLevel
  }
end

#parse_inputObject



33
34
35
36
37
38
39
# File 'lib/melissadata/native_object/geo.rb', line 33

def parse_input
  if ((dpc = input[:delivery_point_code]) || (dpc = input[:dpc])).present?
    obj.GeoPoint(input[:zip].to_s, input[:plus4].to_s, dpc.to_s)
  else
    obj.GeoCode(input[:zip].to_s, input[:plus4].to_s)
  end
end