Class: SvgExport::CommandWrapper

Inherits:
Object
  • Object
show all
Defined in:
app/services/svg_export/command_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, options) ⇒ CommandWrapper

Returns a new instance of CommandWrapper.



4
5
6
7
8
9
10
# File 'app/services/svg_export/command_wrapper.rb', line 4

def initialize(params, options)
  @params = params
  @allowed_types = Engine.default_options[:allowed_types]
  @tmp_path = Engine.default_options[:tmp_path]
  @svg_transformer = Engine.default_options[:svg_transformer]
  @options = options
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'app/services/svg_export/command_wrapper.rb', line 3

def params
  @params
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/svg_export/command_wrapper.rb', line 12

def call
  transformer = @svg_transformer.new(@options)
  svg = transformer.transform(params[:svg])
  File.open('/tmp/jobwert-export-last.svg', 'w+') do |f|
    f.write svg
  end
  infile.write(svg)
  infile.flush
  result = run!
  fs = File.size?( outfile.path)
  if fs.nil? || fs < 10
    raise SvgExport::Error.new( "Output file empty;  #{result}")
  end
  transformer.clear!
  File.open(outfile)
end

#filenameObject



29
30
31
32
# File 'app/services/svg_export/command_wrapper.rb', line 29

def filename
  base = params[:filename].blank? ? "chart" : params[:filename]
  "#{base}.#{ext}"
end

#typeObject



34
35
36
37
38
# File 'app/services/svg_export/command_wrapper.rb', line 34

def type
  @type ||= begin
              @allowed_types.find{|t| t == params[:type] } or raise SvgExport::Error.new("Unknown type #{params[:type]}")
            end
end