Class: Gloo::Core::Pn
Constant Summary collapse
- ROOT =
'root'.freeze
- IT =
'it'.freeze
- ERROR =
'error'.freeze
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#src ⇒ Object
readonly
Returns the value of attribute src.
Class Method Summary collapse
-
.error ⇒ Object
Reference to the error message.
-
.it ⇒ Object
Reference to it.
-
.root ⇒ Object
Reference to the root object path.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Does the pathname reference refer to error?.
-
#exists? ⇒ Boolean
Does the object at the path exist?.
-
#get_parent ⇒ Object
Get the parent that contains the object referenced.
-
#gloo_sys? ⇒ Boolean
Does the pathname reference refer to the gloo system object?.
-
#includes_path? ⇒ Boolean
Does the value include a name?.
-
#initialize(src) ⇒ Pn
constructor
Set up the object given a source string, ie: the full path and name.
-
#it? ⇒ Boolean
Does the pathname reference refer to it?.
-
#name ⇒ Object
Get the name element.
-
#named? ⇒ Boolean
Does the value include path elements?.
-
#named_color? ⇒ Boolean
Is the reference to a color?.
-
#resolve ⇒ Object
Resolve the pathname reference.
-
#root? ⇒ Boolean
Does the pathname reference refer to the root?.
-
#segments ⇒ Object
Convert the raw string to a list of segments.
-
#set_to(value) ⇒ Object
Set the object pathname to the given value.
-
#to_s ⇒ Object
Get the string representation of the pathname.
Methods inherited from Baseo
Constructor Details
#initialize(src) ⇒ Pn
Set up the object given a source string, ie: the full path and name.
22 23 24 |
# File 'lib/gloo/core/pn.rb', line 22 def initialize( src ) set_to src end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
16 17 18 |
# File 'lib/gloo/core/pn.rb', line 16 def elements @elements end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
16 17 18 |
# File 'lib/gloo/core/pn.rb', line 16 def src @src end |
Class Method Details
.error ⇒ Object
Reference to the error message.
43 44 45 |
# File 'lib/gloo/core/pn.rb', line 43 def self.error return Pn.new( ERROR ) end |
Instance Method Details
#error? ⇒ Boolean
Does the pathname reference refer to error?
64 65 66 |
# File 'lib/gloo/core/pn.rb', line 64 def error? return @src.downcase == ERROR end |
#exists? ⇒ Boolean
Does the object at the path exist?
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/gloo/core/pn.rb', line 148 def exists? return true if self.root? return true if self.it? return true if self.error? parent = self.get_parent return false unless parent return parent.contains_child? name end |
#get_parent ⇒ Object
Get the parent that contains the object referenced.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/gloo/core/pn.rb', line 129 def get_parent o = $engine.heap.root if self.includes_path? @elements[ 0..-2 ].each do |e| o = o.find_child( e ) if o.nil? $log.error "Object '#{e}' was not found." return nil end end end return o end |
#gloo_sys? ⇒ Boolean
Does the pathname reference refer to the gloo system object?
71 72 73 74 75 76 77 78 79 |
# File 'lib/gloo/core/pn.rb', line 71 def gloo_sys? return false unless @elements&.count&.positive? o = @elements.first.downcase return true if o == Gloo::Core::GlooSystem.typename return true if o == Gloo::Core::GlooSystem.short_typename return false end |
#includes_path? ⇒ Boolean
Does the value include a name?
122 123 124 |
# File 'lib/gloo/core/pn.rb', line 122 def includes_path? return @elements.count > 1 end |
#it? ⇒ Boolean
Does the pathname reference refer to it?
57 58 59 |
# File 'lib/gloo/core/pn.rb', line 57 def it? return @src.downcase == IT end |
#name ⇒ Object
Get the name element.
106 107 108 109 110 |
# File 'lib/gloo/core/pn.rb', line 106 def name return '' unless self.named? return @elements.last end |
#named? ⇒ Boolean
Does the value include path elements?
115 116 117 |
# File 'lib/gloo/core/pn.rb', line 115 def named? return @elements.count.positive? end |
#named_color? ⇒ Boolean
Is the reference to a color?
162 163 164 165 |
# File 'lib/gloo/core/pn.rb', line 162 def named_color? colors = %w[red blue green white black yellow] return true if colors.include?( @src.downcase ) end |
#resolve ⇒ Object
Resolve the pathname reference. Find the object referenced or return nil if it is not found.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/gloo/core/pn.rb', line 171 def resolve return $engine.heap.root if self.root? return $engine.heap.it if self.it? return $engine.heap.error if self.error? return Gloo::Core::GlooSystem.new( self ) if self.gloo_sys? Here.( self ) if Here.includes_here_ref?( @elements ) parent = self.get_parent return nil unless parent obj = parent.find_child( self.name ) return Gloo::Objs::Alias.resolve_alias( obj, self.src ) end |
#root? ⇒ Boolean
Does the pathname reference refer to the root?
50 51 52 |
# File 'lib/gloo/core/pn.rb', line 50 def root? return @src.downcase == ROOT end |
#segments ⇒ Object
Convert the raw string to a list of segments.
99 100 101 |
# File 'lib/gloo/core/pn.rb', line 99 def segments return @elements end |
#set_to(value) ⇒ Object
Set the object pathname to the given value.
91 92 93 94 |
# File 'lib/gloo/core/pn.rb', line 91 def set_to( value ) @src = value.nil? ? nil : value.strip @elements = @src.nil? ? [] : @src.split( '.' ) end |
#to_s ⇒ Object
Get the string representation of the pathname.
84 85 86 |
# File 'lib/gloo/core/pn.rb', line 84 def to_s return @src end |