Class: Gloo::Core::Pn
Constant Summary collapse
- ROOT =
'root'.freeze
- IT =
'it'.freeze
- ERROR =
'error'.freeze
- CONTEXT =
'@'.freeze
- NAMED_COLORS =
%w[red blue green white black yellow].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.
24 25 26 27 |
# File 'lib/gloo/core/pn.rb', line 24 def initialize( engine, src ) @engine = engine set_to src end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
18 19 20 |
# File 'lib/gloo/core/pn.rb', line 18 def elements @elements end |
#src ⇒ Object (readonly)
Returns the value of attribute src.
18 19 20 |
# File 'lib/gloo/core/pn.rb', line 18 def src @src end |
Class Method Details
.error(engine) ⇒ Object
Reference to the error message.
46 47 48 |
# File 'lib/gloo/core/pn.rb', line 46 def self.error( engine ) return Pn.new( engine, ERROR ) end |
Instance Method Details
#error? ⇒ Boolean
Does the pathname reference refer to error?
67 68 69 |
# File 'lib/gloo/core/pn.rb', line 67 def error? return @src.downcase == ERROR end |
#exists? ⇒ Boolean
Does the object at the path exist?
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/gloo/core/pn.rb', line 166 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.
139 140 141 142 |
# File 'lib/gloo/core/pn.rb', line 139 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.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gloo/core/pn.rb', line 147 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?
74 75 76 77 78 79 80 81 82 |
# File 'lib/gloo/core/pn.rb', line 74 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?
132 133 134 |
# File 'lib/gloo/core/pn.rb', line 132 def includes_context? return @src.start_with?( "#{CONTEXT}." ) end |
#includes_path? ⇒ Boolean
Does the value include a name?
125 126 127 |
# File 'lib/gloo/core/pn.rb', line 125 def includes_path? return @elements.count > 1 end |
#it? ⇒ Boolean
Does the pathname reference refer to it?
60 61 62 |
# File 'lib/gloo/core/pn.rb', line 60 def it? return @src.downcase == IT end |
#name ⇒ Object
Get the name element.
109 110 111 112 113 |
# File 'lib/gloo/core/pn.rb', line 109 def name return '' unless self.named? return @elements.last end |
#named? ⇒ Boolean
Does the value include path elements?
118 119 120 |
# File 'lib/gloo/core/pn.rb', line 118 def named? return @elements.count.positive? end |
#named_color? ⇒ Boolean
Is the reference to a color?
180 181 182 183 184 |
# File 'lib/gloo/core/pn.rb', line 180 def named_color? return true if NAMED_COLORS.include?( @src.downcase ) return false end |
#resolve ⇒ Object
Resolve the pathname reference. Find the object referenced or return nil if it is not found.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/gloo/core/pn.rb', line 190 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?
53 54 55 |
# File 'lib/gloo/core/pn.rb', line 53 def root? return @src.downcase == ROOT end |
#segments ⇒ Object
Convert the raw string to a list of segments.
102 103 104 |
# File 'lib/gloo/core/pn.rb', line 102 def segments return @elements end |
#set_to(value) ⇒ Object
Set the object pathname to the given value.
94 95 96 97 |
# File 'lib/gloo/core/pn.rb', line 94 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.
87 88 89 |
# File 'lib/gloo/core/pn.rb', line 87 def to_s return @src end |