Class: Converter

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

Direct Known Subclasses

JSONConverter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outfile = nil, &b) ⇒ Converter

Returns a new instance of Converter.



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

def initialize outfile=nil, &b
  @outfile = outfile
  @converter = b
end

Instance Attribute Details

#converted_dataObject

Returns the value of attribute converted_data.



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

def converted_data
  @converted_data
end

#converterObject

Returns the value of attribute converter.



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

def converter
  @converter
end

#outfileObject

Returns the value of attribute outfile.



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

def outfile
  @outfile
end

Instance Method Details

#convert(data) ⇒ Object



11
12
13
14
# File 'lib/suds/converter.rb', line 11

def convert data
  raise "A generic Converter can only convert with a block" unless @converter
  @converted_data = @converter.call(data)
end

#convert!(data) ⇒ Object



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

def convert! data
  raise "Cannot output to file if outfile is not set." unless @outfile
  fname = File.expand_path(@outfile)
  dir = File.dirname fname

  if !File.directory?(dir)
    FileUtils.mkdir_p dir
  end

  File.open(fname, 'w').write(convert(data))
end