Created
September 9, 2014 19:30
-
-
Save peijiehu/c735ad60e1dfd6a4976b to your computer and use it in GitHub Desktop.
Retrieving value from yaml file
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
# Helper method for retrieving value from yaml file | |
# @param [String, String] | |
# keys, eg. "timeouts:implicit_wait" to retrieve value "60" from | |
# yml file with content: | |
# timeouts: | |
# implicit_wait: 60 | |
def read_yml(file_name, keys) | |
data = Hash.new | |
begin | |
data = YAML.load_file "#{file_name}" | |
rescue | |
raise Exception, "File #{file_name} doesn't exist" unless File.exist?(file_name) | |
rescue | |
raise YAMLErrors, "Failed to load #{file_name}" | |
end | |
keys_array = keys.split(/:/) | |
value = data | |
keys_array.each do |key| | |
value = value[key] | |
end | |
return value | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment