72 lines
1.8 KiB
Ruby
72 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module BrayniacAI
|
|
class AppearanceReleaseMatching
|
|
class << self
|
|
def match_attachments(request_data)
|
|
# TODO: Send request with request_data and receive real response
|
|
mock_response request_data
|
|
end
|
|
|
|
private
|
|
|
|
def mock_response(request_data)
|
|
attachments = request_data[:files]
|
|
pdfs = []
|
|
images = []
|
|
matches = []
|
|
|
|
# Use first file for the error entry
|
|
first_attachment = attachments.shift
|
|
|
|
if first_attachment.present?
|
|
matches << {
|
|
headshots: [],
|
|
contracts: [],
|
|
unknowns: [first_attachment],
|
|
identifier: ''
|
|
}
|
|
end
|
|
|
|
attachments.each do |attachment|
|
|
blob = ActiveStorage::Blob.find_signed attachment
|
|
next if blob.nil?
|
|
|
|
if blob.image?
|
|
images << attachment
|
|
else
|
|
pdfs << attachment
|
|
end
|
|
end
|
|
|
|
# Create pairs of matches and single headshot/contract after pairs are exhausted
|
|
more_pdfs = pdfs.length > images.length
|
|
pairs = more_pdfs ? pdfs.zip(images) : images.zip(pdfs)
|
|
pairs.each do |pair_element1, pair_element2|
|
|
if more_pdfs
|
|
pdf = pair_element1
|
|
image = pair_element2
|
|
else
|
|
pdf = pair_element2
|
|
image = pair_element1
|
|
end
|
|
headshots = image.present? ? [image] : []
|
|
contracts = pdf.present? ? [pdf] : []
|
|
|
|
matches << {
|
|
headshots: headshots,
|
|
contracts: contracts,
|
|
unknowns: [],
|
|
identifier: ''
|
|
}
|
|
end
|
|
|
|
{
|
|
request_id: request_data[:request_id],
|
|
matches: matches
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|