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 17 |
# File 'lib/logfile_interval/interval.rb', line 8 def initialize(end_time, length, parser_columns) raise ArgumentError, 'end_time must be round' unless (end_time.to_i % length.to_i == 0) @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
19 20 21 |
# File 'lib/logfile_interval/interval.rb', line 19 def [](name) @aggregators[name] end |
#add_record(record) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/logfile_interval/interval.rb', line 27 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
23 24 25 |
# File 'lib/logfile_interval/interval.rb', line 23 def to_hash @aggregators.to_hash end |