Class: HaproxyParser::Sections::Base
- Inherits:
-
Object
- Object
- HaproxyParser::Sections::Base
- Defined in:
- lib/haproxy_parser/sections/base.rb
Instance Attribute Summary collapse
-
#attr_lines ⇒ Object
readonly
Returns the value of attribute attr_lines.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #attr_value(line) ⇒ Object
-
#initialize(lines) ⇒ Base
constructor
A new instance of Base.
- #items ⇒ Object
Constructor Details
#initialize(lines) ⇒ Base
Returns a new instance of Base.
8 9 10 11 |
# File 'lib/haproxy_parser/sections/base.rb', line 8 def initialize(lines) @name = lines[0][1] @attr_lines = lines[1..-1] end |
Instance Attribute Details
#attr_lines ⇒ Object (readonly)
Returns the value of attribute attr_lines.
7 8 9 |
# File 'lib/haproxy_parser/sections/base.rb', line 7 def attr_lines @attr_lines end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/haproxy_parser/sections/base.rb', line 7 def name @name end |
Instance Method Details
#attr_value(line) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/haproxy_parser/sections/base.rb', line 33 def attr_value(line) case line.size when 1 "" when 2 line[1] else line[1..-1] end end |
#items ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/haproxy_parser/sections/base.rb', line 13 def items @items ||= {}.tap do |data| counter = {} attr_lines.each do |line| if data.key?(line[0]) if 1 == counter[line[0]] data[line[0]] = [] << data[line[0]] << attr_value(line) else data[line[0]] << attr_value(line) end else data[line[0]] = attr_value(line) end counter[line[0]] ? counter[line[0]] += 1 : counter[line[0]] = 1 end data[:name] = name break data end end |