Class: LogSlice::SearchBoundary

Inherits:
Object
  • Object
show all
Defined in:
lib/log_slice/search_boundary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#cursorObject (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_backObject

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_forwardObject

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

#resetObject

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