Module: JA2R::KlassRegistry

Extended by:
KlassRegistry
Included in:
KlassRegistry
Defined in:
lib/ja2r/klass_registry.rb

Instance Method Summary collapse

Instance Method Details

#instantiate(hash, options) ⇒ Object



5
6
7
8
9
# File 'lib/ja2r/klass_registry.rb', line 5

def instantiate(hash, options)
  return unless hash&.key? 'type'

  lookup(hash['type']).new(hash, options)
end

#lookup(type) ⇒ Object



11
12
13
# File 'lib/ja2r/klass_registry.rb', line 11

def lookup(type)
  registry.fetch(type) { Element }
end

#register(type, klass) ⇒ Object



15
16
17
# File 'lib/ja2r/klass_registry.rb', line 15

def register(type, klass)
  registry[type] = klass
end