Class: HtmlsToPdf

Inherits:
Object
  • Object
show all
Defined in:
lib/htmls_to_pdf/htmls_to_pdf.rb

Constant Summary collapse

TMP_HTML_PREFIX =
'tmp_html_file_'
TMP_PDF_PREFIX =
'tmp_pdf_file_'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(in_config = {}) ⇒ HtmlsToPdf

Returns a new instance of HtmlsToPdf.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 15

def initialize(in_config = {})
  config = {
    :css => [],
    :remove_css_files => true,
    :remove_html_files => true,
    :remove_tmp_pdf_files => true,
    :overwrite_existing_pdf => false,
    :options => {},
    :savedir => File.expand_path("~"),
    :savename => 'htmls_to_pdf.pdf'
  }.merge(in_config)
  set_dir(config[:savedir])
  @savename = config[:savename]
  @overwrite_existing_pdf = config[:overwrite_existing_pdf]
  exit_if_pdf_exists unless @overwrite_existing_pdf
  @urls = clean_urls(config[:urls])
  @pdfarray = create_pdfarray
  @cssarray = config[:css].kind_of?(Array) ? config[:css] : Array[ config[:css] ]
  @remove_css_files = config[:remove_css_files]
  @remove_html_files = config[:remove_html_files]
  @remove_tmp_pdf_files = config[:remove_tmp_pdf_files]
  @remove_css_files = @remove_html_files = @remove_tmp_pdf_files = true if in_config[:remove_temp_files]
  @options = config[:options]
end

Instance Attribute Details

#cssarrayObject (readonly)

Returns the value of attribute cssarray.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def cssarray
  @cssarray
end

#htmlarrayObject (readonly)

Returns the value of attribute htmlarray.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def htmlarray
  @htmlarray
end

#pdfarrayObject (readonly)

Returns the value of attribute pdfarray.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def pdfarray
  @pdfarray
end

#remove_css_filesObject (readonly)

Returns the value of attribute remove_css_files.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def remove_css_files
  @remove_css_files
end

#remove_html_filesObject (readonly)

Returns the value of attribute remove_html_files.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def remove_html_files
  @remove_html_files
end

#remove_tmp_pdf_filesObject (readonly)

Returns the value of attribute remove_tmp_pdf_files.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def remove_tmp_pdf_files
  @remove_tmp_pdf_files
end

#savedirObject (readonly)

Returns the value of attribute savedir.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def savedir
  @savedir
end

#savenameObject (readonly)

Returns the value of attribute savename.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def savename
  @savename
end

#urlsObject (readonly)

Returns the value of attribute urls.



10
11
12
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 10

def urls
  @urls
end

Instance Method Details

#create_pdfObject



40
41
42
43
44
45
46
# File 'lib/htmls_to_pdf/htmls_to_pdf.rb', line 40

def create_pdf
  clean_temp_files
  download_files
  generate_pdfs
  join_pdfs
  clean_temp_files
end