Class: DTK::DSL::InputOutputCommon::Canonical::Hash

Inherits:
Hash
  • Object
show all
Defined in:
lib/dsl/input_output_common/canonical/hash.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Hash

Returns a new instance of Hash.



22
23
24
# File 'lib/dsl/input_output_common/canonical/hash.rb', line 22

def initialize(*args)
  super
end

Instance Method Details

#remove_all_except!(*output_keys) ⇒ Object



53
54
55
56
57
# File 'lib/dsl/input_output_common/canonical/hash.rb', line 53

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) ⇒ Object

required that value at index is non nil



44
45
46
47
48
49
50
51
# File 'lib/dsl/input_output_common/canonical/hash.rb', line 44

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) ⇒ Object



26
27
28
# 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) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# 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) ⇒ Object

value at index output_key



35
36
37
38
39
40
41
# File 'lib/dsl/input_output_common/canonical/hash.rb', line 35

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