Class: Rgltf::Properties::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/rgltf/properties/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json, document:, index: nil, owner_type: nil) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
15
16
17
# File 'lib/rgltf/properties/base.rb', line 8

def initialize(json, document:, index: nil, owner_type: nil)
  @document = document
  @source_json = json
  @index = index
  @name = json['name']
  @extras = json['extras']
  @raw_extensions = json.fetch('extensions', {})
  @extensions = {}
  @owner_type = owner_type
end

Instance Attribute Details

#extensionsObject (readonly)

Returns the value of attribute extensions.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def extensions
  @extensions
end

#extrasObject (readonly)

Returns the value of attribute extras.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def extras
  @extras
end

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def index
  @index
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def name
  @name
end

#owner_typeObject (readonly)

Returns the value of attribute owner_type.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def owner_type
  @owner_type
end

#source_jsonObject (readonly)

Returns the value of attribute source_json.



6
7
8
# File 'lib/rgltf/properties/base.rb', line 6

def source_json
  @source_json
end

Instance Method Details

#extension(name) ⇒ Object



19
20
21
# File 'lib/rgltf/properties/base.rb', line 19

def extension(name)
  extensions[name]
end

#nested_propertiesObject



40
41
42
# File 'lib/rgltf/properties/base.rb', line 40

def nested_properties
  []
end

#parse_extensions!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rgltf/properties/base.rb', line 23

def parse_extensions!
  return self if @extensions_parsed

  @extensions = @raw_extensions.each_with_object({}) do |(name, value), parsed|
    parsed[name] = @document.extension_registry.parse(
      name,
      value,
      on: @owner_type,
      owner: self,
      doc: @document
    )
  end.freeze
  @extensions_parsed = true
  nested_properties.each(&:parse_extensions!)
  self
end