<commit_before># deref_variables.rb - methods deref_variables, decurlry

# extracts foo from :{foo}
def decurly bracelet
  m=bracelet.match /:\{([_\w]+)\}|:([_\w]+)/
  if m.nil?
    '_not_found'
  else
  m.captures.reject {|e| e.nil? }.first
end
end

# given a string, derefs any variables therein
def deref_variables string
  result = symbol_if_colon(string)
  if result.instance_of?(Symbol)
    Viper::Variables[result]
  else
    #occurs = string.scan /:\{[_\w]+\}/
    #expansions = occurs.map { |e| sym = decurly(e).to_sym;[sym, Viper::VFS["viper"]["variables"][sym]] }.to_h
    string.gsub(/:\{[_\w]+\}|:[_\w]+/) do |match|
      Viper::VFS['viper']['variables'][decurly(match).to_sym]
    end
    #result
  end
end<commit_msg>\'refactored deref_variables to use passed in hash\'<commit_after># deref_variables.rb - methods deref_variables, decurlry

# extracts foo from :{foo}
def decurly bracelet
  m=bracelet.match /:\{([_\w]+)\}|:([_\w]+)/
  if m.nil?
    '_not_found'
  else
  m.captures.reject {|e| e.nil? }.first
end
end

# given a string, derefs any variables therein
def deref_variables string, variables=Viper::VFS['viper']['variables']
  result = symbol_if_colon(string)
  if result.instance_of?(Symbol)
    Viper::Variables[result]
  else
    string.gsub(/:\{[_\w]+\}|:[_\w]+/) do |match|
      variables[decurly(match).to_sym]
    end
    #result
  end
end
{'fraction_non_alphanumeric': 0.17745454545454545, 'fraction_numerical': 0.0, 'mean_word_length': 3.967509025270758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6482618', 'n_tokens_mistral': 529, 'n_tokens_neox': 525, 'n_words': 112}