Module: Shrine::Plugins::ValidatePdfPageCount::AttacherMethods
- Defined in:
- lib/shrine/plugins/validate_pdf_page_count.rb
Constant Summary collapse
- TOO_MANY_PAGES =
'too_many_pages'
- TOO_FEW_PAGES =
'too_few_pages'
Instance Method Summary collapse
- #get_page_count(file) ⇒ Object private
- #validate_pdf_page_count(max_pages: nil, min_pages: 1) ⇒ Object
Instance Method Details
#get_page_count(file) ⇒ Object (private)
25 26 27 28 |
# File 'lib/shrine/plugins/validate_pdf_page_count.rb', line 25 def get_page_count(file) reader = PDF::Reader.new(file) reader.page_count end |
#validate_pdf_page_count(max_pages: nil, min_pages: 1) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/shrine/plugins/validate_pdf_page_count.rb', line 10 def validate_pdf_page_count(max_pages: nil, min_pages: 1) return unless get.mime_type == Mime[:pdf].to_s file = get.download page_count = get_page_count(file) if page_count > max_pages record.warnings << TOO_MANY_PAGES elsif page_count < min_pages record.warnings << TOO_FEW_PAGES end end |