Class: Muhimbi::Converter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Converter

Returns a new instance of Converter.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/muhimbi/converter.rb', line 10

def initialize(opts={})

  unless opts[:file].blank?
    self.file_content = encode_file(opts[:file])
    self.file         = opts[:file]
  end

  self.tap do |client|
    client.options    ||= {}
    client.defaults_options(opts)
    client.options ||= opts
    yield client if block_given?
  end

end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, opts = {}) ⇒ Object



31
32
33
# File 'lib/muhimbi/converter.rb', line 31

def method_missing(meth, opts = {})
  merge_options meth, opts
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



6
7
8
# File 'lib/muhimbi/converter.rb', line 6

def file
  @file
end

#file_contentObject

Returns the value of attribute file_content.



6
7
8
# File 'lib/muhimbi/converter.rb', line 6

def file_content
  @file_content
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/muhimbi/converter.rb', line 6

def options
  @options
end

Instance Method Details

#convertObject



26
27
28
29
# File 'lib/muhimbi/converter.rb', line 26

def convert
  wsdl_res = Muhimbi::Client.client.call(:convert , message: self.options )
  wsdl_res.to_hash[:convert_response][:convert_result]
end

#defaults_options(opts = {}) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/muhimbi/converter.rb', line 35

def defaults_options(opts={})

  self.sourceFile(self.file_content)

  self.openOptions({
    "FileExtension"   => File.extname( self.file ).gsub(".", ""),
    "OriginalFileName"=> File.basename( self.file)
  })

  self.conversionSettings({
    "Format"  => "PDF",
    "Fidelity"=> "Full"
  })
end