Class: GeocodeRecords::GeocodeCsv

Inherits:
Object
  • Object
show all
Defined in:
lib/geocode_records/geocode_csv.rb

Constant Summary collapse

REQUIRED_SMARTYSTREETS_VERSION =
Gem::Version.new('1.8.2')
COLUMN_DEFINITION =
{
  delivery_line_1: true,
  components: {
    street_predirection: true,
    street_name: true,
    street_suffix: true,
    street_postdirection: true,
    primary_number: true,
    secondary_number: true,
    city_name: true,
    default_city_name: true,
    state_abbreviation: true,
    zipcode: true,
    plus4_code: true,
  },
  metadata: {
    latitude: true,
    longitude: true,
    rdi: true,
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, glob:, include_invalid:, num:) ⇒ GeocodeCsv

Returns a new instance of GeocodeCsv.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/geocode_records/geocode_csv.rb', line 33

def initialize(
  path:,
  glob:,
  include_invalid:,
  num:
)
  @path = path
  @glob = glob
  @include_invalid = include_invalid
  @num = num
end

Instance Attribute Details

#globObject (readonly)

Returns the value of attribute glob.



6
7
8
# File 'lib/geocode_records/geocode_csv.rb', line 6

def glob
  @glob
end

#include_invalidObject (readonly)

Returns the value of attribute include_invalid.



7
8
9
# File 'lib/geocode_records/geocode_csv.rb', line 7

def include_invalid
  @include_invalid
end

#numObject (readonly)

Returns the value of attribute num.



8
9
10
# File 'lib/geocode_records/geocode_csv.rb', line 8

def num
  @num
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/geocode_records/geocode_csv.rb', line 5

def path
  @path
end

Instance Method Details

#performObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/geocode_records/geocode_csv.rb', line 45

def perform
  return unless File.size(path) > 32
  memo = GeocodeRecords.new_tmp_path File.basename("geocoded-#{path}")
  args = [
    smartystreets_bin_path,
    '-i', path,
    '-o', memo,
    '--quiet',
    '--auth-id', ENV.fetch('SMARTY_STREETS_AUTH_ID'),
    '--auth-token', ENV.fetch('SMARTY_STREETS_AUTH_TOKEN'),
    '--column-definition', JSON.dump(COLUMN_DEFINITION),
  ]
  if include_invalid
    args += [ '--include-invalid' ]
  end
  input_map.each do |ss, local|
    args += [ "--#{ss}-col", local.to_s ]
  end
  system(*args) or raise("smartystreets failed")
  memo
end