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

#empty?Boolean

Returns:

  • (Boolean)


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

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

#identityObject



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

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

#index?Boolean

Returns:

  • (Boolean)


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

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

#map(&block) ⇒ Object



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

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

#merge(other) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/lazy_graph/path_parser/path.rb', line 19

def merge(other)
  (@merged ||= {})[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



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

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

#shifted_idObject



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

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

#to_path_strObject



28
29
30
# File 'lib/lazy_graph/path_parser/path.rb', line 28

def to_path_str
  @to_path_str ||= create_path_str
end