Class: Ifconf::Parsers::RawBlock

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

Overview

Represents a single interface block of raw ifconfig text with its starting line number.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_line, lines) ⇒ RawBlock

Returns a new instance of RawBlock.



7
8
9
10
11
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 7

def initialize(start_line, lines)
  @start_line = start_line
  @lines = lines.freeze
  freeze
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



5
6
7
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 5

def lines
  @lines
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



5
6
7
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 5

def start_line
  @start_line
end

Instance Method Details

#body_linesObject



21
22
23
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 21

def body_lines
  @lines[1..]
end

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 33

def empty?
  @lines.empty?
end

#find_line(pattern) ⇒ Object



25
26
27
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 25

def find_line(pattern)
  @lines.find { |l| l.match?(pattern) }
end

#find_lines(pattern) ⇒ Object



29
30
31
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 29

def find_lines(pattern)
  @lines.grep(pattern)
end

#header_lineObject



17
18
19
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 17

def header_line
  @lines.first
end

#rawObject



13
14
15
# File 'lib/ifconf/parsers/raw_text_splitter.rb', line 13

def raw
  @lines.join("\n")
end