class Confmake::BashParser

Public Class Methods

parse(text) click to toggle source
# File lib/confmake/bash_parser.rb, line 13
def self.parse text
  parsed_text = text
  parsed_text = parse_as_array text if text.start_with? "["
  parsed_text = parse_as_object text if text.start_with? "{"
  parsed_text
end
parse_user_input(user_input) click to toggle source
# File lib/confmake/bash_parser.rb, line 5
def self.parse_user_input user_input
  parsed_input = {}
  user_input.each { |k,v|
    parsed_input[k.to_s] = self.parse v
  }
  parsed_input
end

Private Class Methods

parse_as_array(text) click to toggle source
# File lib/confmake/bash_parser.rb, line 21
def self.parse_as_array text
  parse_as_json_string text
end
parse_as_json_string(text) click to toggle source
# File lib/confmake/bash_parser.rb, line 29
def self.parse_as_json_string text
  begin
    return JSON.parse text
  rescue JSON::ParserError
    return text
  end
end
parse_as_object(text) click to toggle source
# File lib/confmake/bash_parser.rb, line 25
def self.parse_as_object text
  parse_as_json_string text
end