class GeocodeRecords::GeocodeCsv
Constants
- COLUMN_DEFINITION
- REQUIRED_SMARTYSTREETS_VERSION
Attributes
glob[R]
include_invalid[R]
num[R]
path[R]
Public Class Methods
new( path:, glob:, include_invalid:, num: )
click to toggle source
# 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
Public Instance Methods
perform()
click to toggle source
# 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
Private Instance Methods
input_map()
click to toggle source
# File lib/geocode_records/geocode_csv.rb, line 69 def input_map @input_map ||= begin num_suffix = (num == 1 ? '' : num) if glob { 'street' => "glob#{num_suffix}" } else { 'street' => "house_number_and_street#{num_suffix}", 'zipcode' => "postcode#{num_suffix}", 'city' => "city#{num_suffix}", 'state' => "state#{num_suffix}", } end end end
smartystreets_bin_path()
click to toggle source
# File lib/geocode_records/geocode_csv.rb, line 85 def smartystreets_bin_path @smartystreets_bin_path ||= begin memo = [ 'node_modules/.bin/smartystreets', `which smartystreets`.chomp ].compact.detect do |path| File.exist? path end raise "can't find smartystreets bin" unless memo version = Gem::Version.new `#{memo} -V`.chomp raise "smartystreets #{version} too old" unless version >= REQUIRED_SMARTYSTREETS_VERSION memo end end