Class: Avmtrf1::Openvpn::Config::Parser::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/avmtrf1/openvpn/config/parser/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

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

#simpleObject (readonly)

Returns the value of attribute simple.


12
13
14
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 12

def simple
  @simple
end

#tagsObject (readonly)

Returns the value of attribute tags.


12
13
14
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 12

def tags
  @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?
    tags << ::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_tagObject


51
52
53
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 51

def current_tag
  tags.last
end

#on_tag?Boolean

Returns:

  • (Boolean)

55
56
57
# File 'lib/avmtrf1/openvpn/config/parser/builder.rb', line 55

def on_tag?
  tags.last.if_present(false, &:open?)
end