Class: OpenUSD::AttributeSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/openusd/attribute_spec.rb

Overview

An authored attribute in a Layer.

Constant Summary collapse

UNAUTHORED =

Sentinel distinguishing an absent default from an authored value block.

Object.new.freeze
VARIABILITIES =

Valid attribute variability values.

%i[varying uniform].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type_name, default: UNAUTHORED, variability: :varying, custom: false, metadata: {}) ⇒ AttributeSpec

Returns a new instance of AttributeSpec.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openusd/attribute_spec.rb', line 14

def initialize(name, type_name, default: UNAUTHORED, variability: :varying, custom: false, metadata: {})
  @name = validate_name(name)
  @type_name = String(type_name).dup.freeze
  self.variability = variability
  @custom = custom == true
  @metadata = .dup
  @connections = []
  @connections_authored = false
  @time_samples = {}
  @time_samples_authored = false
  @default_authored = false
  set(default) unless default.equal?(UNAUTHORED)
end

Instance Attribute Details

#connectionsObject

Returns the value of attribute connections.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def connections
  @connections
end

#customObject

Returns the value of attribute custom.



12
13
14
# File 'lib/openusd/attribute_spec.rb', line 12

def custom
  @custom
end

#defaultObject (readonly)

Returns the value of attribute default.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def default
  @default
end

#metadataObject (readonly)

Returns the value of attribute metadata.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def name
  @name
end

#time_samplesObject

Returns the value of attribute time_samples.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def time_samples
  @time_samples
end

#type_nameObject

Returns the value of attribute type_name.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def type_name
  @type_name
end

#variabilityObject

Returns the value of attribute variability.



11
12
13
# File 'lib/openusd/attribute_spec.rb', line 11

def variability
  @variability
end

Instance Method Details

#clear_defaultObject

Remove the default opinion.



68
69
70
71
72
# File 'lib/openusd/attribute_spec.rb', line 68

def clear_default
  @default = nil
  @default_authored = false
  self
end

#connections_authored?Boolean

Whether connections, including an empty list, are authored.

Returns:

  • (Boolean)


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

def connections_authored?
  @connections_authored
end

#default_authored?Boolean

Whether a default opinion, including a value block, is authored.

Returns:

  • (Boolean)


43
44
45
# File 'lib/openusd/attribute_spec.rb', line 43

def default_authored?
  @default_authored
end

#set(value, time: nil) ⇒ Object

Set a default or time-sampled value.



58
59
60
61
62
63
64
65
# File 'lib/openusd/attribute_spec.rb', line 58

def set(value, time: nil)
  normalized = value.nil? ? nil : Types.coerce(type_name, value)
  return set_time_sample(time, normalized) unless time.nil?

  @default = normalized
  @default_authored = true
  normalized
end

#time_samples_authored?Boolean

Whether a timeSamples dictionary, including an empty one, is authored.

Returns:

  • (Boolean)


48
49
50
# File 'lib/openusd/attribute_spec.rb', line 48

def time_samples_authored?
  @time_samples_authored
end

#to_hHash

Returns semantic representation used for equality.

Returns:

  • (Hash)

    semantic representation used for equality



91
92
93
94
95
96
97
98
99
100
# File 'lib/openusd/attribute_spec.rb', line 91

def to_h
  {
    name: name, type_name: type_name, default: default,
    default_authored: default_authored?, time_samples: time_samples,
    time_samples_authored: time_samples_authored?,
    variability: variability, custom: custom, connections: connections,
    connections_authored: connections_authored?,
    metadata: 
  }
end