2020-10-13 19:54:16 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Reports
|
|
|
|
class Utils
|
|
|
|
def self.link_prepare(scinote_url, link)
|
2022-12-15 17:54:24 +08:00
|
|
|
return link if scinote_url.blank?
|
|
|
|
|
2020-10-13 19:54:16 +08:00
|
|
|
link[0] == '/' ? scinote_url + link : link
|
|
|
|
end
|
|
|
|
|
2020-10-28 23:32:22 +08:00
|
|
|
def self.image_prepare(asset)
|
|
|
|
if asset.class == Asset
|
|
|
|
if asset.inline?
|
2024-03-18 22:58:19 +08:00
|
|
|
asset.preview_attachment.representation(resize_to_limit: Constants::MEDIUM_PIC_FORMAT, format: :png)
|
2020-10-28 23:32:22 +08:00
|
|
|
else
|
2024-03-18 22:58:19 +08:00
|
|
|
asset.preview_attachment.representation(resize_to_limit: Constants::LARGE_PIC_FORMAT, format: :png)
|
2020-10-28 23:32:22 +08:00
|
|
|
end
|
|
|
|
elsif asset.class == TinyMceAsset
|
2024-03-18 22:58:19 +08:00
|
|
|
asset.image.representation(format: :png)
|
2020-10-28 23:32:22 +08:00
|
|
|
end
|
2020-10-13 19:54:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.calculate_color_hsp(color)
|
|
|
|
return 255 if color.length != 7
|
|
|
|
|
|
|
|
color = color.delete('#').scan(/.{1,2}/)
|
|
|
|
rgb = color.map(&:hex)
|
|
|
|
Math.sqrt(
|
|
|
|
0.299 * (rgb[0]**2) +
|
|
|
|
0.587 * (rgb[1]**2) +
|
|
|
|
0.114 * (rgb[2]**2)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|