Class: ColumnConverterCleaner

Inherits:
Cleaner
  • Object
show all
Defined in:
lib/suds/cleaner/column_converter_cleaner.rb

Instance Attribute Summary

Attributes inherited from Cleaner

#action, #data

Instance Method Summary collapse

Methods inherited from Cleaner

clean_array, clean_hash

Constructor Details

#initialize(convert_hash, force_strings = false) ⇒ ColumnConverterCleaner

Returns a new instance of ColumnConverterCleaner.



4
5
6
7
# File 'lib/suds/cleaner/column_converter_cleaner.rb', line 4

def initialize convert_hash, force_strings = false
  @force_strings = force_strings
  @convert_hash = convert_hash
end

Instance Method Details

#clean(data) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/suds/cleaner/column_converter_cleaner.rb', line 9

def clean data
  data.each do |row|
    keys = row.keys
    keys.each do |key|
      if new_key = @convert_hash[key]
        old_value = row[key]
        row.delete key
        if @force_strings
          new_key = new_key.to_s
        else
          new_key = new_key.to_sym
        end
        row[new_key] = old_value
      end
    end
  end
end