diff --git a/lib/converter.rb b/lib/converter.rb index d9e2a1e..9511e1a 100644 --- a/lib/converter.rb +++ b/lib/converter.rb @@ -19,11 +19,12 @@ def initialize(storage_dir: C_.storage_directory, logger: Logger.new(C_.conversi # @param version [String] the file version # @param filename [String] the name of the file to convert # @param action [String] the conversion to perform + # @param language [String] the file's language. Forced to `en` if `nil` # @return the converted file name - def convert(doc_key, version, filename, action) + def convert(doc_key, version, filename, action, language = nil) + language ||= 'en' 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 @@ -37,9 +38,10 @@ def convert(doc_key, version, filename, action) # Converts the supplied content. Nothing gets saved. # @param action [String] the conversion to perform # @param orig_content [String] the body of the file to convert - # @param language [String] the file's language + # @param language [String] the file's language. Forced to `en` if `nil` # @return [String] the converted file body - def convert_file(action, orig_content, language = 'en') + def convert_file(action, orig_content, language = nil) + language ||= 'en' Heathen::Converter.new(logger: @logger).convert(action, orig_content, language) rescue Heathen::TaskNotFound => e raise InvalidAction.new(e.message) diff --git a/lib/heathen/converter.rb b/lib/heathen/converter.rb index a57832f..667f9d5 100644 --- a/lib/heathen/converter.rb +++ b/lib/heathen/converter.rb @@ -13,9 +13,10 @@ def initialize(logger: Logger.new(nil)) # Converts the given document according to the action requested. # @param action [String] the conversion action to perform # @param content [String] the document body to be converted - # @param language [String] the document language (defaults to 'en') + # @param language [String] the file's language. Forced to `en` if `nil` # @return [String] the converted document body - def convert(action, content, language = 'en') + def convert(action, content, language = nil) + language ||= 'en' job = Job.new action, content, language processor = Heathen::Processor.new job: job, logger: @logger begin diff --git a/lib/heathen/job.rb b/lib/heathen/job.rb index 054b515..8460156 100644 --- a/lib/heathen/job.rb +++ b/lib/heathen/job.rb @@ -25,11 +25,11 @@ class Job # Constructs a new job # @param action [String] the action to be performed # @param content [String] the file body - # @param language [String] the file's language + # @param language [String] the file's language. Forced to `en` if `nil` # @param sandbox_dir [String] sandbox directory for temporary files - def initialize(action, content, language = 'en', sandbox_dir = nil) + def initialize(action, content, language = nil, sandbox_dir = nil) @action = action - @language = language + @language = language || 'en' @original_content = content @original_mime_type = content.mime_type self.content = @original_content diff --git a/lib/legacy_converter.rb b/lib/legacy_converter.rb index 6fcde99..8315985 100644 --- a/lib/legacy_converter.rb +++ b/lib/legacy_converter.rb @@ -27,9 +27,10 @@ def initialize(storage_dir = C_.storage_directory) # Converts the given file and stores it in the legacy directory # @param action [String] the conversion to perform # @param orig_content [String] the body of the file to convert - # @param language [String] the file's language + # @param language [String] the file's language. Forced to `en` if `nil` # @return [String] the path to the converted file - def convert_file(action, orig_content, language = 'en') + def convert_file(action, orig_content, language = nil) + language ||= 'en' content = Heathen::Converter.new.convert(action, orig_content, language) filename = Digest::SHA2.hexdigest content store_file filename, content