Class: Paperclip::Validators::AttachmentBackgroundValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Paperclip::Validators::AttachmentBackgroundValidator
- Defined in:
- lib/paperclip/validators/attachment_background_validator.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ AttachmentBackgroundValidator
constructor
A new instance of AttachmentBackgroundValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ AttachmentBackgroundValidator
Returns a new instance of AttachmentBackgroundValidator.
4 5 6 |
# File 'lib/paperclip/validators/attachment_background_validator.rb', line 4 def initialize() super end |
Class Method Details
.helper_method_name ⇒ Object
8 9 10 |
# File 'lib/paperclip/validators/attachment_background_validator.rb', line 8 def self.helper_method_name :validates_attachment_background end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/paperclip/validators/attachment_background_validator.rb', line 12 def validate_each(record, attribute, value) if record.send(attr).try(:queued_for_write).present? _video = FFMPEG::Movie.new(record.send(attr).queued_for_write[:original].path) if _video.valid? frame_png = Tempfile.new(["screenshot_#{record.id}_",'.png']) frame_txt = Tempfile.new(["screenshot_#{record.id}_",'.txt']) begin _video.screenshot(frame_png.path) `convert #{frame_png.path} -resize 20% #{frame_txt.path}` lines = `head -n 10 #{frame_txt.path}`.split("\n") lines += `tail -n 10 #{frame_txt.path}`.split("\n") lines.shift if !lines.all? {|l| l.end_with? '(65535,65535,65535) #FFFFFF white'} record.errors.add attr, 'Background is not white (#FFFFFF)' end ensure frame_png.close frame_png.unlink frame_txt.close frame_txt.unlink end end end end |