Class: ReadLog
- Inherits:
-
Object
- Object
- ReadLog
- Defined in:
- lib/roma/tools/log_merger.rb
Instance Method Summary collapse
- #get_date ⇒ Object
- #get_line ⇒ Object
-
#initialize(fn) ⇒ ReadLog
constructor
A new instance of ReadLog.
- #match_line(l) ⇒ Object
- #read_line ⇒ Object
Constructor Details
#initialize(fn) ⇒ ReadLog
Returns a new instance of ReadLog.
5 6 7 8 9 10 |
# File 'lib/roma/tools/log_merger.rb', line 5 def initialize(fn) @f = open(fn) @buff = '' @prev = @f.gets @s_date = '' end |
Instance Method Details
#get_date ⇒ Object
38 39 40 |
# File 'lib/roma/tools/log_merger.rb', line 38 def get_date @s_date end |
#get_line ⇒ Object
34 35 36 |
# File 'lib/roma/tools/log_merger.rb', line 34 def get_line @buff end |
#match_line(l) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/roma/tools/log_merger.rb', line 42 def match_line(l) if /^[TDIWEFU],\s\[(\d{4})\-(\d{2})\-(\d{2})T(\d{2}):(\d{2}):(\d{2})\.(\d+)\s#\d+\].+/ =~ l then @s_date = $1 << $2 << $3 << $4 << $5 << $6 << $7 true else @s_date = nil false end end |
#read_line ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/roma/tools/log_merger.rb', line 12 def read_line begin if /^#\sLogfile\screated\son.+/ =~ @prev then @prev = @f.gets end @buff = @prev @prev = @f.gets while !(match_line(@prev)) && !(@prev.nil?) do @buff << @prev @prev = @f.gets end match_line(@buff) rescue unless @f.closed? @f.close end end end |