Class: LazyGraph::PathParser::Path
- Inherits:
-
Struct
- Object
- Struct
- LazyGraph::PathParser::Path
- 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
-
#parts ⇒ Object
Returns the value of attribute parts.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #identity ⇒ Object
- #index? ⇒ Boolean
- #map(&block) ⇒ Object
- #merge(other) ⇒ Object
- #next ⇒ Object
- #segment ⇒ Object
- #shifted_id ⇒ Object
- #to_path_str ⇒ Object
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts
10 11 12 |
# File 'lib/lazy_graph/path_parser/path.rb', line 10 def parts @parts end |
Instance Method Details
#empty? ⇒ Boolean
12 |
# File 'lib/lazy_graph/path_parser/path.rb', line 12 def empty? = @empty ||= parts.empty? |
#identity ⇒ Object
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
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 |
#next ⇒ Object
11 |
# File 'lib/lazy_graph/path_parser/path.rb', line 11 def next = @next ||= parts.length <= 1 ? Path::BLANK : Path.new(parts: parts[1..]) |
#segment ⇒ Object
13 |
# File 'lib/lazy_graph/path_parser/path.rb', line 13 def segment = @segment ||= parts&.[](0) |
#shifted_id ⇒ Object
17 |
# File 'lib/lazy_graph/path_parser/path.rb', line 17 def shifted_id = @shifted_id ||= object_id << 28 |
#to_path_str ⇒ Object
28 29 30 |
# File 'lib/lazy_graph/path_parser/path.rb', line 28 def to_path_str @to_path_str ||= create_path_str end |