Class: ConvertToPDF

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

Constant Summary collapse

PDF_OPTIONS =
{
  page_size: 'A4'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ ConvertToPDF

Returns a new instance of ConvertToPDF.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/code2pdf/convert_to_pdf.rb', line 6

def initialize(params = {})
  if !params.key?(:from) || params[:from].nil?
    raise ArgumentError.new 'where is the codebase you want to convert to PDF?'
  elsif !valid_directory?(params[:from])
    raise LoadError.new "#{params[:from]} not found"
  elsif !params.key?(:to) || params[:to].nil?
    raise ArgumentError.new 'where should I save the generated pdf file?'
  else
    @from, @to, @except = params[:from], params[:to], params[:except].to_s

    if File.exist?(@except) && invalid_blacklist?
      raise LoadError.new "#{@except} is not a valid blacklist YAML file"
    end

    save
  end
end