Class: Poleica::Converters::LibreOffice::OptionsGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/poleica/converters/libre_office.rb

Overview

Generate options for the soffice command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(polei, options = {}, format = :pdf) ⇒ OptionsGenerator

Returns a new instance of OptionsGenerator.



34
35
36
37
38
39
# File 'lib/poleica/converters/libre_office.rb', line 34

def initialize(polei, options = {}, format = :pdf)
  @polei       = polei
  @format      = format
  @output_path = options[:path] || polei.path_with_md5(format)
  @options     = default_options.merge(options)
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



32
33
34
# File 'lib/poleica/converters/libre_office.rb', line 32

def format
  @format
end

#optionsObject (readonly)

Returns the value of attribute options.



32
33
34
# File 'lib/poleica/converters/libre_office.rb', line 32

def options
  @options
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



32
33
34
# File 'lib/poleica/converters/libre_office.rb', line 32

def output_path
  @output_path
end

#poleiObject (readonly)

Returns the value of attribute polei.



32
33
34
# File 'lib/poleica/converters/libre_office.rb', line 32

def polei
  @polei
end

Instance Method Details

#default_optionsObject



41
42
43
# File 'lib/poleica/converters/libre_office.rb', line 41

def default_options
  { path: polei.path_with_md5 }
end

#generateObject



45
46
47
48
49
50
51
# File 'lib/poleica/converters/libre_office.rb', line 45

def generate
  [
    default_arguments,
    format,
    output_options
  ].flatten
end

#temp_pathObject

Generate a temp path, and create the file this is needed in order to have the right filename, LibreOffice just copy the original filename in the choosen directory, it doesn’t accept filename params.



57
58
59
60
61
# File 'lib/poleica/converters/libre_office.rb', line 57

def temp_path
  @temp_path ||= generate_temp_path
  FileUtils.cp(polei.path, @temp_path) unless File.exist?(@temp_path)
  @temp_path
end