Class: Lcms::Engine::LessonsPdfBundler

Inherits:
Object
  • Object
show all
Defined in:
app/services/lcms/engine/lessons_pdf_bundler.rb

Constant Summary collapse

{
  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

Instance Method Summary collapse

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

#unitObject (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

#bundleObject



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