Skip to content

Instantly share code, notes, and snippets.

@pablobm
Created May 28, 2014 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pablobm/86bb3c06fd023d6494a8 to your computer and use it in GitHub Desktop.
Save pablobm/86bb3c06fd023d6494a8 to your computer and use it in GitHub Desktop.
def substitute_command_tokens(check)
unmatched_tokens = Array.new
substituted = check[:command].split(':::').each_with_index do |match, index|
next if index % 2 == 1
token, default = $1.to_s.split('|', -1)
matched = token.split('.').inject(@settings[:client]) do |client, attribute|
if client[attribute].nil?
default.nil? ? break : default
else
client[attribute]
end
end
if matched.nil?
unmatched_tokens << token
end
matched
end
[substituted, unmatched_tokens]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment