Class: Lcms::Engine::LessonsPdfBundler
- Inherits:
-
Object
- Object
- Lcms::Engine::LessonsPdfBundler
- Defined in:
- app/services/lcms/engine/lessons_pdf_bundler.rb
Constant Summary collapse
- PDF_LINKS_KEYS =
{ full: 'pdf', tm: 'pdf_tm', sm: 'pdf_sm' }.freeze
- TMP_FOLDER =
tmp folder for downloaded pdfs and bundled zip
Rails.root.join('tmp', 'unbounded-pdfs')
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Instance Method Summary collapse
- #bundle ⇒ Object
-
#initialize(unit, type = :full) ⇒ LessonsPdfBundler
constructor
A new instance of LessonsPdfBundler.
Constructor Details
#initialize(unit, type = :full) ⇒ LessonsPdfBundler
Returns a new instance of LessonsPdfBundler.
17 18 19 20 |
# File 'app/services/lcms/engine/lessons_pdf_bundler.rb', line 17 def initialize(unit, type = :full) @unit = unit @type = type.to_sym end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
6 7 8 |
# File 'app/services/lcms/engine/lessons_pdf_bundler.rb', line 6 def unit @unit end |
Instance Method Details
#bundle ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/lcms/engine/lessons_pdf_bundler.rb', line 22 def bundle return if files.empty? folder = File.join(TMP_FOLDER, dirname) begin FileUtils.mkdir_p folder # ensure the folder exists files.each do |url| fname = filename url download url, File.join(folder, fname) end zip_files ensure FileUtils.rm_r(folder) if File.exist?(folder) # remove tmp pdfs end # return ziped bundle path "#{folder}.zip" end |