DB restructure, print page
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
module IdCard
|
||||
class NetworkLogo < ApplicationRecord
|
||||
before_save :round_aspect_ratio
|
||||
before_validation :calculate_aspect_ratio, if: :image_data_changed?
|
||||
|
||||
scope :defaults, -> { where(default: true) }
|
||||
|
||||
class << self
|
||||
|
||||
def medcost
|
||||
defaults.where("filename LIKE ?", "%Medcost%")
|
||||
end
|
||||
|
||||
def cigna
|
||||
defaults.where("filename LIKE ?", "%Cigna%")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def round_aspect_ratio
|
||||
if self.aspect_ratio.present?
|
||||
self.aspect_ratio = self.aspect_ratio.round(2)
|
||||
def calculate_aspect_ratio
|
||||
image_io = StringIO.new(image_data)
|
||||
width, height = FastImage.size(image_io)
|
||||
image_ratio = width.to_f / height
|
||||
if image_ratio
|
||||
self.aspect_ratio = image_ratio.round(2)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user