Class: DataMaps::Converter::Map

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

Overview

Map values

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/map.rb', line 8

def after_initialize
  @option = option.with_indifferent_access
end

#execute(data) ⇒ Object

The execute method to convert the given data

Parameters:

  • data (mixed)

Since:

  • 0.0.1



15
16
17
18
19
20
21
# File 'lib/data_maps/converter/map.rb', line 15

def execute(data)
  case data
    when Array then data.map{ |d| option[d] }
    when Hash then Hash[data.map{ |k,v| [k, option[v]] }]
    else option[data] || data
  end
end