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
# File 'app/services/svg_export/command_wrapper.rb', line 12

def call
  transformer = @svg_transformer.new(@options)
  svg = transformer.transform(params[:svg])
  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
  File.open(outfile)
end

#filenameObject



25
26
27
28
# File 'app/services/svg_export/command_wrapper.rb', line 25

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

#typeObject



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

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