Class: Avmtrf1::Openvpn::Config::Parser::Builder
- Inherits:
-
Object
- Object
- Avmtrf1::Openvpn::Config::Parser::Builder
- Defined in:
- lib/avmtrf1/openvpn/config/parser/builder.rb
Instance Attribute Summary collapse
-
#simple ⇒ Object
readonly
Returns the value of attribute simple.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
- #add_line(line_text) ⇒ Object
- #add_line_not_on_tag(line) ⇒ Object
- #add_line_on_tag(line) ⇒ Object
- #current_tag ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
- #on_tag? ⇒ Boolean
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
14 15 16 17 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 14 def initialize @simple = [] @tags = [] end |
Instance Attribute Details
#simple ⇒ Object (readonly)
Returns the value of attribute simple.
12 13 14 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 12 def simple @simple end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
12 13 14 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 12 def @tags end |
Instance Method Details
#add_line(line_text) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 19 def add_line(line_text) line = ::Avmtrf1::Openvpn::Config::Parser::Line.new(line_text) if on_tag? add_line_on_tag(line) else add_line_not_on_tag(line) end end |
#add_line_not_on_tag(line) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 41 def add_line_not_on_tag(line) return if line.blank_text? if line.open_tag? << ::Avmtrf1::Openvpn::Config::Parser::Tag.new(line.tag_name) else simple << ::Avmtrf1::Openvpn::Config::Parser::Simple.new(line.simple_parts) end end |
#add_line_on_tag(line) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 28 def add_line_on_tag(line) if line.close_tag? if line.tag_name != current_tag.name raise("Closing tag \"#{line.tag_name}\" does not match current tag " \ "\"#{current_tag}\"") end current_tag.close else current_tag.add_line(line.text) end end |
#current_tag ⇒ Object
51 52 53 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 51 def current_tag .last end |
#on_tag? ⇒ Boolean
55 56 57 |
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 55 def on_tag? .last.if_present(false, &:open?) end |