10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/little_finger/parsers/tax_sales_file.rb', line 10
def parse(tax_file)
tax_data = {}
File.open(tax_file,"r").each_line do |line|
data = line.split(",")
zip_code = data[ZIP_CODE_IDX]
effective_date = data[EFFECTIVE_DATE_IDX]
rate = data[COMBINED_RATE_IDX]
state = data[STATE_IDX]
city = data[CITY_IDX]
description = "#{city}, #{state}"
entry = [zip_code,effective_date, rate, description, state, city]
raise StandardError.new("Avatax file format is incorrect: #{entry}") if entry.any?{|elem| elem.nil?}
key = (zip_code + city).strip
effective_date = "2015/01/01" if effective_date == "0000/00/00"
tax_data[key] = { zip: zip_code, city: city, state: state, tax_rate: BigDecimal.new(rate), effective_at: DateTime.strptime(effective_date, "%Y/%m/%d") }
end
tax_data
end
|