Class: Proteus::Modules::DefaultsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/proteus/modules/defaults_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ DefaultsParser

Returns a new instance of DefaultsParser.



6
7
8
9
# File 'lib/proteus/modules/defaults_parser.rb', line 6

def initialize(input)
  @hcl = input
  @variables = {}
end

Instance Attribute Details

#variablesObject (readonly)

Returns the value of attribute variables.



4
5
6
# File 'lib/proteus/modules/defaults_parser.rb', line 4

def variables
  @variables
end

Instance Method Details

#parse_variablesObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/proteus/modules/defaults_parser.rb', line 11

def parse_variables
  lines = @hcl.split("\n")
  lines.reject! { |l| l.start_with?("#") }

  lines.each_with_index do |line, index|
    if line =~ /^variable/
      # ignore mandatory variables
      if line =~ /{/ && line =~ /}/
        next
      end

      variable_lines = find_variable_range(lines, index)

      if variable_lines && variable_lines.any?
        variable = evaluate_variable(variable_lines)

        @variables.merge!({variable[:name] => variable[:value]}) unless variable.nil?
      end
    end
  end
end