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
- #first_interval ⇒ Object
-
#initialize(parsed_lines_enum, parser_columns, length) ⇒ IntervalBuilder
constructor
A new instance of IntervalBuilder.
Constructor Details
#initialize(parsed_lines_enum, parser_columns, length) ⇒ IntervalBuilder
Returns a new instance of IntervalBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 |
# 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 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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/logfile_interval/interval_builder.rb', line 21 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 |
#first_interval ⇒ Object
36 37 38 |
# File 'lib/logfile_interval/interval_builder.rb', line 36 def first_interval each_interval.first end |