Class: LazyGraph::PathParser::Path

Inherits:
Struct
  • Object
show all
Defined in:
lib/lazy_graph/path_parser/path.rb

Overview

Path represents a structured component of a complex path string. It provides methods to navigate and manipulate the path parts.

Constant Summary collapse

BLANK =
Path.new(parts: [])

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject

Returns the value of attribute parts

Returns:

  • (Object)

    the current value of parts



10
11
12
# File 'lib/lazy_graph/path_parser/path.rb', line 10

def parts
  @parts
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
# File 'lib/lazy_graph/path_parser/path.rb', line 34

def ==(other)
  return parts == other if other.is_a?(Array)

  super
end

#absolute?Boolean

Returns:

  • (Boolean)


15
# File 'lib/lazy_graph/path_parser/path.rb', line 15

def absolute?   = instance_variable_defined?(:@absolute) ? @absolute : (@absolute = segment&.part.equal?(:'$'))

#empty?Boolean

Returns:

  • (Boolean)


12
# File 'lib/lazy_graph/path_parser/path.rb', line 12

def empty?      = @empty ||= parts.empty?

#first_path_segmentObject



20
# File 'lib/lazy_graph/path_parser/path.rb', line 20

def first_path_segment = @first_path_segment ||= absolute? ? self.next.segment : segment

#identityObject



17
# File 'lib/lazy_graph/path_parser/path.rb', line 17

def identity    = @identity ||= parts&.each_with_index&.reduce(0) { |acc, (p, i)| acc ^ (p.object_id) << (i * 8) }

#index?Boolean

Returns:

  • (Boolean)


16
# File 'lib/lazy_graph/path_parser/path.rb', line 16

def index?      = @index ||= !empty? && segment&.index?

#lengthObject



13
# File 'lib/lazy_graph/path_parser/path.rb', line 13

def length      = @length ||= parts.length

#map(&block) ⇒ Object



18
# File 'lib/lazy_graph/path_parser/path.rb', line 18

def map(&block) = empty? ? self : Path.new(parts: parts.map(&block))

#merge(other) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/lazy_graph/path_parser/path.rb', line 22

def merge(other)
  if other.empty?
    self
  else
    empty? ? other : Path.new(parts: parts + other.parts)
  end
end

#nextObject



11
# File 'lib/lazy_graph/path_parser/path.rb', line 11

def next        = @next ||= parts.length <= 1 ? Path::BLANK : Path.new(parts: parts[1..])

#segmentObject



14
# File 'lib/lazy_graph/path_parser/path.rb', line 14

def segment     = @segment ||= parts&.[](0)

#shifted_idObject



19
# File 'lib/lazy_graph/path_parser/path.rb', line 19

def shifted_id  = @shifted_id ||= object_id << 28

#to_path_strObject



30
31
32
# File 'lib/lazy_graph/path_parser/path.rb', line 30

def to_path_str
  @to_path_str ||= create_path_str
end