Class: Hash

Inherits:
Object
  • Object
show all
Defined in:
lib/netlinx/erb/helpers.rb

Overview

:nodoc:

Other collapse

Instance Method Details

#remap(nested_key) ⇒ Hash

Reconstructs a single level hash out of a hash with nested parameters.

Examples:

buttons = {
  :TOUCH_PANEL_BUTTON_1 => { btn: 1, matrix_input: :MTX_IN_DVD },
  :TOUCH_PANEL_BUTTON_2 => { btn: 2, matrix_input: :MTX_IN_VCR }
}

# buttons.remap(:btn) will return a hash of touch panel button
# symbols with the :btn numbers mapped as the values, and
# :matrix_input will be discarded.

Parameters:

  • nested_key

    use the value associated with this key in the nested hash

Returns:

  • (Hash)

    keys mapped to the set of values specified



347
348
349
# File 'lib/netlinx/erb/helpers.rb', line 347

def remap nested_key
  self.map { |k,v| [k, v[nested_key]] }.to_h
end