Class: LogSlice::SearchBoundary
- Inherits:
-
Object
- Object
- LogSlice::SearchBoundary
- Defined in:
- lib/log_slice/search_boundary.rb
Instance Attribute Summary collapse
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
Instance Method Summary collapse
-
#cursor_back ⇒ Object
Move cursor backward.
-
#cursor_forward ⇒ Object
Move cursor forward.
-
#initialize(file_size) ⇒ SearchBoundary
constructor
A new instance of SearchBoundary.
-
#reset ⇒ Object
reset the search boundary to cover the entire file.
Constructor Details
#initialize(file_size) ⇒ SearchBoundary
Returns a new instance of SearchBoundary.
6 7 8 |
# File 'lib/log_slice/search_boundary.rb', line 6 def initialize file_size @file_size = file_size end |
Instance Attribute Details
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
4 5 6 |
# File 'lib/log_slice/search_boundary.rb', line 4 def cursor @cursor end |
Instance Method Details
#cursor_back ⇒ Object
Move cursor backward. The cursor is moved half way between it’s start location and the lower boundary.
28 29 30 31 |
# File 'lib/log_slice/search_boundary.rb', line 28 def cursor_back @upper = @cursor @cursor = @cursor - (@cursor - @lower) / 2 end |
#cursor_forward ⇒ Object
Move cursor forward. The cursor is moved half way between it’s start location and the upper boundary.
21 22 23 24 |
# File 'lib/log_slice/search_boundary.rb', line 21 def cursor_forward @lower = @cursor @cursor = @cursor + (@upper - @cursor) / 2 end |
#reset ⇒ Object
reset the search boundary to cover the entire file
11 12 13 14 15 16 17 |
# File 'lib/log_slice/search_boundary.rb', line 11 def reset @lower = 0 @upper = @file_size @cursor = 0 cursor_forward self end |