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
- #==(other) ⇒ Object
- #absolute? ⇒ Boolean
- #empty? ⇒ Boolean
- #first_path_segment ⇒ Object
- #identity ⇒ Object
- #index? ⇒ Boolean
- #length ⇒ Object
- #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
#==(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
15 |
# File 'lib/lazy_graph/path_parser/path.rb', line 15 def absolute? = instance_variable_defined?(:@absolute) ? @absolute : (@absolute = segment&.part.equal?(:'$')) |
#empty? ⇒ Boolean
12 |
# File 'lib/lazy_graph/path_parser/path.rb', line 12 def empty? = @empty ||= parts.empty? |
#first_path_segment ⇒ Object
20 |
# File 'lib/lazy_graph/path_parser/path.rb', line 20 def first_path_segment = @first_path_segment ||= absolute? ? self.next.segment : segment |
#identity ⇒ Object
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
16 |
# File 'lib/lazy_graph/path_parser/path.rb', line 16 def index? = @index ||= !empty? && segment&.index? |
#length ⇒ Object
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 |
#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
14 |
# File 'lib/lazy_graph/path_parser/path.rb', line 14 def segment = @segment ||= parts&.[](0) |
#shifted_id ⇒ Object
19 |
# File 'lib/lazy_graph/path_parser/path.rb', line 19 def shifted_id = @shifted_id ||= object_id << 28 |
#to_path_str ⇒ Object
30 31 32 |
# File 'lib/lazy_graph/path_parser/path.rb', line 30 def to_path_str @to_path_str ||= create_path_str end |