Class: TermUtils::FF::Cursor
- Inherits:
-
Object
- Object
- TermUtils::FF::Cursor
- Defined in:
- lib/term_utils/ff/cursor.rb
Overview
Represents a query cursor.
Defined Under Namespace
Classes: Context
Instance Attribute Summary collapse
- #index ⇒ Integer readonly
Instance Method Summary collapse
-
#bootstrap ⇒ TermUtils::FF::Cursor?
Starts the query.
-
#components ⇒ Array<String>
Returns the path components.
- #depth ⇒ Integer
-
#following ⇒ TermUtils::FF::Cursor?
Returns the next cursor.
-
#initialize(config, path) ⇒ Cursor
constructor
A new instance of Cursor.
- #name ⇒ String
- #relative_path ⇒ String
-
#result ⇒ String
Returns the result associated to this one.
Constructor Details
#initialize(config, path) ⇒ Cursor
Returns a new instance of Cursor
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
#index ⇒ Integer (readonly)
26 27 28 |
# File 'lib/term_utils/ff/cursor.rb', line 26 def index @index end |
Instance Method Details
#bootstrap ⇒ TermUtils::FF::Cursor?
Starts the query.
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 |
#components ⇒ Array<String>
Returns the path components.
85 86 87 |
# File 'lib/term_utils/ff/cursor.rb', line 85 def components @contexts.last.components.dup end |
#depth ⇒ Integer
72 73 74 |
# File 'lib/term_utils/ff/cursor.rb', line 72 def depth @contexts.last.components.length end |
#following ⇒ TermUtils::FF::Cursor?
Returns the next cursor.
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 |
#name ⇒ String
80 81 82 |
# File 'lib/term_utils/ff/cursor.rb', line 80 def name @contexts.last.components[-1] end |
#relative_path ⇒ String
76 77 78 |
# File 'lib/term_utils/ff/cursor.rb', line 76 def relative_path @contexts.last.components.join("/") end |
#result ⇒ String
Returns the result associated to this one.
68 69 70 |
# File 'lib/term_utils/ff/cursor.rb', line 68 def result @contexts.last.path end |