Class: LogTimer::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/log_timer/log.rb

Overview

Represents a log file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Log

Returns a new instance of Log.



6
7
8
# File 'lib/log_timer/log.rb', line 6

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/log_timer/log.rb', line 4

def path
  @path
end

Instance Method Details

#modification_dateObject



10
11
12
# File 'lib/log_timer/log.rb', line 10

def modification_date
  File.mtime(@path)
end

#older?(reference_time) ⇒ Boolean

Checks if the log file is older than the given datetime

Returns:

  • (Boolean)


15
16
17
# File 'lib/log_timer/log.rb', line 15

def older?(reference_time)
  File.mtime(@path) < reference_time
end

#tail(lines = 10) ⇒ Object

Returns the last n lines from the log file Implementing this directly in Ruby is annoyingly complicated (and/or slow) it seems



21
22
23
# File 'lib/log_timer/log.rb', line 21

def tail(lines = 10)
  `tail -n #{lines} #{@path}`.split("\n")
end