Class: BigIParse::Config::Section
- Inherits:
-
Object
- Object
- BigIParse::Config::Section
- Defined in:
- lib/bigip_parse/config.rb
Overview
Class to represent a section of a config file
Constant Summary collapse
- REGEX =
/ ^(?<header>([^\s{}#]+[ ]?)+) # Header definition ({ # Opening bracket (?<content>( # Optional content capture everything [^\n]*(?=\s}) # not a new-line followed by space bracket | # OR .*?(?=^}) # everything then closing bracket ) ) )? # Make content capture optional /mx
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(header, content = nil) ⇒ Section
constructor
A new instance of Section.
- #subsections ⇒ Object
- #subsections? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(header, content = nil) ⇒ Section
Returns a new instance of Section.
22 23 24 25 |
# File 'lib/bigip_parse/config.rb', line 22 def initialize(header, content = nil) @header = header @content = content end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
8 9 10 |
# File 'lib/bigip_parse/config.rb', line 8 def header @header end |
Instance Method Details
#content ⇒ Object
27 28 29 30 31 |
# File 'lib/bigip_parse/config.rb', line 27 def content return nil if @content.nil? return nil if @content.strip.empty? @content.strip_heredoc.lstrip end |
#subsections ⇒ Object
37 38 39 40 |
# File 'lib/bigip_parse/config.rb', line 37 def subsections return [] if content.nil? content.scan(REGEX).map { |h, c| self.class.new(h.strip, c) } end |
#subsections? ⇒ Boolean
33 34 35 |
# File 'lib/bigip_parse/config.rb', line 33 def subsections? !content.nil? end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/bigip_parse/config.rb', line 42 def to_s "#{self.class.name}(header=#{header}, content=#{content})" end |