Class: DataMaps::Converter::Key
- Inherits:
-
Base
- Object
- Executable
- Base
- DataMaps::Converter::Key
- Defined in:
- lib/data_maps/converter/key.rb
Overview
Converts hash keys
Instance Attribute Summary
Attributes inherited from Executable
Instance Method Summary collapse
-
#after_initialize ⇒ Object
The after initialize callback.
-
#execute(data) ⇒ Object
The execute method to convert the keys of given data.
Methods inherited from Executable
#initialize, valid_collection?
Constructor Details
This class inherits a constructor from DataMaps::Executable
Instance Method Details
#after_initialize ⇒ Object
The after initialize callback
8 9 10 |
# File 'lib/data_maps/converter/key.rb', line 8 def after_initialize @option = option.with_indifferent_access end |
#execute(data) ⇒ Object
The execute method to convert the keys of given data
15 16 17 18 19 20 |
# File 'lib/data_maps/converter/key.rb', line 15 def execute(data) case data when Hash then Hash[data.map{ |k,v| [option[k] || k, v] }] else data end end |