Class: OpenUSD::Path
Overview
Immutable SdfPath-like value object for prim and property paths.
Constant Summary collapse
- IDENTIFIER =
Reusable USD identifier fragment.
/[\p{L}_][\p{L}\p{N}_]*/u- PRIM_NAME =
Validation expression for prim names.
/\A#{IDENTIFIER}\z/u- PROPERTY_NAME =
Validation expression for namespaced property names.
/\A#{IDENTIFIER}(?::#{IDENTIFIER})*\z/u
Instance Attribute Summary collapse
-
#property_name ⇒ Object
readonly
Returns the value of attribute property_name.
Class Method Summary collapse
-
.parse(value) ⇒ Path
Parse a path string.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compare paths by their canonical string form.
-
#absolute? ⇒ Boolean
Whether this path begins at the pseudo-root.
-
#child(name) ⇒ Path
Append a child prim name.
- #eql?(other) ⇒ Boolean (also: #==)
-
#hash ⇒ Integer
Value hash compatible with #eql?.
-
#initialize(value) ⇒ Path
constructor
A new instance of Path.
-
#inspect ⇒ String
Developer representation.
-
#parent ⇒ Path?
Return the namespace parent, or nil when no parent exists.
-
#prim_path ⇒ Path
Return the prim portion of this path.
-
#property(name) ⇒ Path
Append a property name.
-
#property? ⇒ Boolean
Whether this identifies a property rather than a prim.
-
#to_s ⇒ String
Canonical path text.
Constructor Details
#initialize(value) ⇒ Path
Returns a new instance of Path.
31 32 33 34 35 36 |
# File 'lib/openusd/path.rb', line 31 def initialize(value) @value = value.dup.freeze @property_name = split_property validate! freeze end |
Instance Attribute Details
#property_name ⇒ Object (readonly)
Returns the value of attribute property_name.
15 16 17 |
# File 'lib/openusd/path.rb', line 15 def property_name @property_name end |
Class Method Details
Instance Method Details
#<=>(other) ⇒ Object
Compare paths by their canonical string form.
99 100 101 102 103 |
# File 'lib/openusd/path.rb', line 99 def <=>(other) @value <=> self.class.parse(other).to_s rescue PathError nil end |
#absolute? ⇒ Boolean
Whether this path begins at the pseudo-root.
39 40 41 |
# File 'lib/openusd/path.rb', line 39 def absolute? @value.start_with?("/") end |
#child(name) ⇒ Path
Append a child prim name.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/openusd/path.rb', line 72 def child(name) raise PathError, "a property path cannot have prim children" if property? child_name = String(name) raise PathError, "invalid prim name: #{child_name.inspect}" unless PRIM_NAME.match?(child_name) separator = @value == "/" ? "" : "/" self.class.parse("#{@value}#{separator}#{child_name}") rescue ArgumentError, TypeError raise PathError, "child name must be a string" end |
#eql?(other) ⇒ Boolean Also known as: ==
105 106 107 |
# File 'lib/openusd/path.rb', line 105 def eql?(other) other.is_a?(self.class) && @value == other.to_s end |
#hash ⇒ Integer
Returns value hash compatible with #eql?.
111 112 113 |
# File 'lib/openusd/path.rb', line 111 def hash @value.hash end |
#inspect ⇒ String
Returns developer representation.
121 122 123 |
# File 'lib/openusd/path.rb', line 121 def inspect "#<#{self.class} #{@value.inspect}>" end |
#parent ⇒ Path?
Return the namespace parent, or nil when no parent exists.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/openusd/path.rb', line 58 def parent return prim_path if property? return nil if @value == "/" separator = @value.rindex("/") return nil unless separator return self.class.parse("/") if separator.zero? self.class.parse(@value[0...separator]) end |
#prim_path ⇒ Path
Return the prim portion of this path.
50 51 52 53 54 |
# File 'lib/openusd/path.rb', line 50 def prim_path return self unless property? self.class.parse(@value.delete_suffix(".#{property_name}")) end |
#property(name) ⇒ Path
Append a property name.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/openusd/path.rb', line 87 def property(name) raise PathError, "a property path cannot have another property" if property? property = String(name) raise PathError, "invalid property name: #{property.inspect}" unless PROPERTY_NAME.match?(property) self.class.parse("#{@value}.#{property}") rescue ArgumentError, TypeError raise PathError, "property name must be a string" end |
#property? ⇒ Boolean
Whether this identifies a property rather than a prim.
44 45 46 |
# File 'lib/openusd/path.rb', line 44 def property? !property_name.nil? end |
#to_s ⇒ String
Returns canonical path text.
116 117 118 |
# File 'lib/openusd/path.rb', line 116 def to_s @value end |