Class: TermUtils::FF::Cursor

Inherits:
Object
  • Object
show all
Defined in:
lib/term_utils/ff/cursor.rb

Overview

Represents a query cursor.

Defined Under Namespace

Classes: Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, path) ⇒ Cursor

Returns a new instance of Cursor.

Parameters:



29
30
31
32
33
34
35
# File 'lib/term_utils/ff/cursor.rb', line 29

def initialize(config, path)
  @config = config
  @path = path
  @contexts = []
  push_context(path)
  @index = 0
end

Instance Attribute Details

#indexInteger (readonly)

Returns:

  • (Integer)


26
27
28
# File 'lib/term_utils/ff/cursor.rb', line 26

def index
  @index
end

Instance Method Details

#bootstrapTermUtils::FF::Cursor?

Starts the query.

Returns:



38
39
40
41
42
43
44
45
46
47
# File 'lib/term_utils/ff/cursor.rb', line 38

def bootstrap
  res = self
  if @config.min_depth
    while depth < @config.min_depth
      res = following0
      break unless res
    end
  end
  res
end

#componentsArray<String>

Returns the path components.

Returns:

  • (Array<String>)


85
86
87
# File 'lib/term_utils/ff/cursor.rb', line 85

def components
  @contexts.last.components.dup
end

#depthInteger

Returns:

  • (Integer)


72
73
74
# File 'lib/term_utils/ff/cursor.rb', line 72

def depth
  @contexts.last.components.length
end

#followingTermUtils::FF::Cursor?

Returns the next cursor.

Returns:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/term_utils/ff/cursor.rb', line 50

def following
  res = nil
  loop do
    res = following0
    break unless res
    if @config.min_depth
      next if depth < @config.min_depth
    end
    if @config.max_depth
      next if depth > @config.max_depth
    end
    @index += 1
    break
  end
  res
end

#nameString

Returns:

  • (String)


80
81
82
# File 'lib/term_utils/ff/cursor.rb', line 80

def name
  @contexts.last.components[-1]
end

#relative_pathString

Returns:

  • (String)


76
77
78
# File 'lib/term_utils/ff/cursor.rb', line 76

def relative_path
  @contexts.last.components.join("/")
end

#resultString

Returns the result associated to this one.

Returns:

  • (String)


68
69
70
# File 'lib/term_utils/ff/cursor.rb', line 68

def result
  @contexts.last.path
end