Class: Ifconf::Parsers::BlockAccumulator

Inherits:
Object
  • Object
show all
Defined in:
lib/ifconf/parsers/raw_text_splitter.rb

Overview

Accumulates lines into RawBlock instances during ifconfig text splitting.

Instance Method Summary collapse

Constructor Details

#initializeBlockAccumulator

Returns a new instance of BlockAccumulator.



57
58
59
60
61
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 57

def initialize
  @blocks = []
  @current_lines = []
  @current_start = nil
end

Instance Method Details

#finalizeObject



73
74
75
76
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 73

def finalize
  flush_current_block
  @blocks
end

#process_line(line, idx) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 63

def process_line(line, idx)
  if line.strip.empty?
    flush_current_block
  elsif /\A\S/.match?(line)
    start_new_block(line, idx)
  elsif !@current_lines.empty?
    @current_lines << line
  end
end