Class: DataMaps::Converter::Key

Inherits:
Base show all
Defined in:
lib/data_maps/converter/key.rb

Overview

Converts hash keys

Since:

  • 0.0.1

Instance Attribute Summary

Attributes inherited from Executable

#@option, #option

Instance Method Summary collapse

Methods inherited from Executable

#initialize, valid_collection?

Constructor Details

This class inherits a constructor from DataMaps::Executable

Instance Method Details

#after_initializeObject

The after initialize callback

Since:

  • 0.0.1



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

Parameters:

  • data (mixed)

Since:

  • 0.0.1



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