Class: LogSlice::DateRange
- Inherits:
-
Object
- Object
- LogSlice::DateRange
- Defined in:
- lib/log_slice/date_range.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(file, start_date, end_date = nil) ⇒ DateRange
constructor
A new instance of DateRange.
Constructor Details
#initialize(file, start_date, end_date = nil) ⇒ DateRange
Returns a new instance of DateRange.
9 10 11 12 13 |
# File 'lib/log_slice/date_range.rb', line 9 def initialize file, start_date, end_date=nil @file = file @start_date = start_date.is_a?(DateTime) ? start_date : DateTime.parse(start_date) @end_date = (end_date.is_a?(DateTime) || end_date.nil?) ? end_date : DateTime.parse(end_date) end |
Instance Method Details
#each ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/log_slice/date_range.rb', line 15 def each file = LogSlice.new(@file).find do |line| date_compare @start_date, line end begin line = file.readline if @end_date.nil? || date_compare(@end_date, line) == 1 yield line else break end end until file.eof? end |