Class: Heathen::Converter

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

Overview

The Converter takes the given action and input content, identifies the task required to perform the action, then constructs a [Processor] to convert the document.

Instance Method Summary collapse

Constructor Details

#initialize(logger: Logger.new(nil)) ⇒ Converter

Returns a new instance of Converter.


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

def initialize( logger: Logger.new(nil) )
  @logger = logger
end

Instance Method Details

#convert(action, content, language = 'en') ⇒ String

Converts the given document according to the action requested.

Parameters:

  • action (String)

    the conversion action to perform

  • content (String)

    the document body to be converted

  • language (String) (defaults to: 'en')

    the document langauge (defaults to 'en')

Returns:

  • (String)

    the converted document body


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

def convert action, content, language='en'
  job = Job.new action, content, language
  processor = Heathen::Processor.new job: job, logger: @logger
  begin
    processor.perform_task action
  ensure
    processor.clean_up
  end
  job.content
end