Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Approach 1 #168

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,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 (defaults to 'en')
# @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
Expand All @@ -34,9 +35,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 (defaults to 'en')
# @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 )
Expand Down
3 changes: 2 additions & 1 deletion lib/heathen/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ def initialize( logger: Logger.new(nil) )
# @param content [String] the document body to be converted
# @param language [String] the document langauge (defaults to 'en')
# @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
Expand Down
6 changes: 3 additions & 3 deletions lib/heathen/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,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 (defaults to 'en')
# @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
Expand Down
5 changes: 3 additions & 2 deletions lib/legacy_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,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 (defaults to 'en')
# @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
Expand Down