Class: DTK::DSL::InputOutputCommon::Canonical::Hash
- Inherits:
-
Hash
- Object
- Hash
- Hash
- DTK::DSL::InputOutputCommon::Canonical::Hash
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
#delete_key(output_key) ⇒ Object
34
35
36
|
# 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) ⇒ Object
57
58
59
60
61
|
# 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) ⇒ Object
required that value at index is non nil
48
49
50
51
52
53
54
55
|
# 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) ⇒ 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
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
39
40
41
42
43
44
45
|
# 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
|