Class: Translatomatic::Converter

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

Overview

Converts files from one format to another

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Converter

Returns a new instance of Converter.



4
5
6
# File 'lib/translatomatic/converter.rb', line 4

def initialize(options = {})
  @options = options
end

Instance Method Details

#convert(source, target) ⇒ Translatomatic::ResourceFile

Convert a resource file from one format to another.

Parameters:

  • source (String)

    Path to source file. File must exist

  • target (String)

    Path to target file. File will be created or overwritten if it already exists.

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/translatomatic/converter.rb', line 13

def convert(source, target)
  source_path = Pathname.new(source.to_s)
  target_path = Pathname.new(target.to_s)
  raise t("file.not_found", file: source.to_s) unless source_path.file?
  raise t("file.directory", file: target.to_s) if target_path.directory?

  source_file = load_file(source_path)
  target_file = load_file(target_path)

  # copy properties from source file to target
  target_file.properties = source_file.properties
  target_file.save(target_path, @options)
  target_file
end