Class: WeasyRb::Converter

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

Overview

Main converter class responsible for orchestrating HTML to PDF conversion Follows Single Responsibility Principle by focusing only on conversion logic

Instance Method Summary collapse

Constructor Details

#initialize(command_builder: CommandBuilder.new, executor: Executor.new) ⇒ Converter

Returns a new instance of Converter.



7
8
9
10
# File 'lib/weasy_rb/converter.rb', line 7

def initialize(command_builder: CommandBuilder.new, executor: Executor.new)
  @command_builder = command_builder
  @executor = executor
end

Instance Method Details

#convert(html, output_path, options = {}) ⇒ String

Converts HTML content to PDF file

Parameters:

  • html (String)

    HTML content to convert

  • output_path (String)

    Path where the PDF will be saved

  • options (Hash) (defaults to: {})

    Additional options for WeasyPrint

Returns:

  • (String)

    Path to the generated PDF file



17
18
19
20
21
22
23
24
# File 'lib/weasy_rb/converter.rb', line 17

def convert(html, output_path, options = {})
  validate_inputs(html, output_path)

  command = @command_builder.build(output_path, options)
  result = @executor.execute(command, html)

  handle_result(result, output_path)
end