Class: LogfileInterval::IntervalBuilder
- Inherits:
-
Object
- Object
- LogfileInterval::IntervalBuilder
- Defined in:
- lib/logfile_interval/interval_builder.rb,
lib/logfile_interval/interval_builder/ascending.rb,
lib/logfile_interval/interval_builder/descending.rb
Defined Under Namespace
Modules: Ascending, Descending
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#parsed_lines_enum ⇒ Object
readonly
Returns the value of attribute parsed_lines_enum.
-
#parser_columns ⇒ Object
readonly
Returns the value of attribute parser_columns.
Instance Method Summary collapse
- #each_interval {|current_interval| ... } ⇒ Object
- #end_boundary_time(t) ⇒ Object
- #first_interval ⇒ Object
-
#initialize(parsed_lines_enum, parser_columns, length, options = {}) ⇒ IntervalBuilder
constructor
A new instance of IntervalBuilder.
- #start_boundary_time(t) ⇒ Object
Constructor Details
#initialize(parsed_lines_enum, parser_columns, length, options = {}) ⇒ IntervalBuilder
Returns a new instance of IntervalBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/logfile_interval/interval_builder.rb', line 8 def initialize(parsed_lines_enum, parser_columns, length, = {}) @parsed_lines_enum = parsed_lines_enum @parser_columns = parser_columns @length = length raise ArgumentError if .include?(:boundary_offset) && .include?(:offset_by_start_time) @boundary_offset = .fetch(:boundary_offset, 0) offset_by_start_time = .fetch(:offset_by_start_time, nil) if offset_by_start_time @boundary_offset = offset_by_start_time.to_i % length end case order when :asc then self.extend Ascending when :desc then self.extend Descending when :empty then nil else raise ArgumentError, "Can't determine parsed_lines_enum sort order" end end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
6 7 8 |
# File 'lib/logfile_interval/interval_builder.rb', line 6 def length @length end |
#parsed_lines_enum ⇒ Object (readonly)
Returns the value of attribute parsed_lines_enum.
6 7 8 |
# File 'lib/logfile_interval/interval_builder.rb', line 6 def parsed_lines_enum @parsed_lines_enum end |
#parser_columns ⇒ Object (readonly)
Returns the value of attribute parser_columns.
6 7 8 |
# File 'lib/logfile_interval/interval_builder.rb', line 6 def parser_columns @parser_columns end |
Instance Method Details
#each_interval {|current_interval| ... } ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/logfile_interval/interval_builder.rb', line 29 def each_interval(&block) return enum_for(:each_interval) unless block_given? return if order == :empty current_interval = create_first_interval parsed_lines_enum.each do |record| next if out_of_order_record?(current_interval, record) current_interval = move_over_empty_intervals(current_interval, record) { |interval| yield interval } current_interval.add_record(record) end yield current_interval if current_interval.size > 0 end |
#end_boundary_time(t) ⇒ Object
53 54 55 56 |
# File 'lib/logfile_interval/interval_builder.rb', line 53 def end_boundary_time(t) secs = ((t.to_i - @boundary_offset)/ length.to_i + 1) * length.to_i + @boundary_offset Time.at(secs) end |
#first_interval ⇒ Object
44 45 46 |
# File 'lib/logfile_interval/interval_builder.rb', line 44 def first_interval each_interval.first end |
#start_boundary_time(t) ⇒ Object
48 49 50 51 |
# File 'lib/logfile_interval/interval_builder.rb', line 48 def start_boundary_time(t) secs = ((t.to_i - @boundary_offset) / length.to_i) * length.to_i + @boundary_offset Time.at(secs) end |