Class: LogfileInterval::Logfile
- Inherits:
-
Object
- Object
- LogfileInterval::Logfile
- Defined in:
- lib/logfile_interval/logfile.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #each_line ⇒ Object
- #each_parsed_line ⇒ Object
- #exist? ⇒ Boolean
- #first_timestamp ⇒ Object
-
#initialize(filename, parser) ⇒ Logfile
constructor
A new instance of Logfile.
Constructor Details
#initialize(filename, parser) ⇒ Logfile
Returns a new instance of Logfile.
5 6 7 8 |
# File 'lib/logfile_interval/logfile.rb', line 5 def initialize(filename, parser) @filename = filename @parser = parser end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/logfile_interval/logfile.rb', line 3 def filename @filename end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
3 4 5 |
# File 'lib/logfile_interval/logfile.rb', line 3 def parser @parser end |
Instance Method Details
#each_line ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logfile_interval/logfile.rb', line 25 def each_line return unless exist? return enum_for(:each_line) unless block_given? f = Util::FileBackward.new(@filename) while(line = f.gets) yield line.chomp end f.close end |
#each_parsed_line ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/logfile_interval/logfile.rb', line 36 def each_parsed_line return enum_for(:each_parsed_line) unless block_given? each_line do |line| record = parser.create_record(line) yield record if record end end |
#exist? ⇒ Boolean
10 11 12 |
# File 'lib/logfile_interval/logfile.rb', line 10 def exist? filename && File.exist?(@filename) end |
#first_timestamp ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/logfile_interval/logfile.rb', line 14 def return unless exist? File.open(@filename) do |f| while line = f.gets if record = parser.create_record(line) return record.time end end end end |