Class: Colore::Converter

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

Overview

The Colore Converter is a glue class to allow Colore to access the Heathen conversion system.

Instance Method Summary collapse

Constructor Details

#initialize(storage_dir: C_.storage_directory, logger: Logger.new(C_.conversion_log || STDOUT)) ⇒ Converter


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

def initialize storage_dir: C_.storage_directory, logger: Logger.new(C_.conversion_log || STDOUT)
  @storage_dir = storage_dir
  @logger = logger
end

Instance Method Details

#convert(doc_key, version, filename, action) ⇒ Object

Converts the given file and stores it under the same document version.


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/converter.rb', line 20

def convert doc_key, version, filename, action
  doc = Document.load @storage_dir, doc_key
  ignore, orig_content = doc.get_file( version, filename)
  language = 'en' # TODO - add to spec and upload
  new_content = convert_file action, orig_content, language  # TODO - handling for variant formats with the same extension
  #        probably by adding format info before suffix
  #        e.g. foo.40x40.jpg

  new_filename = Heathen::Filename.suggest filename, new_content.mime_type
  doc.add_file version, new_filename, new_content
  doc.
  return new_filename
end

#convert_file(action, orig_content, language = 'en') ⇒ String

Converts the supplied content. Nothing gets saved.


39
40
41
42
43
44
45
# File 'lib/converter.rb', line 39

def convert_file action, orig_content, language='en'
  Heathen::Converter.new(logger:@logger).convert(action, orig_content, language)
rescue Heathen::TaskNotFound => e
  raise InvalidAction.new( e.message )
rescue Heathen::Error => e
  raise ConversionError.new( e )
end