Class: LogTimer::Log
- Inherits:
-
Object
- Object
- LogTimer::Log
- Defined in:
- lib/log_timer/log.rb
Overview
Represents a log file
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Log
constructor
A new instance of Log.
- #modification_date ⇒ Object
-
#older?(reference_time) ⇒ Boolean
Checks if the log file is older than the given datetime.
-
#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.
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
#path ⇒ Object
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_date ⇒ Object
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
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 |