Module: TinyGLTF::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



18
19
20
# File 'lib/tiny_gltf.rb', line 18

def model
  @model
end

Class Method Details

.included(base) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tiny_gltf.rb', line 21

def self.included(base)
  base.module_eval do
    class << self
      # :nodoc:
      # Easy way to differentiate between properties that should show up in
      # #inspect and #to_h, and those which should not.
      def attr_inspectable(name)
        name = name.to_sym
        @inspectable_attrs ||= []
        @inspectable_attrs.push name unless @inspectable_attrs.include?(name)
        attr_reader name
      end
    end
  end
end

Instance Method Details

#inspectObject



49
50
51
# File 'lib/tiny_gltf.rb', line 49

def inspect
  to_h.inspect
end

#to_hObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tiny_gltf.rb', line 37

def to_h
  {}.tap do |hash|
    self.class.instance_variable_get(:"@inspectable_attrs")&.each do |name|
      val = send(name)
      if val.kind_of?(Array)   then hash[name] = val.map { |el| el.kind_of?(Base) ? el.to_h : el }
      elsif val.kind_of?(Base) then hash[name] = val.to_h
      else                     hash[name] = val
      end
    end
  end
end

#to_json(*o) ⇒ Object



53
54
55
# File 'lib/tiny_gltf.rb', line 53

def to_json(*o)
  to_h.to_json(*o)
end