Class: DtkCommon::DSL::FileParser::InputHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/dsl/file_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ InputHash

to provide autovification and use of symbol indexes



155
156
157
158
159
160
161
162
163
# File 'lib/dsl/file_parser.rb', line 155

def initialize(hash=nil)
  super()
  return unless hash
  replace_el = hash.inject(Hash.new) do |h,(k,v)|
    processed_v = (v.kind_of?(Hash) ? self.class.new(v) : v)
    h.merge(k =>  processed_v)
  end
  replace(replace_el)
end

Instance Method Details

#[](index) ⇒ Object



165
166
167
168
# File 'lib/dsl/file_parser.rb', line 165

def [](index)
  val = super(internal_key_form(index)) || {}
  (val.kind_of?(Hash) ? self.class.new(val) : val)
end

#only_has_keys?(*only_has_keys) ⇒ Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/dsl/file_parser.rb', line 169

def only_has_keys?(*only_has_keys)
  (keys() - only_has_keys.map{|k|internal_key_form(k)}).empty?
end