class DTK::DSL::InputOutputCommon::Canonical::Hash

Public Class Methods

new(*args) click to toggle source
Calls superclass method DTK::DSL::InputOutputCommon::Hash::new
# File lib/dsl/input_output_common/canonical/hash.rb, line 22
def initialize(*args)
  super
end

Public Instance Methods

delete_key(output_key) click to toggle source
# File lib/dsl/input_output_common/canonical/hash.rb, line 34
def delete_key(output_key)
  delete(canonical_key_form_from_output_key(output_key))
end
remove_all_except!(*output_keys) click to toggle source
# File lib/dsl/input_output_common/canonical/hash.rb, line 57
def remove_all_except!(*output_keys)
  matching_internal_indexes = output_keys.inject([]) { |a, k| a + possible_key_forms_from_output_key(k) }
  keys.each { |internal_index| delete(internal_index) unless matching_internal_indexes.include?(internal_index) }
  self
end
req(output_key) click to toggle source

required that value at index is non nil

# File lib/dsl/input_output_common/canonical/hash.rb, line 48
def req(output_key)
  ret = val(output_key)
  if ret.nil?
    raise Error, "Unexpected nil value for output key '#{output_key}'"
  else
    ret
  end
end
set(output_key, val) click to toggle source
# File lib/dsl/input_output_common/canonical/hash.rb, line 26
def set(output_key, val)
  self[canonical_key_form_from_output_key(output_key)] = val
end
set?(output_key, val) click to toggle source
# File lib/dsl/input_output_common/canonical/hash.rb, line 30
def set?(output_key, val)
  set(output_key, val) unless val.nil?
end
val(output_key) click to toggle source

value at index output_key

# File lib/dsl/input_output_common/canonical/hash.rb, line 39
def val(output_key)
  ret = nil
  possible_key_forms_from_output_key(output_key).each do |internal_index|
    return self[internal_index] if has_key?(internal_index)
  end
  ret
end

Private Instance Methods

canonical_key_form_from_output_key(output_key) click to toggle source
# File lib/dsl/input_output_common/canonical/hash.rb, line 65
def canonical_key_form_from_output_key(output_key)
  HashKey.index(output_key)
end
possible_key_forms_from_output_key(output_key) click to toggle source

TODO: after converting so that all accessed keys are in canonical_key_form then can have do away with this method

# File lib/dsl/input_output_common/canonical/hash.rb, line 71
def possible_key_forms_from_output_key(output_key)
  key = canonical_key_form_from_output_key(output_key)
  [key.to_s, key.to_sym]
end