Files
baclight/app/services/image_processor_service.rb
T

33 lines
1016 B
Ruby
Raw Normal View History

2026-03-20 10:46:53 -04:00
class ImageProcessorService
2026-03-13 08:47:13 -04:00
ALLOWED_LOGO_TYPES = ['Network', 'Employer'].freeze
2026-03-13 08:47:13 -04:00
def initialize(image_path, logo_type, new_filename = nil)
@image_path = image_path
2026-03-13 08:47:13 -04:00
@logo_type = logo_type.capitalize
@new_filename = new_filename
2026-03-13 08:47:13 -04:00
unless ALLOWED_LOGO_TYPES.include?(@logo_type)
raise ArgumentError, "Invalid logo type: #{@logo_type}. Must be one of: #{ALLOWED_LOGO_TYPES.join(', ')}"
end
end
def call
if @new_filename
filename = @new_filename
else
filename = File.basename(@image_path)
end
binary_data = File.binread(@image_path)
# binary_data = File.open(@image_path, 'rb').read
meme_type = Marcel::MimeType.for Pathname.new(@image_path)
2026-03-13 08:47:13 -04:00
logo_model = "IdCard::#{@logo_type}Logo".constantize
logo_model.find_or_create_by(filename: filename) do |logo|
logo.image_data = binary_data
logo.content_type = meme_type
end
end
end