Class: Converter
- Inherits:
-
Object
- Object
- Converter
- Defined in:
- lib/suds/converter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#converted_data ⇒ Object
Returns the value of attribute converted_data.
-
#converter ⇒ Object
Returns the value of attribute converter.
-
#outfile ⇒ Object
Returns the value of attribute outfile.
Instance Method Summary collapse
- #convert(data) ⇒ Object
- #convert!(data) ⇒ Object
-
#initialize(outfile = nil, &b) ⇒ Converter
constructor
A new instance of Converter.
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_data ⇒ Object
Returns the value of attribute converted_data.
4 5 6 |
# File 'lib/suds/converter.rb', line 4 def converted_data @converted_data end |
#converter ⇒ Object
Returns the value of attribute converter.
4 5 6 |
# File 'lib/suds/converter.rb', line 4 def converter @converter end |
#outfile ⇒ Object
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.(@outfile) dir = File.dirname fname if !File.directory?(dir) FileUtils.mkdir_p dir end File.open(fname, 'w').write(convert(data)) end |