Class: MicrosoftKiotaAbstractions::ParseNodeFactoryRegistry

Inherits:
Object
  • Object
show all
Includes:
ParseNodeFactory
Defined in:
lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from ParseNodeFactory

get_parse_node

Class Attribute Details

.default_instanceObject

Returns the value of attribute default_instance.



8
9
10
# File 'lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb', line 8

def default_instance
  @default_instance
end

Instance Method Details

#content_type_associated_factoriesObject



16
17
18
# File 'lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb', line 16

def content_type_associated_factories
  @content_type_associated_factories ||= Hash.new
end

#default_instanceObject



12
13
14
# File 'lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb', line 12

def default_instance
self.class.default_instance
end

#get_parse_node(content_type, content) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/microsoft_kiota_abstractions/serialization/parse_node_factory_registry.rb', line 20

def get_parse_node(content_type, content)
  if !content_type
    raise Exception.new 'content type cannot be undefined or empty'
  end
  if !content
    raise Exception.new 'content cannot be undefined or empty'
  end
  vendor_specific_content_type = content_type.split(';').first
  factory = @content_type_associated_factories[vendor_specific_content_type]
  if factory
    return factory.get_parse_node(vendor_specific_content_type, content)
  end

  clean_content_type = vendor_specific_content_type.gsub(/[^\/]+\+/i, '')
  factory = @content_type_associated_factories[clean_content_type]
  if factory
    return factory.get_parse_node(clean_content_type, content)
  end
  raise Exception.new "Content type #{contentType} does not have a factory to be parsed"
end