Class: Gloo::Core::Pn
Constant Summary collapse
- ROOT =
'root'.freeze
- IT =
'it'.freeze
- ERROR =
'error'.freeze
- CONTEXT =
'@'.freeze
Constants inherited from Baseo
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(engine) ⇒ Object
Reference to the error message.
-
.it(engine) ⇒ Object
Reference to it.
-
.root(engine) ⇒ 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?.
-
#expand_context ⇒ Object
Expand the context so we have the full path.
-
#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_context? ⇒ Boolean
Does the path start with the context?.
-
#includes_path? ⇒ Boolean
Does the value include a name?.
-
#initialize(engine, 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(engine, src) ⇒ Pn
Set up the object given a source string, ie: the full path and name.
23 24 25 26 |
# File 'lib/gloo/core/pn.rb', line 23 def initialize( engine, src ) @engine = engine set_to src end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
17 18 19 |
# File 'lib/gloo/core/pn.rb', line 17 def elements @elements end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
17 18 19 |
# File 'lib/gloo/core/pn.rb', line 17 def src @src end |
Class Method Details
.error(engine) ⇒ Object
Reference to the error message.
45 46 47 |
# File 'lib/gloo/core/pn.rb', line 45 def self.error( engine ) return Pn.new( engine, ERROR ) end |
Instance Method Details
#error? ⇒ Boolean
Does the pathname reference refer to error?
66 67 68 |
# File 'lib/gloo/core/pn.rb', line 66 def error? return @src.downcase == ERROR end |
#exists? ⇒ Boolean
Does the object at the path exist?
165 166 167 168 169 170 171 172 173 174 |
# File 'lib/gloo/core/pn.rb', line 165 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 |
#expand_context ⇒ Object
Expand the context so we have the full path.
138 139 140 141 |
# File 'lib/gloo/core/pn.rb', line 138 def # return unless @engine.heap.context self.set_to( "#{@engine.heap.context}#{@src[1..-1]}" ) end |
#get_parent ⇒ Object
Get the parent that contains the object referenced.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/gloo/core/pn.rb', line 146 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? @engine.err "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?
73 74 75 76 77 78 79 80 81 |
# File 'lib/gloo/core/pn.rb', line 73 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_context? ⇒ Boolean
Does the path start with the context?
131 132 133 |
# File 'lib/gloo/core/pn.rb', line 131 def includes_context? return @src.start_with?( "#{CONTEXT}." ) end |
#includes_path? ⇒ Boolean
Does the value include a name?
124 125 126 |
# File 'lib/gloo/core/pn.rb', line 124 def includes_path? return @elements.count > 1 end |
#it? ⇒ Boolean
Does the pathname reference refer to it?
59 60 61 |
# File 'lib/gloo/core/pn.rb', line 59 def it? return @src.downcase == IT end |
#name ⇒ Object
Get the name element.
108 109 110 111 112 |
# File 'lib/gloo/core/pn.rb', line 108 def name return '' unless self.named? return @elements.last end |
#named? ⇒ Boolean
Does the value include path elements?
117 118 119 |
# File 'lib/gloo/core/pn.rb', line 117 def named? return @elements.count.positive? end |
#named_color? ⇒ Boolean
Is the reference to a color?
179 180 181 182 |
# File 'lib/gloo/core/pn.rb', line 179 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.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/gloo/core/pn.rb', line 188 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( @engine, self ) if self.gloo_sys? if Here.includes_here_ref?( @elements ) Here.( @engine, self ) end if self.includes_context? end parent = self.get_parent return nil unless parent obj = parent.find_child( self.name ) return Gloo::Objs::Alias.resolve_alias( @engine, obj, self.src ) end |
#root? ⇒ Boolean
Does the pathname reference refer to the root?
52 53 54 |
# File 'lib/gloo/core/pn.rb', line 52 def root? return @src.downcase == ROOT end |
#segments ⇒ Object
Convert the raw string to a list of segments.
101 102 103 |
# File 'lib/gloo/core/pn.rb', line 101 def segments return @elements end |
#set_to(value) ⇒ Object
Set the object pathname to the given value.
93 94 95 96 |
# File 'lib/gloo/core/pn.rb', line 93 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.
86 87 88 |
# File 'lib/gloo/core/pn.rb', line 86 def to_s return @src end |