module PicsolveDockerBuilder module Helpers module Config # represents a config string that contains variables class VariableObject # Regex that finds variabales def self.regex_full /^\$\{([^\}]*)\}$/ end def self.regex /\$\{[^\}]*\}/ end # Checks if a string needs to be replaced by an VariableObject def self.replace_string(obj) return obj unless VariableObject.regex.match(obj) VariableObject.new(obj) end def list @list ||= create_list end # Split the strings accordingly def create_list lst = split_list replace_variables(lst) end # Replace variables def replace_variables(list) list.map! do |elem| m = elem.match(VariableObject.regex_full) if m "var=#{m[1]}" else elem end end end def to_s # TODO: implement var evaluation here "<#VariableObject#{list}>" end def inspect "<#VariableObject#{list}>" end # Split the strings accordingly def split_list(existing_list = []) if existing_list.length == 0 str = @str else str = existing_list.pop return existing_list if str.length == 0 end list = existing_list + str.partition(VariableObject.regex) split_list(list) end def initialize(str) @str = str end end end end end