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.
43 lines
723 B
43 lines
723 B
2 years ago
|
class BulkUpload::Processor
|
||
|
attr_reader :bulk_upload
|
||
|
|
||
|
def initialize(bulk_upload:)
|
||
|
@bulk_upload = bulk_upload
|
||
|
end
|
||
|
|
||
|
def call
|
||
|
download
|
||
|
validator.call
|
||
|
ensure
|
||
|
downloader.delete_local_file!
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def downloader
|
||
|
@downloader ||= BulkUpload::Downloader.new(bulk_upload:)
|
||
|
end
|
||
|
|
||
|
def download
|
||
|
downloader.call
|
||
|
end
|
||
|
|
||
|
def validator
|
||
|
@validator ||= validator_class.new(
|
||
|
bulk_upload:,
|
||
|
path: downloader.path,
|
||
|
)
|
||
|
end
|
||
|
|
||
|
def validator_class
|
||
|
case bulk_upload.log_type
|
||
|
when "lettings"
|
||
|
BulkUpload::Lettings::Validator
|
||
|
when "sales"
|
||
|
BulkUpload::Sales::Validator
|
||
|
else
|
||
|
raise "Validator not found for #{bulk_upload.log_type}"
|
||
|
end
|
||
|
end
|
||
|
end
|