You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
559 B
26 lines
559 B
2 years ago
|
require "csv"
|
||
|
|
||
|
module Imports
|
||
|
class LocalAuthoritiesService
|
||
|
attr_reader :path, :count
|
||
|
|
||
|
def initialize(path:)
|
||
|
@path = path
|
||
|
@count = 0
|
||
|
end
|
||
|
|
||
|
def call
|
||
|
CSV.foreach(path, headers: true) do |row|
|
||
|
LocalAuthority.upsert(
|
||
|
{ code: row["code"],
|
||
|
name: row["name"],
|
||
|
start_date: Time.zone.local(row["start_year"], 4, 1),
|
||
|
end_date: (Time.zone.local(row["end_year"], 3, 31) if row["end_year"]) },
|
||
|
unique_by: %i[code],
|
||
|
)
|
||
|
@count += 1
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|