Class: ErlangConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/utils/erlang_parser.rb

Class Method Summary collapse

Class Method Details

.parse(content) ⇒ Object



177
178
179
180
181
# File 'lib/inspec/utils/erlang_parser.rb', line 177

def self.parse(content)
  lex = ErlangParser.new.parse(content)
  tree = ErlangTransform.new.apply(lex)
  turn_to_hash(tree)
end

.turn_to_hash(t) ⇒ Object



183
184
185
186
187
188
189
# File 'lib/inspec/utils/erlang_parser.rb', line 183

def self.turn_to_hash(t)
  if t.is_a?(Array) && t.all? { |x| x.class == ErlangTransform::Tuple && x.length == 2 }
    Hash[t.map { |i| [i[0], turn_to_hash(i[1])] }]
  else
    t
  end
end