Class: LogfileInterval::Interval
- Inherits:
-
Object
- Object
- LogfileInterval::Interval
- Defined in:
- lib/logfile_interval/interval.rb
Defined Under Namespace
Classes: OutOfRange
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #add_record(record) ⇒ Object
-
#initialize(end_time, length, parser_columns) ⇒ Interval
constructor
A new instance of Interval.
- #to_hash ⇒ Object
Constructor Details
#initialize(end_time, length, parser_columns) ⇒ Interval
Returns a new instance of Interval.
8 9 10 11 12 13 14 15 16 |
# File 'lib/logfile_interval/interval.rb', line 8 def initialize(end_time, length, parser_columns) @end_time = end_time @start_time = end_time - length @length = length @parser = parser @size = 0 @aggregators = AggregatorSet.new(parser_columns) end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
3 4 5 |
# File 'lib/logfile_interval/interval.rb', line 3 def end_time @end_time end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
3 4 5 |
# File 'lib/logfile_interval/interval.rb', line 3 def length @length end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
3 4 5 |
# File 'lib/logfile_interval/interval.rb', line 3 def parser @parser end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/logfile_interval/interval.rb', line 4 def size @size end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/logfile_interval/interval.rb', line 3 def start_time @start_time end |
Instance Method Details
#[](name) ⇒ Object
18 19 20 |
# File 'lib/logfile_interval/interval.rb', line 18 def [](name) @aggregators[name] end |
#add_record(record) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/logfile_interval/interval.rb', line 29 def add_record(record) raise OutOfRange, 'too recent' if record.time>@end_time raise OutOfRange, 'too old' if record.time<=@start_time @size += 1 @aggregators.add(record) end |
#to_hash ⇒ Object
22 23 24 25 26 27 |
# File 'lib/logfile_interval/interval.rb', line 22 def to_hash h = @aggregators.to_hash h[:start_time] = self.start_time h[:end_time] = self.end_time h end |