Class: LogFinder
- Inherits:
-
Object
- Object
- LogFinder
- Defined in:
- lib/log_finder.rb,
lib/log_finder/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filename, read_length, number_of_lines) ⇒ LogFinder
constructor
A new instance of LogFinder.
- #search_by(regexp) ⇒ Object
Constructor Details
#initialize(filename, read_length, number_of_lines) ⇒ LogFinder
Returns a new instance of LogFinder.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/log_finder.rb', line 5 def initialize( filename , read_length , number_of_lines ) raise unless filename.instance_of?( ::String ) raise unless read_length.integer? @filename = filename @read_length = read_length @number_of_lines = number_of_lines @search_by = nil set_array end |
Class Method Details
.search_by(regexp, filename, read_length: 256 * 1024, number_of_lines: nil) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/log_finder.rb', line 40 def self.search_by( regexp , filename , read_length: 256 * 1024 , number_of_lines: nil ) self.new( filename , read_length , number_of_lines ).search_by( regexp ) end |
Instance Method Details
#search_by(regexp) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/log_finder.rb', line 16 def search_by( regexp ) raise unless regexp.instance_of?( ::String ) or regexp.instance_of?( ::Regexp ) @search_by = regexp n = row_number unless n.nil? from_n = Math.max( 0 , n - 10 ) to_n = Math.min( n + 100 , @ary.length ) unless from_n == n puts @ary[ from_n..( n - 1 ) ] puts "" end puts @ary[n] unless to_n == n puts "" puts @ary[ ( n + 1 )..to_n ] end puts "" puts "=" * 64 puts "displayed from \##{ from_n } to \##{ to_n }" else puts "No row matched with #{ @search_by.inspect }" end end |