Created
May 28, 2014 10:39
-
-
Save pablobm/86bb3c06fd023d6494a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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